如果屏幕有 pin/graphical 键,推送通知不会打开 activity
Push notification don't open activity if screen has pin/graphical key
错误存在于屏幕 pin/graphical 键锁的手机上。没有它也能正常工作。
当用户点击推送通知启动主程序时 activity 仅此而已,如果没有 pin 或图形键则需要启动 activity。
这是我的 GCM 侦听器代码:
@Override
public void onMessageReceived(String from, Bundle data) {
String id = data.getString("news_id");
String message = data.getString("message");
Random random = new Random();
Intent intent = new Intent(this, SpecificNewsActivity.class);
intent.putExtra("newsId", id);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(this, random.nextInt(), intent,
PendingIntent.FLAG_ONE_SHOT);
Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.mipmap.ic_launcher)
.setContentTitle(getString(R.string.app_name))
.setContentText(message)
.setAutoCancel(true)
.setSound(defaultSoundUri)
.setContentIntent(pendingIntent);
NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(random.nextInt(), notificationBuilder.build());
}
有什么解决办法吗?
编辑: 看来这个问题只出现在中国手机(魅族、小米)上。
如果其他人遇到这个问题。这个问题很简单地解决了 - 对服务器的请求从具有片段容器的 Activity 移动到片段本身。小米和魅族没有这个activity就停在了frame布局的fragment交易阶段
错误存在于屏幕 pin/graphical 键锁的手机上。没有它也能正常工作。
当用户点击推送通知启动主程序时 activity 仅此而已,如果没有 pin 或图形键则需要启动 activity。
这是我的 GCM 侦听器代码:
@Override
public void onMessageReceived(String from, Bundle data) {
String id = data.getString("news_id");
String message = data.getString("message");
Random random = new Random();
Intent intent = new Intent(this, SpecificNewsActivity.class);
intent.putExtra("newsId", id);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(this, random.nextInt(), intent,
PendingIntent.FLAG_ONE_SHOT);
Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.mipmap.ic_launcher)
.setContentTitle(getString(R.string.app_name))
.setContentText(message)
.setAutoCancel(true)
.setSound(defaultSoundUri)
.setContentIntent(pendingIntent);
NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(random.nextInt(), notificationBuilder.build());
}
有什么解决办法吗?
编辑: 看来这个问题只出现在中国手机(魅族、小米)上。
如果其他人遇到这个问题。这个问题很简单地解决了 - 对服务器的请求从具有片段容器的 Activity 移动到片段本身。小米和魅族没有这个activity就停在了frame布局的fragment交易阶段