List of usage examples for android.content Intent ACTION_VIEW
String ACTION_VIEW
To view the source code for android.content Intent ACTION_VIEW.
Click Source Link
From source file:com.xmartlabs.cordova.market.Market.java
/** * Open the appId details on Google Play . * * @param appId//from w w w . jav a 2 s. co m * Application Id on Google Play. * E.g.: com.google.earth */ private void openGooglePlay(String appId) throws android.content.ActivityNotFoundException { Context context = this.cordova.getActivity().getApplicationContext(); Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + appId)); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(intent); }
From source file:com.proofhq.Open.java
/** * Creates an intent for the data of mime type * * @param path// ww w. j a v a 2 s . com * @param callbackContext */ private void chooseIntent(String path, CallbackContext callbackContext) { if (path != null && path.length() > 0) { try { Uri uri = Uri.parse(path); String mime = getMimeType(path); Intent fileIntent = new Intent(Intent.ACTION_VIEW); if (Build.VERSION.SDK_INT > 15) { fileIntent.setDataAndTypeAndNormalize(uri, mime); // API Level 16 -> Android 4.1 } else { fileIntent.setDataAndType(uri, mime); } cordova.getActivity().startActivity(fileIntent); callbackContext.success(); } catch (ActivityNotFoundException e) { e.printStackTrace(); callbackContext.error(1); } } else { callbackContext.error(2); } }
From source file:com.appnexus.opensdk.PBImplementation.java
private static void launchApp(Context context) { Intent intent = new Intent(Intent.ACTION_VIEW, URI_LAUNCH_APP); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); try {//from w ww . j a v a 2s .c o m context.startActivity(intent); } catch (ActivityNotFoundException e) { Clog.w(Clog.baseLogTag, Clog.getString(R.string.opening_url_failed, URI_LAUNCH_APP.toString())); } }
From source file:com.phonegap.cordova.FileOpener.java
private void openFile(String url) throws IOException { // Create URI Uri uri = Uri.parse(url);// w ww . jav a 2 s. c o m Intent intent = null; // Check what kind of file you are trying to open, by comparing the url with extensions. // When the if condition is matched, plugin sets the correct intent (mime) type, // so Android knew what application to use to open the file if (url.contains(".doc") || url.contains(".docx")) { // Word document intent = new Intent(Intent.ACTION_VIEW); intent.setDataAndType(uri, "application/msword"); } else if (url.contains(".pdf")) { // PDF file intent = new Intent(Intent.ACTION_VIEW); intent.setDataAndType(uri, "application/pdf"); } else if (url.contains(".ppt") || url.contains(".pptx")) { // Powerpoint file intent = new Intent(Intent.ACTION_VIEW); intent.setDataAndType(uri, "application/vnd.ms-powerpoint"); } else if (url.contains(".xls") || url.contains(".xlsx")) { // Excel file intent = new Intent(Intent.ACTION_VIEW); intent.setDataAndType(uri, "application/vnd.ms-excel"); } else if (url.contains(".rtf")) { // RTF file intent = new Intent(Intent.ACTION_VIEW); intent.setDataAndType(uri, "application/rtf"); } else if (url.contains(".wav")) { // WAV audio file intent = new Intent(Intent.ACTION_VIEW); intent.setDataAndType(uri, "audio/x-wav"); } else if (url.contains(".gif")) { // GIF file intent = new Intent(Intent.ACTION_VIEW); intent.setDataAndType(uri, "image/gif"); } else if (url.contains(".jpg") || url.contains(".jpeg")) { // JPG file intent = new Intent(Intent.ACTION_VIEW); intent.setDataAndType(uri, "image/jpeg"); } else if (url.contains(".png")) { // PNG file intent = new Intent(Intent.ACTION_VIEW); intent.setDataAndType(uri, "image/png"); } else if (url.contains(".txt")) { // Text file intent = new Intent(Intent.ACTION_VIEW); intent.setDataAndType(uri, "text/plain"); } else if (url.contains(".mpg") || url.contains(".mpeg") || url.contains(".mpe") || url.contains(".mp4") || url.contains(".avi")) { // Video files intent = new Intent(Intent.ACTION_VIEW); intent.setDataAndType(uri, "video/*"); } //if you want you can also define the intent type for any other file //additionally use else clause below, to manage other unknown extensions //in this case, Android will show all applications installed on the device //so you can choose which application to use else { intent = new Intent(Intent.ACTION_VIEW); intent.setDataAndType(uri, "*/*"); } this.cordova.getActivity().startActivity(intent); }
From source file:com.github.longkai.zhihu.util.Utils.java
public static void viewOnWeb(Context context, Uri uri) { Intent intent = new Intent(Intent.ACTION_VIEW); intent.setData(uri);/*from w w w .java 2s . c o m*/ context.startActivity(intent); }
From source file:com.applechip.android.showcase.rest.GoogleSearchGsonActivity.java
@Override protected void onListItemClick(android.widget.ListView l, android.view.View v, int position, long id) { if (this.results == null) { return;/*from w w w. j a v a2 s .co m*/ } GoogleSearchResult result = this.results.get(position); startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(result.getUrl()))); }
From source file:com.beesham.popularmovies.ReviewAdapter.java
@Override public View getView(int position, View convertView, ViewGroup parent) { final DetailsFragment.Reviews reviews = getItem(position); if (convertView == null) { convertView = LayoutInflater.from(getContext()).inflate(R.layout.list_item_review, parent, false); }//from ww w . ja va2 s . c o m ButterKnife.bind(this, convertView); reviewAuthorTextView.setText(reviews.getAuthor()); readReviewButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Intent intent = new Intent(Intent.ACTION_VIEW); intent.setData(Uri.parse(reviews.getUrl())); if (intent.resolveActivity(getContext().getPackageManager()) != null) { getContext().startActivity(intent); } } }); return convertView; }
From source file:com.epsi.plugins.cordova.CafeBazaar.java
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) { if (action.equals("display-app")) { try {/*www. ja va 2 s. c o m*/ JSONObject arg_object = args.getJSONObject(0); String app = arg_object.getString("app"); Intent intent = new Intent(Intent.ACTION_VIEW); intent.setData(Uri.parse("bazaar://details?id=" + app)); intent.setPackage("com.farsitel.bazaar"); this.cordova.getActivity().startActivity(intent); callbackContext.success("success"); return true; } catch (Exception e) { System.err.println("Exception: " + e.getMessage()); callbackContext.error(e.getMessage()); return false; } } if (action.equals("rate-app")) { try { JSONObject arg_object = args.getJSONObject(0); String app = arg_object.getString("app"); Intent intent = new Intent(Intent.ACTION_EDIT); intent.setData(Uri.parse("bazaar://details?id=" + app)); intent.setPackage("com.farsitel.bazaar"); this.cordova.getActivity().startActivity(intent); callbackContext.success("success"); return true; } catch (Exception e) { System.err.println("Exception: " + e.getMessage()); callbackContext.error(e.getMessage()); return false; } } if (action.equals("disp-developer")) { try { JSONObject arg_object = args.getJSONObject(0); String developer = arg_object.getString("developer"); Intent intent = new Intent(Intent.ACTION_VIEW); intent.setData(Uri.parse("bazaar://collection?slug=by_author&aid=" + developer)); intent.setPackage("com.farsitel.bazaar"); this.cordova.getActivity().startActivity(intent); callbackContext.success("success"); return true; } catch (Exception e) { System.err.println("Exception: " + e.getMessage()); callbackContext.error(e.getMessage()); return false; } } //callbackContext.error("false command"); return true; }
From source file:jp.bugscontrol.github.GithubLogin.java
@Override protected void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); final Uri data = getIntent().getData(); if (data != null) { final String responseState = data.getQueryParameter("state"); if (state.equals(responseState)) { final String code = data.getQueryParameter("code"); new OauthTask(code).execute(); } else {//from www.j av a2 s.c o m // TODO give feedback to the user finish(); } return; } state = String.valueOf(UUID.randomUUID().hashCode()); final String githubUrl = "https://github.com/login/oauth/authorize?scope=user,repo&client_id=" + CLIENT_ID + "&state=" + state; startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(githubUrl))); }
From source file:be.ac.ucl.lfsab1509.llncampus.ExternalAppUtility.java
/** * Start the Google Maps application and navigate the user to the specified location. * /*from w w w.j a v a 2s. c om*/ * @param lat * Destination latitude. * @param lon * Destination longitude. * @param c * Current context. */ public static void startNavigation(float lat, float lon, Context c) { try { Intent intent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse("http://maps.google.com/maps?daddr=" + lat + "," + lon + "&dirflg=w")); intent.setComponent( new ComponentName("com.google.android.apps.maps", "com.google.android.maps.MapsActivity")); c.startActivity(intent); } catch (ActivityNotFoundException e) { // If we don't have Google Maps Log.e("ExternalAppUtility", c.getString(R.string.no_google_maps)); Toast t = Toast.makeText(LLNCampus.getContext().getApplicationContext(), R.string.no_google_maps, Toast.LENGTH_LONG); t.setGravity(Gravity.CENTER, 0, 0); t.show(); } }