gpt4 book ai didi

Android:推送通知点击后打开外部浏览器

转载 作者:行者123 更新时间:2023-11-29 20:11:57 24 4
gpt4 key购买 nike

我在处理锁定屏幕上的推送通知点击时遇到问题。

我在我的应用程序中创建了一个 GCM 模块,MyAppGcmListenerService 类扩展了 GcmListenerService 并在 onMessageReceived 方法中我处理了正在进行的 bundle

@Override
public void onMessageReceived(String from, Bundle data) {
logger.info("MyAppGcmListenerService: onMessageReceived: from = " + from + "; data = " + data.toString());
sendNotification(createMessage(data));
}

    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());
}

当我点击通知栏中的推送通知时一切正常 - 我收到带有非空 url 的推送并且外部浏览器打开我的 url。当我在锁定屏幕 (Android 5+) 上点击通知时会出现问题 - 在这种情况下,我被建议“滑动屏幕解锁”,然后没有运行浏览器来打开 url。

有人知道如何解决这个问题吗?

UPD。启动应用程序 (MainActivity.class) 在两种情况下都运行良好:当点击通知栏和锁定屏幕上的通知时。

最佳答案

您是否将 Chrome 用作设备上的默认浏览器?如果是这样,这可能是 Chrome 在锁定屏幕时忽略收到的 Intent 的问题,如 here 所示。

我仍在尝试为此寻找解决方法,我还尝试将 Intent 发送到虚拟 Activity ,该 Activity 已完成并在调用 onResume() 时启动 Chrome(当 Activity 在前面且可见时调用 onResume给用户),但不知何故 Chrome 仍然忽略了这个 Intent ......

关于Android:推送通知点击后打开外部浏览器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34632344/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com