2016-04-05 9 views
-3

私はAndroidのローカル通知に取り組んでいます。通知は、所定の時間に基づいて送信されます。ローカル通知の送信を停止するandroid

ユーザはスイッチを使用してこの通知を制御することができます(ON - >通知が送信され、OFFの場合 - >この通知を「NOtのみキャンセル」し、まったく送信しないでください) 。 ONの場合は完璧ですが、OFFの場合は通知が送信されます。

スイッチがOFFに設定されている場合、通知を送信する "Stop"を助けることができますか?ここで

は、私が使用していますスイッチです: enter image description here

をそして、これは私が使用していますコードです:

if(isChecked == true) 
    { 
     // Send the Notification 

} else { 

     // Stop Sending the Notification 

    } 
+0

はあなたがあなたのコードとあなたが既に試したを持っているところに、例えば、より多くの情報を与えることができますか? –

+0

これはあなたを助けるかもしれませんが、わかりません。 Ref:http://stackoverflow.com/questions/36347187/how-to-stop-alarmmanager-when-activity-start/36349036#36349036 – Sabari

+0

@佐波里ありがとうございました。これはまさに私が探しているものです。この質問に答えとして追加することはできますか? – Ghadeer

答えて

0

これはあなたを助けるかもしれないが、私はわかりません。

参考:How to stop AlarmManager when activity start

通知をキャンセルするには:

public void cancelNotification(int requestCode) { 
     try { 
      Intent notificationIntent = new Intent(getApplicationContext(), NotificationReceiver.class); 
      PendingIntent pendingIntent = PendingIntent.getBroadcast(getApplicationContext(), requestCode, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT); 
      AlarmManager alarmManager = (AlarmManager) getApplicationContext().getSystemService(Context.ALARM_SERVICE); 
      alarmManager.cancel(pendingIntent); 
     } catch (Exception e) { 
      e.printStackTrace(); 
     } 
    } 
関連する問題