2017-02-07 15 views
-2

特定の時刻(午前7時)に何かをチェックしてから、条件が真であれば、アプリがアクティブでない場合でも通知を送信したいバックグラウンドで実行されている "ただ"でも。私はNotificationClass.classわからないです毎日繰り返される特定の時間に関する通知

Intent intent_notification = new Intent(getApplicationContext() , NotificationClass.class); 
     AlarmManager alarmManager = (AlarmManager)getSystemService(ALARM_SERVICE); 
     PendingIntent pendingIntent = PendingIntent.getService(getApplicationContext(), 0, intent_notification, 0); 
     Calendar calendar = Calendar.getInstance(); 
     calendar.set(Calendar.HOUR_OF_DAY, 7); 
     calendar.set(Calendar.MINUTE, 00); 
     calendar.set(Calendar.SECOND, 00); 
     alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), AlarmManager.INTERVAL_DAY , pendingIntent); 

これは(MainActivity.javaで)今のコードです。それはどのように一般的に見える必要がありますか?

ありがとうございます。

答えて

0

NotificationClass.classは、Alarm BroadcastReceiverになります。アラームサービスはスケジュールされた時間にこの受信機を起動します。マニフェストで

public class NotificationClass extends BroadcastReceiver { 

    @Override 
    public void onReceive(Context context, Intent intent) { 
     //check something at a scheduled time 
     if(condition is true){ 
      sendNotification(); 
     } 
    } 
} 

宣言NotificationClass.class

<receiver android:name=".NotificationClass" 
      android:process=":remote" /> 
関連する問題