updated 2015. 4. 21
Youtube 3.0 version
------------------------------------------------------------
Youtube 영상보기
Youtube 의 영상을 바로 실행시키려면 아래의 코드를 사용하면 된다.StringBuilder sb = new StringBuilder("vnd.youtube:");
sb.append("YoutubeID");
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(sb.toString())));
- http://www.youtube.com/watch?v=Xw0URnMrFV8
에서 Xw0URnMrFV8 가 YoutubeID 가 된다.
Default app 의 호출이 실패할 때[ref. 3]
// default youtube app
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse("vnd.youtube:" + videoID));
List list = getPackageManager().queryIntentActivities(i, PackageManager.MATCH_DEFAULT_ONLY);
if (list.size() == 0) {
// default youtube app not present or doesn't conform to the standard we know
// use our own activity
i = new Intent(getApplicationContext(), YouTube.class);
i.putExtra("VIDEO_ID", videoID);
}
startActivity(i);
}
Youtube 에서 검색하기
Youtube 에서 검색(search) 를 하려면 아래의 코드를 사용하면 된다.Intent intent = new Intent(Intent.ACTION_SEARCH);
intent.setPackage("com.google.android.youtube");
intent.putExtra("query", "what_you_want_to_search");
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
See Also
- YouTube API v2.0 – API Query Parameters - YouTube — Google Developers from https://developers.google.com/youtube/2.0/developers_guide_protocol_api_query_parameters
댓글 없음:
댓글 쓰기