0

I want to open my YouTube channel link in YouTube Android app, if YouTube app is installed on the device.

If YouTube app is not installed, then show available browser to open the link.

I found below code for facebook, But I want to implemnet similar functionality for YouTube.

ImageView ifb = (ImageView) findViewById(R.id.fb);
        ifb.setOnClickListener(new View.OnClickListener() {
            public void onClick(View paramAnonymousView) {
                try {
                    Intent localIntent = new Intent(
                            "android.intent.action.VIEW", Uri
                                    .parse("fb://profile/987987646432132"));
                    SettingsActivity.this.startActivity(localIntent);
                    return;
                } catch (Exception localException) {
                    SettingsActivity.this.startActivity(new Intent(
                            "android.intent.action.VIEW",
                            Uri.parse("http://www.facebook.com/myfacebookpageurl")));
                }
            }
        });
AADProgramming
  • 5,124
  • 11
  • 32
  • 56
user3733739
  • 57
  • 1
  • 7
  • do not use youtube specific uris(i don't know if such even exist) just use uri which starts with `http://..` system will ask user to choose between browser or youtube app – Selvin Jan 12 '15 at 14:30
  • 1
    I am quite sure that same problem has been discussed here: http://stackoverflow.com/questions/16510860/open-youtube-channel-calling-youtube-app-android – pkuszewski Jan 12 '15 at 14:34

1 Answers1

1
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.youtube.com/user/your-youtube-channel")));

This should open Android System's App chooser so that user can choose set of apps to complete action. User can decide if YouTube(or any other)app is to be used (Only Once or Always).

If user chooses "Always", then Android should launch subsequent YouTube channels using YouTube App.

To check if YouTube is installed or not, below code can be used:

protected boolean isYouTubeAppInstalled(String packageName) {
    Intent mIntent = getPackageManager().getLaunchIntentForPackage(packageName);
    if (mIntent != null) {
        return true;
    }
    else {
        return false;
    }
}

You should be passing "com.google.android.youtube" to above method.

If YouTube is not installed (or disabled), Android should start YouTube channel using Browser.

AADProgramming
  • 5,124
  • 11
  • 32
  • 56