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

时间:2011-06-03 20:25:44

标签: android

我的问题如下:

我正在向通知栏发布通知,并且我在其中发送了一个URI链接。一旦我点击通知我得到一个对话框我想做什么,但它显示垃圾,如应用程序信息,条形码扫描仪,调用对话框。而不是浏览器。

我出示了我的代码:

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

所以我可能没想到正确的方向。 我是否应该插入一个intent并在我自己的应用程序中有一个处理程序而是为浏览器创建一个新的意图? 但那会很奇怪,为什么android无法正确处理我的初始意图呢。

一如既往 非常感谢任何和所有帮助。

谢谢, 罗汉。

2 个答案:

答案 0 :(得分:36)

我认为问题是您在将数据提供给PendingIntent后将数据设置为“notificationIntent”。

试试这个:

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

答案 1 :(得分:4)

它为我工作

Intent notificationIntent = new Intent(Intent.ACTION_VIEW);
            notificationIntent.setData(Uri.parse("http://www.google.com")); 
            PendingIntent pi = PendingIntent.getActivity(context, 0, notificationIntent, 0);
             // Resources r = getResources();
              Notification notification = new NotificationCompat.Builder(context)
                      .setTicker("yortext")
                      .setSmallIcon(android.R.drawable.ic_menu_report_image)
                      .setContentTitle("yortext")
                      .setContentText("sdsd")
                      .setContentIntent(pi)
                      .setAutoCancel(true)
                      .build();

              NotificationManager notificationManager2 =  (NotificationManager) context.getSystemService(Service.NOTIFICATION_SERVICE);
              notificationManager2.notify(0, notification);
相关问题