2016-08-17 10 views
1

一定の間隔の後に通知が表示されるように設定しようとしています。私はこれが動作することを期待しかし、何も私の電話機でコンソールに印刷されている受信者以外のコードを実行するときに発生するようだと私は理由を見つけることができないようです。どんな助けでも大歓迎です。間隔でアンドロイドで通知を送信する

ここにアラームを設定するためのコードがあります。ここで

Calendar calendar = Calendar.getInstance(); 
calendar.set(Calendar.SECOND, 10); 
Intent intent = new Intent(getApplicationContext(), NotificationReciever.class); 
PendingIntent pendingIntent = PendingIntent.getBroadcast(getApplicationContext(), 100, intent, PendingIntent.FLAG_UPDATE_CURRENT); 
AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE); 
alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), AlarmManager.INTERVAL_FIFTEEN_MINUTES, pendingIn 

は、ここで関連するマニフェスト線である通知受信クラス

public class NotificationReceiver extends BroadcastReceiver { 
@Override 
public void onReceive(Context context, Intent intent) { 
    System.out.println("at reciever"); 
    NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); 

    Intent repeatingIntent = new Intent(context, LoginActivity.class); 
    repeatingIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 

    PendingIntent pendingIntent = PendingIntent.getActivity(context, 100, repeatingIntent, PendingIntent.FLAG_UPDATE_CURRENT); 

    NotificationCompat.Builder builder = new NotificationCompat.Builder(context) 
      .setContentIntent(pendingIntent) 
      .setContentTitle("Please Leave at the cage") 
      .setContentText("It almost 5") 
      .setAutoCancel(true); 

    notificationManager.notify(100, builder.build()); 
} 
} 

ある
受信アンドロイド:名= が許可使用アンドロイド "NotificationReciever。":名= "com.android。 alarm.permission.SET_ALARM "

+0

'com.android.alarm.permission.SET_ALARM'これは、基本的なnotifcationため –

答えて

0

基本的には、通知ごとにアイコンを設定する必要があります。

NotificationCompat.Builder builder = new NotificationCompat.Builder(context) 
      .setContentIntent(pendingIntent) 
      .setContentTitle("Please Leave at the cage") 
      .setSmallIcon(R.drawable.crosshair); //crosshair is the icon choice in this example 
      .setContentText("It almost 5") 
      .setAutoCancel(true); 
+0

おかげで多くのことを必要と問題を修正されていません – Sjw

関連する問題