I want to open app when device receive push notification from GCM same time app is already closed,I tried this code it works on some devices not on all devices. Below is my code snippet,
@Override
public void onHandleIntent(Intent intent) {
notificationManager(this, getString(R.string.new_ride), true);
}
public static void notificationManager(Context context, String message, boolean
ring) {
try {
long when = System.currentTimeMillis();
NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
Log.v("message",","+message);
Intent notificationIntent = new Intent(context, SplashNewActivity.class);
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent intent = PendingIntent.getActivity(context, 0, notificationIntent, 0);
NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
builder.setAutoCancel(true);
builder.setContentTitle(context.getString(R.string.app_name));
builder.setStyle(new NotificationCompat.BigTextStyle().bigText(message));
builder.setContentText(message);
builder.setTicker(message);
if(ring){
builder.setLights(Color.GREEN, 500, 500);
}
else{
builder.setDefaults(Notification.DEFAULT_ALL);
}
builder.setWhen(when);
builder.setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.drawable.ic_launcher));
builder.setSmallIcon(R.drawable.notif_icon);
builder.setContentIntent(intent);
Notification notification = builder.build();
notificationManager.notify(NOTIFICATION_ID, notification);
//Open the App while new ride request arrives
Intent dialogIntent = new
Intent(getBaseContext(),SplashNewActivity.class);
dialogIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
getApplication().startActivity(dialogIntent);
} catch (Exception e) {
e.printStackTrace();
}
}
Please let me know is it possible on all devices or it is device dependent. Thanks in advance.