2015-08-08 63 views
2

这是我的代码,我想打开一个URL,当用户点击通知。android-如何打开浏览器的通知点击

这是代码:

`Intent notificationIntent = new Intent(Intent.ACTION_VIEW); 
      notificationIntent.setData(Uri.parse(link)); 

      Notification myNotification = new NotificationCompat.Builder(ctx) 
        .setSmallIcon(R.drawable.ic_launcher).setAutoCancel(false).setLargeIcon(remote_picture) 
        .setContentTitle(onvan).setContentIntent(notificationIntent) 
        .setContentText(msg).setStyle(notiStyle).build(); 
      notificationManager.notify(1, myNotification);` 

我得到这个错误: 在类型NotificationCompat.Builder的方法setContentIntent(的PendingIntent)不适用于参数(意向)

我是什么做错了?如何在用户点击通知时告诉它打开浏览器?

谢谢

回答

2

您必须将挂起的意图添加到通知。

Intent notificationIntent = new Intent(Intent.ACTION_VIEW); 
    notificationIntent.setData(Uri.parse(link)); 

    PendingIntent pending = PendingIntent.getActivity(this, 0, notificationIntent, Intent.FLAG_ACTIVITY_NEW_TASK); 
    myNotification.setContentIntent(pending); 
相关问题