我一直在我的应用程序之一中实施推送通知,并且它正常工作,直到时间应用程序打开或它在后台运行。当应用程序关闭时无法接收通知
但是,从后台删除应用程序后,我无法收到我的设备上的通知。我经历了几乎所有与此问题相关的链接,并且很可能已经实现了所有需要收到通知的内容。
我只是停留在这一点上,所以如果有人知道如何在应用程序关闭时收到通知,请发布解决方案。
我们将非常感谢您的帮助。
服务类代码:
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