繁体   English   中英

Android-用户点击通知时打开浏览器

[英]Android- Opening a browser when user clicks a notification

嗨,我想创建一个通知,当用户点击它时将打开浏览器。 但通知只是消失了就是这样。 我已经制作了这段代码的houndreds版本:

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

谢谢你的帮助。

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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