【问题标题】:Android- Opening a browser when user clicks a notificationAndroid-当用户点击通知时打开浏览器
【发布时间】:2014-05-14 12:18:13
【问题描述】:

您好,我想创建一个通知,当用户点击它时会打开浏览器。但是通知只是消失了,仅此而已。我已经制作了该代码的数百个版本:

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

感谢您的帮助。

【问题讨论】:

  • hashString(url) 中的这个值是什么?
  • 我没有看到代码有任何问题,它对我有用,但请检查 hashString(url) 中的值。
  • hashString(url) 的值有效并且通知显示。问题是当我点击它时没有任何反应——浏览器没有出现。

标签: android android-intent browser notifications android-pendingintent


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-01-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-05-05
    相关资源
    最近更新 更多