Ich habe die Push-Benachrichtigung in einer meiner Anwendungen implementiert und es funktioniert gut, bis die App geöffnet ist oder im Hintergrund läuft.Ich kann keine Benachrichtigung erhalten, wenn die App geschlossen wird
Aber nach dem Entfernen der Anwendung aus dem Hintergrund kann ich keine Benachrichtigung auf meinem Gerät erhalten. Ich habe fast alle mit diesem Problem verbundenen Links durchgespielt und höchstwahrscheinlich alles implementiert, was erforderlich ist, um eine Benachrichtigung zu erhalten.
Ich bin nur auf diesem Punkt nur so fest, wenn es jemanden gibt, der weiß, wie man eine Benachrichtigung erhält, wenn die App geschlossen ist, bitte posten Sie eine Lösung.
Ihre Hilfe wird sehr geschätzt.
Service Class Code:
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);
}
Manifest:
<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>
Dank.
Mögliches Duplikat von [Android GCM (Push-Benachrichtigung): Das Gerät erhält keine Benachrichtigung, wenn die Anwendung gestoppt wird] (http://stackoverflow.com/questions/12073449/android-gcm-push-notification-device-doesnt- receive-notification-if-applicat) – Exaqt
relevanten Code eingeben – saeed
Bevor Sie es als Duplikat veröffentlichen, versuchen Sie einfach zu wissen, was das Problem ist. Ich bin durch diesen Link gegangen, aber es hat mein Problem nicht gelöst. – shubham0703