I'm trying to open a URL on notification click. There are 2 browsers installed including Chrome but the code doesn't work.
I'm using this:
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);
Notification:
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());
Error:
No Activity found to handle Intent { act=android.intent.action.VIEW dat=link>https: flg=0x10008000 }
Android version is 6 and I'm running this in AsyncTask in as a service, if that's relevant. There's nothing wrong with the URL. I got data from it before and 'https://' part is not missing from it.
I'm new to android so I'm hoping for a simplified explanation :)
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(movieURL));
I am uncertain what movieURL
contains, but it is turning into link>https:
when you parse it. That is not a valid URL, and Android will not find an app to be able to handle ACTION_VIEW
for it.
Note that raising a Notification
from your app, where the Notification
launches a third-party app when clicked, is unusual. The typical point behind a Notification
is to allow the user to control aspects of your app's behavior. If your objective is to launch an activity from your own app, do not use an implicit Intent
(new Intent(Intent.ACTION_VIEW, ...)
). Instead, use an explicit Intent
(new Intent(this, YourAwesomeActivity.class)
). You can still use setAction()
or putExtra()
to attach information to tell your activity what to display.