【发布时间】:2020-04-08 22:19:28
【问题描述】:
我正在尝试在点击通知时打开一个 URL。安装了 2 个浏览器,包括 Chrome,但代码不起作用。
我正在使用这个:
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(movieURL));
browserIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(browserIntent);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, browserIntent, PendingIntent.FLAG_UPDATE_CURRENT);
通知:
NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
.setSmallIcon(R.mipmap.ic_launcher_foreground)
.setContentTitle(movieName + " is available")
.setContentText("Click here to open in browser")
.setPriority(NotificationCompat.PRIORITY_DEFAULT)
.setDefaults(Notification.DEFAULT_ALL)
.setContentIntent(pendingIntent)
.setAutoCancel(true);
NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context);
notificationManager.notify(1, builder.build());
错误:
No Activity found to handle Intent { act=android.intent.action.VIEW dat=link>https: flg=0x10008000 }
Android 版本为 6,如果相关,我在 AsyncTask 中将其作为服务运行。 URL 没有任何问题。我之前从它那里得到了数据,并且没有丢失“https://”部分。
我是 android 新手,所以我希望得到一个简化的解释 :)
【问题讨论】:
-
我想问题出在错误的 url
-
只需尝试将方案添加到您的网址
https://yts.lt。您的网址上没有方案,所以,我认为这是一个真正的问题 -
只是好奇。你的手机上是否安装了浏览器
-
他的意思是协议。而且您以错误的方式发布了网址。没有人能看到它一开始就有协议
https://。不要使用引号而是打勾。 (好吧,正确的刻度,有几个)。 -
dat=link>https:-- 您的网址似乎无效。如果您尝试在 Web 浏览器的地址栏中粘贴link>https:,您将无法获得网页。 “我将 url 打印到日志以进行检查”——Intent似乎没有该 URL。它有link>https:。
标签: android android-intent browser push-notification android-pendingintent