Reputation: 1171
I've got a problem with handling push notification tap on Lock screen.
I created a GCM module in my app, MyAppGcmListenerService class extended GcmListenerService and in onMessageReceived method I handled ongoing bundle
@Override
public void onMessageReceived(String from, Bundle data) {
logger.info("MyAppGcmListenerService: onMessageReceived: from = " + from + "; data = " + data.toString());
sendNotification(createMessage(data));
}
and
private void sendNotification(Message message) {
Intent intent = null;
if (TextUtils.isEmpty(message.getUrl())) {
intent = new Intent(this, MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
} else {
intent = new Intent(Intent.ACTION_VIEW);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setData(Uri.parse(Utils.buildUrlWithExtraInfo(message.getUrl(), Prefs.restoreGuid())));
}
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_ONE_SHOT);
Uri defaultSoundUri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.notif_small_icon)
.setColor(getBaseContext().getResources().getColor(R.color.notif_bg_color))
.setContentTitle(message.getTitle())
.setContentText(message.getParagraph())
.setAutoCancel(true)
.setSound(defaultSoundUri)
.setContentIntent(pendingIntent);
NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
manager.notify(0, notificationBuilder.build());
}
Everything works fine when I tap push notification in notification bar - I receive push with not-null url and outside browser open my url. The problem happens when I tap notification on Lock screen (Android 5+) - in that case I was suggested "Swipe screen to unlock" and then no browser was run to open url.
Is there anybody khow how to fix this issue?
UPD. Start app (MainActivity.class) going well in both cases: when tap notification on Notification Bar and on Lock screen too.
Upvotes: 1
Views: 1361
Reputation: 251
Are you using Chrome as the default browser on your device? If so, this might be a problem of Chrome ignoring received intents while in lock screen as seen here
I'm still trying to find a workaround for this, I also tried to send the Intent to a dummy activity which is finished and starts Chrome when onResume() is called (onResume is called when the activity is in front and visible to the user), but somehow Chrome still ignores this intent...
Upvotes: 2