2016-04-07 10 views
-1

私はプッシュ通知を実装しようとしていますが、通知もあります。しかし、今私は、通知バーの通知をオンにする必要があります。私。モバイルがオンになっているときに通知が届いた場合、通知領域に通知が表示されず、デバイスがシャットダウンしたときにモバイルに切り替えたときに、通知バーにその通知を取得する必要があります。通知領域の通知を削除した場合、10分後に通知領域/バーにその通知が必要です。デバイスのシャットダウン時に通知領域/バーに通知を保存する方法はありますか?

どうすればこの問題を解決できますか?

答えて

0

あなたのマニフェストでブート時にstuffを実行するには、BroadcastReceveiverBOOT_COMPLETEDです。

一定時間後のものは、AlarmManagerを使用してください。

+0

私はGCMのプッシュ通知に取り組んでいますが、そのアラームマネージャおよびブロードキャストReceveiver – Latha

1

あなたはFLAG_ONE_SHOTでPendingIntentを使用することができます。

private void sendNotification(String from, String message) { 
     Bundle bundle = new Bundle(); 
     Intent intent = new Intent(this, ChatActivity.class); 
     intent.putExtra("INFO", bundle); 
     PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_ONE_SHOT); 
     Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); 
     NotificationCompat.Builder builder = new NotificationCompat.Builder(this) 
       .setContentTitle(from) 
       .setSound(defaultSoundUri) 
       .setContentText(message) 
       .setSmallIcon(R.drawable.ic_notification) 
       .setAutoCancel(true) 
       .setContentIntent(pendingIntent); 

     NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); 

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

そして、あなたのマニフェストファイルにセットWAKE_LOCK権限を覚えている:

<uses-permission android:name="android.permission.WAKE_LOCK" /> 
+0

と関係するものであるなし、電源投入後、通知領域にまでpopingないのではないworking.its – Latha

3
  1. あなたは通知内容いくつかのようなSharePreferenceを保存する必要があります。
  2. このインテント "android.intent.action.BOOT_COMPLETED"を使用してデバイスを起動したときに、ブロードキャストレシーバが起動すると、ステップ1の通知コンテンツを読み込み、再び通知を受け取ります。右

簡単、:)

関連する問題