2016-11-05 17 views
-1

私は、通知を送信するためにsetRepeatingメソッドを使用するアプリを開発しています。通知がクリックされたとき(スワイプされていない)アラームアプリをキャンセルするようにします。 ?通知がクリックされたときにAlarmManagerをキャンセルする

私の通知に同じことをするボタンを置く方法がない場合、またはそれをキャンセルするにはアプリにボタンを置く必要がありますか?おかげ

これは、通知をクリックしたときに、私は意図とAlarmManager

public void onClick(View v) { 
     intent = new Intent(getApplicationContext(), Notifications.class); 
     pend = PendingIntent.getBroadcast(getApplicationContext(), 100, intent, PendingIntent.FLAG_UPDATE_CURRENT); 
     am = (AlarmManager) getSystemService(ALARM_SERVICE); 
am.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), 1000 * 60, pend); 

答えて

1

を使用する部分である(スワイプない)...は それを行うためにそこに方法は何ですか?

あなたは自分の保留中の意図にあなたのアラームIDを追加する必要が通知を発行する際はい、:そして、

Intent notificationIntent = new Intent(context, NotificationsLandingActivity.class); 
notificationIntent.putExtra("alarm_id","123"); 

PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT); 
... 

を、あなたは打ち上げの活動からsavedInstanceStateからそのIDを取得することができます

public class NotificationsLandingActivity extends Activity { 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 

     try { 
      String alarmId = getIntent().getExtras().getString("alarm_id"); 
      //cancel the alarm 
     } catch (Exception e) { 
      ... 
     } 
     ... 
    } 
} 
+0

これが通知のクリックにどのように影響するのか分かりませんか?私はアンドロイドの初心者です。私は私のコード –

+0

の意図の部分を追加しました。あなたがこれがリンクであるのを助けることができるなら、別の問題があります。 http://stackoverflow.com/questions/40456093/how-to-check-if -alarmmanager-is-already-working あなたの時間に感謝します。 –

関連する問題