1

私は自分のアプリケーションの1つでプッシュ通知を実装していて、アプリが開いているか、バックグラウンドで実行されている間は正常に動作しています。アプリケーションが終了したときに通知を受け取ることができません

しかし、アプリケーションをバックグラウンドから削除した後、私のデバイスで通知を受け取ることができません。私はこの問題に関連するほとんどすべてのリンクを辿り、通知を受けるために必要とされるすべてのものを実装した可能性が最も高いでしょう。

私はちょうどこの時点で固執しているので、アプリが閉じられたときに通知を受け取る方法を知っている人がいる場合は、解決策を投稿してください。

あなたのご協力をお待ちしております。

サービスクラスコード:

public void onMessageReceived(String from, Bundle data){ 
    String message = data.getString("message"); 
    //createNotification(mTitle, push_msg); 

    Log.e("*Notification-Response*" , from); 
    Log.e("*Notification-Bundle*" , String.valueOf(data)); 

    //checkApp(); 
    generateNotification(getApplicationContext(),message); 

} 


private static void generateNotification(Context context, String message) { 



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

    Intent notificationIntent = new Intent(context, Dashboard.class); 
    notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); 
    PendingIntent pIntent = PendingIntent.getActivity(context, (int) System.currentTimeMillis(), notificationIntent, 0); 

    Notification notification = new NotificationCompat.Builder(context) 
      .setSmallIcon(R.drawable.appicon) 
      .setContentTitle("Title") 
      .setContentText(message) 
      .setContentIntent(pIntent) 
      .setAutoCancel(true) 
      .build(); 

    notification.flags |= Notification.FLAG_AUTO_CANCEL; 

    // Play default notification sound 
    notification.defaults |= Notification.DEFAULT_SOUND; 

    // Vibrate if vibrate is enabled 
    notification.defaults |= Notification.DEFAULT_VIBRATE; 
    notificationManager.notify(999999, notification); 

} 

マニフェスト:

<service 
      android:name=".GCM.PushNotificationService" 
      android:exported="false"> 
      <intent-filter> 
       <action android:name="com.google.android.c2dm.intent.RECEIVE" /> 
      </intent-filter> 
     </service> 



     <receiver 
      android:name="com.google.android.gms.gcm.GcmReceiver" 
      android:exported="true" 
      android:permission="com.google.android.c2dm.permission.SEND"> 
      <intent-filter> 
       <action android:name="com.google.android.c2dm.intent.RECEIVE" /> 
       <action android:name="com.google.android.c2dm.intent.REGISTRATION" /> 
       <category android:name="com.google.android.gcm.demo" /> 
      </intent-filter> 
     </receiver> 

感謝。

+0

[Android GCM(プッシュ通知):アプリが停止してもデバイスが通知を受信しない](http://stackoverflow.com/questions/12073449/android-gcm-push-notification-device-doesnt-受信通知アプリケーションの場合) – Exaqt

+0

関連コード – saeed

+0

を投稿する前に、問題が何であるかを知るようにしてください。私はそのリンクを通過しましたが、それでも私の問題は解決しませんでした。 – shubham0703

答えて

0

問題を解決しました。

デバイス関連の問題でした。他のデバイスでテストされ、正常に動作していました。

+0

問題を修正できましたか?私は同じ問題を抱えています。一部のデバイスでは、アプリケーションが終了してもプッシュ通知が表示されません。 –

+0

デバイス関連の問題でした – shubham0703

+0

そのデバイスで問題を解決できましたか?私はまた、アプリケーションが終了してもwhatsAppが動作しているデバイスを持っています。しかし、私のアプリは閉じたときに通知を受け取ることはありません。他のデバイスでは正常に動作します。 –

0

deviceIDを正しく登録しないと問題が発生することがあります。 Ondestroy()が呼び出している可能性があります。したがって、backgroundIDからアプリを削除している間に、deviceIDも削除されます。だから再度deviceIDを登録する必要があります。

+0

これはデバイスの問題でした。上記のコードは正常に動作しています。 – shubham0703

関連する問題