【问题标题】:Opening a browser link through notification isn't working通过通知打开浏览器链接不起作用
【发布时间】:2016-03-30 20:53:13
【问题描述】:

我的问题如下:

我正在向通知栏发布通知,并且我已将 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);

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

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

谢谢, 罗汉。

【问题讨论】:

    标签: android


    【解决方案1】:

    我认为问题在于您在将数据提供给 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);
    

    【讨论】:

      【解决方案2】:

      它对我有用

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

      【讨论】:

      • 嗨,sirmagid。您的代码效果很好。您是否知道必须进行哪些更改才能解析应用程序(在我的情况下为 webview 应用程序)而不是浏览器中的链接?非常感谢任何帮助。
      • @JohnA10,你能找到解析的代码吗?如果是,请发布。
      • @ChrisHarris 你有这个问题在另一个线程中打开吗?如果我在答案的答案中发布代码,它会看起来很糟糕。
      • @JohnA10,请在此处发布 - stackoverflow.com/questions/40492749/…
      猜你喜欢
      • 1970-01-01
      • 2020-08-22
      • 1970-01-01
      • 1970-01-01
      • 2018-10-04
      • 1970-01-01
      • 1970-01-01
      • 2017-02-05
      • 1970-01-01
      相关资源
      最近更新 更多