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

Roh*_*han 23 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);
Run Code Online (Sandbox Code Playgroud)

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

一如既往,非常感谢任何和所有的帮助.

谢谢,罗汉.

小智 39

我认为问题是你在将数据提供给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);
Run Code Online (Sandbox Code Playgroud)

或试试这个:

      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);
Run Code Online (Sandbox Code Playgroud)


sir*_*gid 6

它对我的工作

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);
Run Code Online (Sandbox Code Playgroud)