/
YouTubeApp.java
31 lines (24 loc) · 938 Bytes
/
YouTubeApp.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package com.thefinestartist.ytpa.utils;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.net.Uri;
import android.support.annotation.NonNull;
import java.util.List;
/**
* Created by TheFinestArtist on 2/16/15.
*/
public class YouTubeApp {
private YouTubeApp() {}
public static void startVideo(@NonNull Context context, @NonNull String videoId) {
Uri video_uri = Uri.parse(YouTubeUrlParser.getVideoUrl(videoId));
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("vnd.youtube:" + videoId));
List<ResolveInfo> list = context.getPackageManager().queryIntentActivities(
intent,
PackageManager.MATCH_DEFAULT_ONLY);
if (list.isEmpty())
intent = new Intent(Intent.ACTION_VIEW, video_uri);
context.startActivity(intent);
}
}