我想打開應用程序,當設備從GCM接收推送通知時,同一時間的應用程序已經關閉,我試過這個代碼,它在一些設備上並不是在所有設備上都能正常工作。 下面是我的代碼片段,如何在應用程序關閉時收到推送通知(GCM)時在所有設備上打開android應用程序?
@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();
}
}
請讓我知道是否有可能在所有設備上,或者是設備相關。 在此先感謝。
「我想在設備從GCM同時接收推送通知時打開應用程序ap p已經關閉「 - 用戶可能不會欣賞你的活動,在他們正在做的事情中間打斷他們。用戶可能以多種方式表達他們的不滿(比如差評,身體暴力等)。 「我試過這個代碼,它可以在一些設備上運行,而不是在所有設備上運行」 - 請詳細解釋**「什麼是不是所有設備」的含義。當你使用你的調試器或日誌時,看看會發生什麼......會發生什麼? – CommonsWare