Force Video To Open In Youtube App On Android
I have a mobile website that links to a youtube video. On Android, clicking on this link brings up a dialog asking the user to 'Complete action using' their browser or the Youtube
Solution 1:
Here's how you can do that:
Intentintent=newIntent(Intent.ACTION_VIEW, Uri.parse("vnd.youtube://" + id));
startActivity(intent);
The id is the identifier after the questionmark in the url. For example: youtube.com/watch?v=ID
Another way is:
IntentvideoIntent=newIntent(Intent.ACTION_VIEW);
videoIntent.setData(url);
videoIntent.setClassName("com.google.android.youtube", "com.google.android.youtube.WatchActivity");
startActivity(videoIntent);
......
Solution 2:
The best way
try {
Intentintent=newIntent(Intent.ACTION_VIEW, Uri.parse("vnd.youtube://" + id));
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
} catch (ActivityNotFoundException e) {
// youtube is not installed.Will be opened in other available appsIntenti=newIntent(Intent.ACTION_VIEW, Uri.parse("https://youtube.com/watch?v=" + id));
startActivity(i);
}
Solution 3:
Try to use a JavaScript redirection like the following:
window.location = "vnd.youtube://the.youtube.video.url";
More comprehensively:
if( /Android/i.test(navigator.userAgent ) ) {
// If the user is using an Android device.setTimeout(function () { window.location = "market://details?id=com.google.android.youtube"; }, 25);
window.location = "vnd.youtube://www.youtube.com/watch?v=yourVideoId";
}
If Youtube app is disabled, the timeout function will redirect you to the youtube app on the play store to let you enable the app. The second redirect will pop up and play the youtube video on Android Youtube app.
If you are already switched to the YouTube app within the timeout interval, the timeout function will not be called and you are not switched to the play store but stay in the YouTube app.
Post a Comment for "Force Video To Open In Youtube App On Android"