How to hide Intent Chooser window in android?

when i click the button, i run the action for youtube video as follows:

startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.youtube.com/watch?v=cxLG2wtE7TM")));

if I use it, redirect it to the choice of intent to open this video URL in a browser or YouTube application. How to choose the default application as youtube programmatically?

my conclusion is to open this video directly on the YouTube player. as? any idea?

+4
source share
2 answers

Requesting a specific activity is risky, as YouTube may change the name of its package, which will follow if your application is violated.

In addition, there is no guarantee that the YT player is installed on all Android devices.

, , youtube. , , "" , .

/**
 * @param context
 * @param url To display, such as http://www.youtube.com/watch?v=t_c6K1AnxAU
 * @return an Intent to start the YouTube Viewer. If it is not found, will
 *         return a generic video-play intent, and system will display a
 *         chooser to ther user.
 */
public static Intent getYouTubeIntent(Context context, String url) {
  Intent videoIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
  final PackageManager pm = context.getPackageManager();
  List<ResolveInfo> activityList = pm.queryIntentActivities(videoIntent, 0);
  for (int i = 0; i < activityList.size(); i++) {
    ResolveInfo app = activityList.get(i);
    if (app.activityInfo.name.contains("youtube")) {
      videoIntent.setClassName(app.activityInfo.packageName, app.activityInfo.name);
      return videoIntent;
    }
  }
  return videoIntent;
}
+7

, , , . , , youtube . . .

, -, , , . , ? , - , ?

: , , :.

Intent intent = new Intent(this, YouTubeViewerActivity.class);
intent.addExtra("URI", Uri.parse("http://www.youtube.com/watch?v=cxLG2wtE7TM"));
startActivity(intent);

, YouTubeViewerActivity. , , - , YouTube, , , , , .

+1

All Articles