Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

How to Add YouTube Live Stream Feature in Android?

  • Last Updated : 09 Mar, 2021

YouTube provides a service to make a live stream video on their platform to connect with your subscribers. In this article, we will take a look at the implementation of YouTube video live streaming video in Android App. 

What we are going to build in this article? 

We will be building a simple application in which we will be displaying a simple button and on clicking that button we will be making a live stream on YouTube. A sample video is given below to get an idea about what we are going to do in this article. Note that we are going to implement this project using the Java language. 

Step by Step Implementation

Step 1: Create a New Project

To create a new project in Android Studio please refer to How to Create/Start a New Project in Android Studio. Note that select Java as the programming language.

Step 2: Working with the activity_main.xml file

Navigate to the app > res > layout > activity_main.xml and add the below code to that file. Below is the code for the activity_main.xml file. 


<?xml version="1.0" encoding="utf-8"?>
<!--in this we are displaying a nested scroll view-->
    <!--button for starting youtube livestream video-->
        android:text="Start Youtube Live Stream"
        android:textAllCaps="false" />

Step 3: Working with the file

Go to the file and refer to the following code. Below is the code for the file. Comments are added inside the code to understand the code in more detail.


import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
import java.util.List;
public class MainActivity extends AppCompatActivity {
    // creating a variable for button
    // to start youtube live stream
    private Button startBtn;
    protected void onCreate(Bundle savedInstanceState) {
        // adding on click listener to our button.
        startBtn = findViewById(;
        startBtn.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                // calling a method to check if the device has
                // support to make youtube live stream or not.
    private boolean canResolveMobileLiveIntent(Context context) {
        // in this method we are calling a youtube live  intent package name
        // and we are checking if youtube live intent is present or not.
        Intent intent = new Intent("").setPackage("");
        PackageManager pm = context.getPackageManager();
        List resolveInfo = pm.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
        // returning the result after checking
        // the youtube live stream intent.
        return resolveInfo != null && !resolveInfo.isEmpty();
    private void validateMobileLiveIntent(Context context) {
        if (canResolveMobileLiveIntent(context)) {
            // Launch the live stream Activity
        } else {
            // on below line displaying a toast message if the intent is not present.
            Toast.makeText(context, "Please Update your Youtube app.", Toast.LENGTH_SHORT).show();
            // Prompt user to install or upgrade the YouTube app
    // method to create our intent for youtube live stream.
    private Intent createMobileLiveIntent(Context context, String description) {
        // on below line we are creating a new intent and we are setting package name to it.
        Intent intent = new Intent("").setPackage("");
        // on below line we are creating a new uri and setting
        // a scheme to it and appending our path with our package name.
        Uri referrer = new Uri.Builder()
        // on above line we are building our intent.
        // on below line we are adding our referer
        // and subject for our live video.
        intent.putExtra(Intent.EXTRA_REFERRER, referrer);
        if (!TextUtils.isEmpty(description)) {
            intent.putExtra(Intent.EXTRA_SUBJECT, description);
        // at last we are returning intent.
        return intent;
    private void startMobileLive(Context context) {
        // calling a method to create an intent.
        Intent mobileLiveIntent = createMobileLiveIntent(context, "Streaming via ...");
        // on below line we are calling
        // our activity to start stream

Now run your app and see the output of the app.


My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!