2016-12-25 9 views
1

私は数時間探していますが、私の問題を解決できませんでした。ヘッドアップ通知ボタンがブロードキャストを呼び出す方法を知っている人はいますか?私のコード:ヘッドアップ通知ボタンが実行されていません

アラームレシーバ通知ビルダー:

 NotificationCompat.Builder builder = 
      new NotificationCompat.Builder(context) 
        .setSmallIcon(R.drawable.alarmicon) 
        .setContentTitle("Alarm for " + timeString) 
        .setContentText(MainActivity.alarmLabel.getText().toString()) 
        .setDefaults(Notification.DEFAULT_ALL) // must requires VIBRATE permission 
        .setPriority(NotificationCompat.PRIORITY_HIGH); //must give priority to High, Max which will considered as heads-up notification 

    //set intents and pending intents to call service on click of "dismiss" action button of notification 
    Intent dismissIntent = new Intent(context, notificationButtonAction.class); 
    dismissIntent.setAction(DISMISS_ACTION); 
    PendingIntent piDismiss = PendingIntent.getBroadcast(context, 0, dismissIntent, 0); 
    builder.addAction(R.drawable.alarmoff, "Dismiss", piDismiss); 

    //set intents and pending intents to call service on click of "snooze" action button of notification 
    Intent snoozeIntent = new Intent(context, notificationButtonAction.class); 
    snoozeIntent.setAction(SNOOZE_ACTION); 
    PendingIntent piSnooze = PendingIntent.getBroadcast(context, 0, snoozeIntent, 0); 
    builder.addAction(R.drawable.snooze, "Snooze", piSnooze); 

    // Gets an instance of the NotificationManager service 
    NotificationManager notificationManager = 
      (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); 
    //to post your notification to the notification bar with a id. If a notification with same id already exists, it will get replaced with updated information. 
    notificationManager.notify(0, builder.build()); 

notificationButtonAction: "notificationButtonAction開始" notificationButtonActionで

public static class notificationButtonAction extends BroadcastReceiver { 
    @Override 
    public void onReceive(Context context, Intent intent) { 
     System.out.println("notificationButtonAction Started"); 
     String action = intent.getAction(); 
     if (SNOOZE_ACTION.equals(action)) { 
      stopAlarm(); 
      System.out.println("Alarm Snoozed"); 
      MainActivity ma = new MainActivity(); 
      ma.setAlarm(true); 
     } 
     else if (DISMISS_ACTION.equals(action)) { 
      stopAlarm(); 
      System.out.println("Alarm Dismissed"); 
     } 
    } 
} 

マイプリントラインがいなくても、印刷されません。

私はBrevity Software(http://www.brevitysoftware.com/blog/how-to-get-heads-up-notifications-in-android/)からのチュートリアルに従いましたが、そのコードは機能していないようです。

ご協力いただきましてありがとうございます。ありがとう!

+0

テハス、ここに運がありますか? –

+1

はい、Android Manifestにクラスを追加していないことが判明しました。うわー! –

答えて

0

私はマニフェストにクラスを追加していませんでした。私のコードは問題ありませんでした。

関連する問題