Opening a browser link through notification isn't working

前端 未结 2 1946
无人及你
无人及你 2020-12-05 17:54

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 t

相关标签:
2条回答
  • 2020-12-05 18:35

    its work for me

    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);
    
    0 讨论(0)
  • 2020-12-05 18:39

    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);
    
    0 讨论(0)
提交回复
热议问题