Java intent for youtube android stackoveroverflow

www.‮tual‬turi.com
Java intent for youtube android stackoveroverflow

To open a YouTube video in the YouTube app on Android using an Intent, you can use the following code:

String videoId = "dQw3w1WgXcQx";
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse("vnd.youtube:" + videoId));
startActivity(i);

In this example, videoId is the ID of the YouTube video that you want to open. The Intent uses the ACTION_VIEW action and sets the data to the Uri of the video, using the "vnd.youtube" scheme and the video ID. This tells the system to open the video in the YouTube app.

You can then call startActivity to start the activity and open the video in the YouTube app.

If the device does not have the YouTube app installed, this code will open the video in a web browser instead.

For more information on using Intents to open YouTube videos in Android, you can refer to the Android documentation or the Stack Overflow question that you mentioned.

Created Time:2017-11-03 23:27:13  Author:lautturi