Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/201.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 安卓:点击推送通知后打开外部浏览器_Android_Browser_Push Notification_Google Cloud Messaging_Android Pendingintent - Fatal编程技术网

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

Android 安卓:点击推送通知后打开外部浏览器,android,browser,push-notification,google-cloud-messaging,android-pendingintent,Android,Browser,Push Notification,Google Cloud Messaging,Android Pendingintent,我在处理锁屏上的推送通知点击时遇到问题 我在我的应用程序中创建了一个GCM模块,MyAppGcmListenerServiceclass extendedGcmListenerService,并在onMessageReceived方法中处理了正在进行的捆绑包 @Override public void onMessageReceived(String from, Bundle data) { logger.info("MyAppGcmListenerService: on

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

我在我的应用程序中创建了一个GCM模块,MyAppGcmListenerServiceclass extendedGcmListenerService,并在onMessageReceived方法中处理了正在进行的捆绑包

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

当我点击通知栏中的推送通知时,一切都正常-我接收到非空url的推送,并在浏览器外部打开我的url。当我点击锁屏上的通知(Android 5+)时,问题就发生了——在这种情况下,有人建议我“刷屏解锁”,然后没有运行浏览器来打开url

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


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

您是否使用Chrome作为设备上的默认浏览器? 如果是这样,这可能是Chrome在锁定屏幕时忽略接收到的意图的问题


我仍在试图找到解决方法,我还试图将意图发送到一个虚拟活动,该活动在调用onResume()时完成并启动Chrome(当活动在前面且用户可见时调用onResume),但不知何故Chrome仍然忽略了此意图…

根据您的更新评论,你说这两种情况都很顺利。是否有任何问题需要解决?是的,问题是实际的。在这两种情况下,启动应用程序都进展顺利,但当我试图打开浏览器时,点击锁定屏幕上的按钮——失败了,浏览器并没有打开。
    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());
}