我正在尝试在单击通知时打开一个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新手,所以我希望得到一个简化的解释:)
请先检查一下,看看结果如何
if (browserIntent.resolveActivity(getPackageManager()) != null) {
startActivity(browserIntent);
}