What I wanted to do was open the app by notification in two cases:
Case open app : Just pull background
Case closed app: Opens new app
The code that I have is the next:
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());
}
The problem I have is that the code is working on Android 5 and up, but does not work on Android : JELLY_BEAN and KITKAT .
Someone help me?