2016-10-02 19 views
0

をsetLatestEventInfo`が、私は方法setLatestEventInfo方法を解決することはできません取得します。`メソッドを解決できない私はリマインダーアプリを作る

public class NotifyService extends Service { 

    public class ServiceBinder extends Binder { 
     NotifyService getService() { 
      return NotifyService.this; 
     } 
    } 

    private static final int NOTIFICATION = 123; 
    public static final String INTENT_NOTIFY = "com.example.seng.healthyapp.INTENT_NOTIFY"; 
    private NotificationManager mNM; 

    @Override 
    public void onCreate() { 
     Log.i("NotifyService", "onCreate()"); 
     mNM = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); 
    } 

    @Override 
    public int onStartCommand(Intent intent, int flags, int startId) { 
     Log.i("LocalService", "Received start id " + startId + ": " + intent); 

     if (intent.getBooleanExtra(INTENT_NOTIFY, false)) 
      showNotification(); 

     return START_NOT_STICKY; 
    } 

    @Override 
    public IBinder onBind(Intent intent) { 
     return mBinder; 
    } 

    private final IBinder mBinder = new ServiceBinder(); 

    private void showNotification() { 

     CharSequence title = "Alarm!!"; 
     int icon = R.drawable.ic_dialog_alert; 

     CharSequence text = "Your notification time is upon us."; 
     long time = System.currentTimeMillis(); 

     Notification notification = new Notification(icon, text, time); 

     PendingIntent contentIntent = PendingIntent.getActivity(this, 0, new Intent(this, SecondActivity.class), 0); 

     notification.setLatestEventInfo(this, title, text, contentIntent); 

     notification.flags |= Notification.FLAG_AUTO_CANCEL; 

     mNM.notify(NOTIFICATION, notification); 

     stopSelf(); 
    } 
} 

編集

public class NotifyService extends Service { 

    public class ServiceBinder extends Binder { 
     NotifyService getService() { 
      return NotifyService.this; 
     } 
    } 

    private static final int NOTIFICATION = 123; 
    public static final String INTENT_NOTIFY = "com.example.seng.healthyapp.INTENT_NOTIFY"; 
    private NotificationManager mNM; 

    @Override 
    public void onCreate() { 
     Log.i("NotifyService", "onCreate()"); 
     mNM = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); 
    } 

    @Override 
    public int onStartCommand(Intent intent, int flags, int startId) { 
     Log.i("LocalService", "Received start id " + startId + ": " + intent); 

     if(intent.getBooleanExtra(INTENT_NOTIFY, false)) 
      showNotification(); 

     return START_NOT_STICKY; 
    } 

    @Override 
    public IBinder onBind(Intent intent) { 
     return mBinder; 
    } 

    private final IBinder mBinder = new ServiceBinder(); 

    private void showNotification() { 
     CharSequence title = "Alarm!!"; 

     int icon = R.drawable.ic_dialog_alert; 
     CharSequence text = "Your notification time is upon us."; 

     long time = System.currentTimeMillis(); 

     PendingIntent contentIntent = PendingIntent.getActivity(this, 0, new Intent(this, SecondActivity.class), 0); 

     Notification.Builder builder = new Notification.Builder(this) 
       .setSmallIcon(icon) 
       .setContentTitle(title) 
       .setContentText(text) 
       .setContentIntent(contentIntent); 
     Notification notification = builder.build(); 

     notification.flags |= Notification.FLAG_AUTO_CANCEL; 

     mNM.notify(NOTIFICATION, notification); 

     stopSelf(); 
    } 
} 

答えて

1

「setLatestInfo`は、API 23で削除されました:https://developer.android.com/sdk/api_diff/23/changes/android.app.Notification.html

あなたが代わりにNotification.Builderを使用する必要があります。https://developer.android.com/reference/android/app/Notification.Builder.html

を例hereがあります。

私はあなたが時代遅れAndroidのチュートリアルを使用していると仮定しています。 https://developer.android.comのものを使用してください。彼らは最も信頼できます。

+0

ヘソン、すべての情報に感謝します。私はあなたが与えた例に基づいて自分のコードを編集しました。私が正しい方法でそれらを実装したかどうかを確認するのを助けてくれますか? –

+0

「長い」時間は使用されません –

+0

何のために使用しますか? – Zarwan

関連する問題