简体   繁体   中英

Android- Opening a browser when user clicks a notification

Hi I wanted to create a notification that will open a browser when user clicks on it. But the notification simply disappears and that's it. I have already made houndreds of versions of this code:

    private void sendNotification(String url){

    NotificationManager mNotificationManager =
            (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

    Uri webpage = Uri.parse(url);
    Intent intent = new Intent(Intent.ACTION_VIEW, webpage);

    PendingIntent resultPendingIntent =
            PendingIntent.getActivity(MediaMonitorService.this,0,intent,0);
    long[] vibrations = {250,250,500,250,250};
    NotificationCompat.Builder mBuilder =
            new NotificationCompat.Builder(MediaMonitorService.this)
                    .setSmallIcon(R.drawable.ic_launcher)
                    .setContentTitle("MediaMonitor notification")
                    .setContentText(notificationMessage)
                    .setAutoCancel(true)
                    .setVibrate(vibrations)
                    .setLights(0xff00ff00,300,1000)
                    .setContentIntent(resultPendingIntent);

    mNotificationManager.notify(hashString(url), mBuilder.build());
}

Thanks for your help.

问题是url在开头没有“http://”。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM