SHARE
TWEET

on-create-open-youtube-url

a guest Mar 25th, 2018 65 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ...
  2. @Override
  3.     protected void onCreate(Bundle savedInstanceState) {
  4.         super.onCreate(savedInstanceState);
  5.         setContentView(R.layout.activity_main);
  6.  
  7.  
  8.         if( getIntent() != null
  9.             && getIntent().getStringExtra("URL") != null ){
  10.  
  11.             String urlVideo = getIntent().getStringExtra("URL");
  12.             String videoId = urlVideo.split("v=")[0];
  13.  
  14.             Intent appIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("vnd.youtube:" + videoId));
  15.             Intent webIntent = new Intent(Intent.ACTION_VIEW, Uri.parse( urlVideo ));
  16.  
  17.             try {
  18.                 startActivity(appIntent);
  19.             }
  20.             catch (ActivityNotFoundException ex) {
  21.                 startActivity(webIntent);
  22.             }
  23.             finish();
  24.         }
  25.     }
  26. ...
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top