zu öffnen, was ich tun wollte, war offen die App durch Benachrichtigung in zwei Fällen:App für Vordergrund, wenn sie auf Benachrichtigung klicken, ohne neue
Fall offen App: Ziehen Sie einfach Hintergrund
Fall geschlossene App: öffnet neuen App
der Code, den ich habe, ist die nächste:
NotificationManager manager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
String title = context.getString(R.string.notification_title);
String message = context.getString(getNotificationText());
Bitmap largeIcon = getLargeBitmap();
NotificationCompat.Builder notification =
(NotificationCompat.Builder) new NotificationCompat.Builder(context).setContentTitle(title).setContentText(message)
.setSmallIcon(getIcon()).setLargeIcon(largeIcon).setOngoing(true);
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN) {
Intent intent = new Intent(context, MainActivity.class);
intent.setAction("android.intent.action.MAIN");
intent.addCategory("android.intent.category.LAUNCHER");
TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
stackBuilder.addParentStack(MainActivity.class);
stackBuilder.addNextIntent(intent);
PendingIntent contentIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
notification.setContentIntent(contentIntent);
}
manager.notify(NETWORK_STATUS_NOTIFICATION_ID, notification.build());
}
Das Problem, das ich habe, ist, dass der Code auf Android 5 und höher funktioniert, aber nicht auf Android funktioniert: JELLY_BEAN und KITKAT.
Jemand mir helfen?
Auf Android JELLY_BEAN und KITKAT, Fortsetzung funktioniert nicht! :( –
Warum haben Sie 'intent.setAction (" android.intent.action.MAIN "); und' intent.addCategory' festgelegt? –
http://stackoverflow.com/questions/2960459/re-open-background- Anwendung-über-Benachrichtigung-Element –