通过通知打开浏览器链接无效

问题描述:

我的问题如下:

我正在将通知发布到通知栏,并且已将URI链接放入随它一起发送的意图中.当我单击通知时,我会弹出一个对话框,我想做什么,但是它显示出垃圾信息,例如应用程序信息",条形码扫描仪",呼叫"对话框.而不是浏览器.

I'm posting a notification to the notifications bar, and i've put a URI link in the intent being sent with it. As soon as i click on the notification i get a dialog what i want to do, but it's showing rubbish like Application info, Barcode scanner, Call dialog. instead of Browser.

我提供了我的代码:

      Intent notificationIntent = new Intent(Intent.ACTION_VIEW);

      PendingIntent contentIntent = PendingIntent.getActivity(contexta, 0, notificationIntent, 0);
      notificationIntent.setData(Uri.parse("http://www.google.com"));
      notification.setLatestEventInfo(contexta, contentTitle, contentText, contentIntent);
      mNotificationManager.notify(970970, notification);

所以我可能没有在正确的方向思考. 我是否应该在我自己的应用程序中插入一个意图并让一个处理程序为浏览器创建一个新的意图? 但这很奇怪,为什么android为什么不能正确处理我的初始意图.

So i'm probably not thinking in the right direction. Should i perhaps insert an intent and have a handler in my own application create a new intent for the browser instead? But that would be strange, why does android not handle my initial intent correctly then.

一如既往, 任何帮助都将不胜感激.

As always, Any and all help is greatly appreciated.

谢谢, 罗汉.

我认为问题是,在将数据提供给PendingIntent之后,您正在将数据设置为"notificationIntent".

I think the problem is you're setting the data to "notificationIntent" after you give it to PendingIntent.

尝试一下:

      Intent notificationIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.google.com"));

      PendingIntent contentIntent = PendingIntent.getActivity(contexta, 0, notificationIntent, 0);
      notification.setLatestEventInfo(contexta, contentTitle, contentText, contentIntent);
      mNotificationManager.notify(970970, notification);

或尝试以下操作:

      Intent notificationIntent = new Intent(Intent.ACTION_VIEW);

      notificationIntent.setData(Uri.parse("http://www.google.com"));
      PendingIntent contentIntent = PendingIntent.getActivity(contexta, 0, notificationIntent, 0);
      notification.setLatestEventInfo(contexta, contentTitle, contentText, contentIntent);
      mNotificationManager.notify(970970, notification);