私は自分のアプリケーションの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>
感謝。
[Android GCM(プッシュ通知):アプリが停止してもデバイスが通知を受信しない](http://stackoverflow.com/questions/12073449/android-gcm-push-notification-device-doesnt-受信通知アプリケーションの場合) – Exaqt
関連コード – saeed
を投稿する前に、問題が何であるかを知るようにしてください。私はそのリンクを通過しましたが、それでも私の問題は解決しませんでした。 – shubham0703