2

I have an android application. I just need to open youtube application home activity from my android application. Please note I do not want to open any specific video or channel. Just want to open application. I have gone through this and this but all are for opening any video or channel. Please suggest me if anyone knows this.

Note: Application is running on TV and android version is 4.4

Community
  • 1
  • 1
vijaypalod
  • 398
  • 4
  • 15

5 Answers5

2

for opening any app form your device you have to know the package name of that app......

By firing an intent of that package name you can open an app form your app but if intent does not get a package name than no intent is their for handle that intent so take care of it...

Intent LaunchIntent = getPackageManager().getLaunchIntentForPackage("any package name you want to open");
startActivity( LaunchIntent );

In your case it is youtube so package name is :

 com.google.android.youtube
santoXme
  • 802
  • 5
  • 20
1

open app using package name youtube package name is com.google.android.youtube so you can use below intent code

try {
       Intent LaunchIntent = packageManager.getLaunchIntentForPackage("com.google.android.youtube");
       startActivity(LaunchIntent);
    } catch (Exception e) {
            e.printStackTrace();
    }

just surround with try catch if in case package not found to get package name of any app use this Application on Google Play

same code work for Android TV

Dhaval Parmar
  • 18,812
  • 8
  • 82
  • 177
  • 1
    I am getting `LaunchIntent` null even if youtube app is installed in phone. – vijaypalod Dec 23 '15 at 06:11
  • @Palod's: post your code in question or try in different devices working or not because this code is working fine in live apps on google play which i have share in answer. – Dhaval Parmar Dec 23 '15 at 06:18
1

Actually the package name for youtube app in TV was not same as that in phones. the package name for youtube app on TV is "com.google.android.youtube.googletv" so following code worked for me.

Intent LaunchIntent = getPackageManager().getLaunchIntentForPackage("com.google.android.youtube.googletv");
startActivity( LaunchIntent ); 
vijaypalod
  • 398
  • 4
  • 15
0

This will work on a device but not the emulator

startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.youtube.com/watch?v=cxLG2wtE7TM")));
Quang Doan
  • 632
  • 4
  • 12
  • 1
    you should not copy answers from other posts, and that too as it is. This is copied from [HERE](http://stackoverflow.com/questions/574195/android-youtube-app-play-video-intent). You could have just provided a reference or at least given credit to the person who actually answered it. – Viral Patel Dec 23 '15 at 06:12
  • 4
    **Funny thing even the video id is same as in the post the answer is copied from**. – Viral Patel Dec 23 '15 at 06:19
0

Try this :

public static void openInstalledApp(Context context, String bundle_id) {

    PackageManager pm = context.getPackageManager();
    Intent appStartIntent = pm.getLaunchIntentForPackage(bundle_id);
    if (null != appStartIntent) {
        context.startActivity(appStartIntent);
    }

}

And use it :

openInstalledApp(<your_context>,"com.google.android.youtube");

Where in second param you can pass any bundleID which is installed in your device and you wants to open it.

Kishan Soni
  • 816
  • 1
  • 6
  • 19