how to redirect on youtube in androi
Posted
by
rajshree
on Stack Overflow
See other posts from Stack Overflow
or by rajshree
Published on 2013-10-30T03:52:45Z
Indexed on
2013/10/30
3:53 UTC
Read the original article
Hit count: 154
android
public class MovieDescription extends Activity {
Vibrator vibrator;
TextView tv_title,tv_year,tv_banner,tv_desc;
RatingBar ratingBar;
ImageView iv_watch,iv_poster;
private static final String TAG_CONTACTS = "Demo";
private static final String TAG_ID = "id";
private static final String TAG_TITLE = "title";
private static final String TAG_YEAR = "year";
private static final String TAG_RATING = "rating";
private static final String TAG_BANNER= "category";
private static final String TAG_DESC = "description";
private static final String TAG_URL = "url";
private static final String TAG_POSTER = "poster";
String id,title,year,rating,banner,description,poster, movieUrl;
static JSONArray contacts = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.movie_description);
initialize();
String movieDescUrl = "http://vaibhavtech.com/work/android/movie_description.php?id="+MainActivity.movie_Id;
MovieDescriptionParser jParser = new MovieDescriptionParser();
JSONObject json = jParser.getJSONFromUrl(movieDescUrl);
try {
contacts = json.getJSONArray(TAG_CONTACTS);
for (int i = 0; i < contacts.length(); i++)
{
/**********************************Value Parse FromUrl**********************************/
JSONObject c = contacts.getJSONObject(i);
id = c.getString(TAG_ID);
title = c.getString(TAG_TITLE);
year = c.getString(TAG_YEAR);
rating = c.getString(TAG_RATING);
banner=c.getString(TAG_BANNER);
description = c.getString(TAG_DESC);
movieUrl = c.getString(TAG_URL);
poster = c.getString(TAG_POSTER);
/**********************************Valeu Assing to UI Component**********************************/
Log.i(id, title);
}
} catch (JSONException e) {
e.printStackTrace();
}
tv_title.setText(title);
tv_year.setText(year);
tv_banner.setText(banner);
tv_desc.setText(description);
Float rat=Float.parseFloat(rating);
ratingBar.setRating(rat);
Bitmap bimage= getBitmapFromURL("http://vaibhavtech.com/work/android/admin/upload/"+poster);
iv_poster.setImageBitmap(bimage);
iv_watch.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
vibrator.vibrate(40);
LayoutInflater inflater=getLayoutInflater();
View view=inflater.inflate(R.layout.customtoast,(ViewGroup)findViewById(R.id.custom_toast_layout));
Toast toast=new Toast(getApplicationContext());
toast.setDuration(Toast.LENGTH_LONG);
toast.setGravity(Gravity.CENTER_HORIZONTAL, 0, 0);
toast.setView(view);
toast.show();
Intent intent=new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(movieUrl));
startActivity(intent);
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// TODO Auto-generated method stub
int currentapiVersion = android.os.Build.VERSION.SDK_INT;
Log.i("Device Versoin is", ""+currentapiVersion);
if (currentapiVersion >= android.os.Build.VERSION_CODES.JELLY_BEAN){
ActionBar actionBar = getActionBar();
actionBar.setHomeButtonEnabled(true);
actionBar.setDisplayHomeAsUpEnabled(true);
getMenuInflater().inflate(R.menu.main, menu);
}
return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// TODO Auto-generated method stub
switch (item.getItemId()) {
case android.R.id.home:
onBackPressed();
return true;
case R.id.home:
Intent intent = new Intent(this, MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
Log.i("Home", "Press");
return true;
}
return super.onOptionsItemSelected(item);
}
public void initialize()
{
tv_banner=(TextView) findViewById(R.id.tv_movie_description_banner);
tv_desc=(TextView) findViewById(R.id.tv_movie_description_decription);
tv_title=(TextView) findViewById(R.id.tv_movie_description_name);
tv_year=(TextView) findViewById(R.id.tv_movie_description_year);
ratingBar=(RatingBar) findViewById(R.id.ratingBar1);
iv_watch=(ImageView) findViewById(R.id.iv_movie_description_watch);
iv_poster=(ImageView) findViewById(R.id.iv_movie_description_poster);
vibrator=(Vibrator)getSystemService(Context.VIBRATOR_SERVICE);;
}
public static Bitmap getBitmapFromURL(String src) {
try {
Log.i("src",src);
URL url = new URL(src);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setDoInput(true);
connection.connect();
InputStream input = connection.getInputStream();
Bitmap myBitmap = BitmapFactory.decodeStream(input);
Log.i("Bitmap","returned");
return myBitmap;
} catch (IOException e) {
e.printStackTrace();
Log.e("Exception",e.getMessage());
return null;
}
}
}
when i am clciking on watch now button its giving me 4 options -by mozilz,by chrome,by youtube, i want that when i click on watch now button it get redirect on youtube url link,..how can i do this please give me any suggetion.:(
© Stack Overflow or respective owner