2016-10-04 2 views
1

アラームアプリを作成し、MyAlarmServiceに以下のコードがあります。 ONSTART方法で`getNotification`は廃止されないようにするには?

public class MyAlarmService extends Service 
{ 
    private NotificationManager mManager; 

    @Override 
    public IBinder onBind(Intent arg0) 
    { 
     // TODO Auto-generated method stub 
     return null; 
    } 

    @Override 
    public void onCreate() 
    { 
     // TODO Auto-generated method stub 
     super.onCreate(); 
    } 

    @SuppressWarnings("static-access") 
    @Override 
    public int onStartCommand(Intent intent, int flags, int startId) 
    { 
     mManager = (NotificationManager) this.getApplicationContext().getSystemService(this.getApplicationContext().NOTIFICATION_SERVICE); 
     Notification.Builder notification = new Notification.Builder(MyAlarmService.this); 
     Intent intent1 = new Intent(this.getApplicationContext(),ReminderPage.class); 
     PendingIntent pendingNotificationIntent = PendingIntent.getActivity(this.getApplicationContext(),0, intent1,0); 
     notification.setSmallIcon(R.drawable. notification_template_icon_bg) 
       .setContentTitle("Music player") 
       .setContentIntent(pendingNotificationIntent); 
     NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); 
     Notification notification1 = notification.getNotification(); 
     notificationManager.notify(R.drawable.notification_template_icon_bg, notification1); 
     mManager.notify(0, notification1); 
     return super.onStartCommand(intent,flags, startId); 
    } 

    @Override 
    public void onDestroy() 
    { 
     // TODO Auto-generated method stub 
     super.onDestroy(); 
    } 
  1. 、それは常に取り消し線を持っています。グーグルでは、onStartメソッドをonStartCommand()に変更しましたが、これを修正する正しい方法は不明です。
  2. getNotificationは推奨されていません。

AndroidMainfest

<uses-sdk 
     android:minSdkVersion="8" 
     android:targetSdkVersion="10" /> 

感謝。

答えて

1

あなたはこれを試すことができ、

NotificationCompat.Builder builder = new NotificationCompat.Builder(
       context); 
     notification = builder.setContentIntent(intent) 
       .setSmallIcon(R.drawable.push_icon).setTicker(title).setWhen(when) 
       .setAutoCancel(true).setContentTitle(title) 
       .setContentText(message).build(); 
     notificationManager.notify(requestID, notification); 
+0

は私がsuper.onStartCommand(意図、旗、startId)を返す '必要があるはずですか;'? –

+0

はい、できます。それはちょうどいくつかの方法を変更するだけで動作します – Saveen

+0

いつrequestIDですか.... –

関連する問題