Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
209 views
in Technique[技术] by (71.8m points)

android - Opening a browser link through notification isn't working

My problem is the following:

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.

I present my code:

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

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.

Thanks, Rohan.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

Try this:

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

Or try this:

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...