List of usage examples for android.content Intent setDataAndType
public @NonNull Intent setDataAndType(@Nullable Uri data, @Nullable String type)
From source file:com.github.notizklotz.derbunddownloader.issuesgrid.DownloadedIssuesActivity.java
private void openPDF(String uri) { Intent intent = new Intent(Intent.ACTION_VIEW); intent.setDataAndType(Uri.fromFile(new File(uri)), MEDIA_TYPE_PDF); intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY); PackageManager packageManager = getPackageManager(); assert packageManager != null; if (intent.resolveActivity(packageManager) != null) { startActivity(intent);//from ww w. j av a2 s .co m } else { Toast.makeText(this, R.string.no_pdf_reader, Toast.LENGTH_LONG).show(); } }
From source file:com.amaze.filemanager.utils.files.FileUtils.java
/** * Method supports showing a UI to ask user to open a file without any extension/mime *//*from w w w . ja v a2 s . co m*/ public static void openWith(final File f, final Context c, final boolean useNewStack) { MaterialDialog.Builder a = new MaterialDialog.Builder(c); a.title(c.getString(R.string.openas)); String[] items = new String[] { c.getString(R.string.text), c.getString(R.string.image), c.getString(R.string.video), c.getString(R.string.audio), c.getString(R.string.database), c.getString(R.string.other) }; a.items(items).itemsCallback((materialDialog, view, i, charSequence) -> { Uri uri = fileToContentUri(c, f); if (uri == null) uri = Uri.fromFile(f); Intent intent = new Intent(); intent.setAction(Intent.ACTION_VIEW); switch (i) { case 0: if (useNewStack) applyNewDocFlag(intent); intent.setDataAndType(uri, "text/*"); break; case 1: intent.setDataAndType(uri, "image/*"); break; case 2: intent.setDataAndType(uri, "video/*"); break; case 3: intent.setDataAndType(uri, "audio/*"); break; case 4: intent = new Intent(c, DatabaseViewerActivity.class); intent.putExtra("path", f.getPath()); break; case 5: intent.setDataAndType(uri, "*/*"); break; } try { c.startActivity(intent); } catch (Exception e) { Toast.makeText(c, R.string.noappfound, Toast.LENGTH_SHORT).show(); openWith(f, c, useNewStack); } }); try { a.build().show(); } catch (Exception e) { e.printStackTrace(); } }
From source file:com.danielhalupka.imageviewer.ImageViewer.java
@Override public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException { try {/*from w w w .j a va2s .com*/ if (ACTION_VIEW_IMAGE.equals(action)) { JSONObject arg_object = args.getJSONObject(0); Intent intent = new Intent(); intent.setAction(Intent.ACTION_VIEW); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); String filePath = arg_object.getString("filepath"); intent.setDataAndType(Uri.parse(filePath), "image/*"); this.cordova.getActivity().startActivity(intent); callbackContext.success(); return true; } callbackContext.error("Invalid action"); return false; } catch (JSONException e) { System.err.println("Exception: " + e.getMessage()); callbackContext.error(e.getMessage()); return false; } }
From source file:com.github.vase4kin.teamcityapp.artifact.router.ArtifactRouterImpl.java
/** * {@inheritDoc}/* w ww .ja va2s.c o m*/ */ @Override public void startFileActivity(File file) { MimeTypeMap map = MimeTypeMap.getSingleton(); String ext = MimeTypeMap.getFileExtensionFromUrl(file.getName()); String type = map.getMimeTypeFromExtension(ext); if (type == null) { type = ALL_FILES_TYPE; } Intent intent = new Intent(Intent.ACTION_VIEW); Uri data = FileProvider.getUriForFile(mActivity, BuildConfig.APPLICATION_ID + ".provider", file); intent.setDataAndType(data, type); intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION); //User couldn't have app with type intent try { mActivity.startActivity(intent); } catch (android.content.ActivityNotFoundException e) { intent.setDataAndType(data, ALL_FILES_TYPE); mActivity.startActivity(intent); } }
From source file:cn.net_show.doctor.activity.AuthActivity.java
public void onClick(View v) { switch (v.getId()) { case R.id.btn_back: this.finish(); break;//from ww w . j av a 2 s. com case R.id.authImage: Intent intent = new Intent(Intent.ACTION_PICK); intent.setDataAndType(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, "image/*"); startActivityForResult(intent, 1111); break; case R.id.btn_auth: if (isUpload) { Toast.makeText(this, "???", Toast.LENGTH_SHORT).show(); return; } if (uri == null) { Toast.makeText(this, "?", Toast.LENGTH_SHORT).show(); return; } else { if (pd == null) { getProcessDialog(); } pd.show(); String key = ""; if (rdgroup.getCheckedRadioButtonId() == R.id.rd_qw) { key = "license"; } else { key = "plate"; } auth(key); } break; default: break; } }
From source file:com.luorrak.ouroboros.deepzoom.DeepZoomFragment.java
@Override public void onActivityCreated(@Nullable Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); if (mediaItem.ext.equals(".webm") || mediaItem.ext.equals(".mp4")) { mediaPlayButton.setVisibility(View.VISIBLE); mediaPlayButton.setOnClickListener(new View.OnClickListener() { @Override/*from w w w .ja v a 2 s.co m*/ public void onClick(View v) { Uri uri = Uri.parse(ChanUrls.getImageUrl(boardName, mediaItem.fileName, mediaItem.ext)); Intent intent = new Intent(Intent.ACTION_VIEW, uri); intent.setDataAndType(uri, "video/" + mediaItem.ext.substring(1)); startActivity(intent); } }); } }
From source file:com.activiti.android.app.fragments.task.TaskFormFragment.java
@Subscribe public void onDownloadTransferEvent(DownloadTransferEvent event) { if (event.hasException) { Snackbar.make(getActivity().findViewById(R.id.left_panel), event.exception.getMessage(), Snackbar.LENGTH_SHORT).show(); return;/* w w w .j a v a 2 s. c o m*/ } hideWaiting(); try { switch (event.mode) { case ContentTransferSyncAdapter.MODE_SHARE: Intent sendIntent = new Intent(Intent.ACTION_SEND); sendIntent.putExtra(Intent.EXTRA_SUBJECT, event.data.getName()); sendIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(event.data)); sendIntent.setType(event.mimetype); getActivity().startActivity( Intent.createChooser(sendIntent, getResources().getText(R.string.action_send_file))); break; case ContentTransferSyncAdapter.MODE_OPEN_IN: Intent viewIntent = new Intent(Intent.ACTION_VIEW); viewIntent.putExtra(Intent.EXTRA_SUBJECT, event.data.getName()); viewIntent.setDataAndType(Uri.fromFile(event.data), event.mimetype); startActivity(viewIntent); break; } } catch (ActivityNotFoundException e) { Snackbar.make(getActivity().findViewById(R.id.left_panel), R.string.file_editor_error_open, Snackbar.LENGTH_SHORT).show(); } }
From source file:br.com.viniciuscr.notification2android.mediaPlayer.MusicUtils.java
static void activateTab(Activity a, int id) { Intent intent = new Intent(Intent.ACTION_PICK); switch (id) { case R.id.artisttab: intent.setDataAndType(Uri.EMPTY, "vnd.android.cursor.dir/artistalbum"); break;// w ww .ja v a 2 s . c o m case R.id.albumtab: intent.setDataAndType(Uri.EMPTY, "vnd.android.cursor.dir/album"); break; case R.id.songtab: intent.setDataAndType(Uri.EMPTY, "vnd.android.cursor.dir/track"); break; case R.id.playlisttab: intent.setDataAndType(Uri.EMPTY, MediaStore.Audio.Playlists.CONTENT_TYPE); break; case R.id.nowplaying: // intent = new Intent(a, MediaPlaybackActivity.class); // a.startActivity(intent); // fall through and return default: return; } intent.putExtra("withtabs", true); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); a.startActivity(intent); a.finish(); a.overridePendingTransition(0, 0); }
From source file:com.ducnd.recordvideo_sample.CaptureDemoFragment.java
public void playVideo() { if (filename == null) return;//from w ww . j a v a 2 s. com final Intent videoIntent = new Intent(Intent.ACTION_VIEW); videoIntent.setDataAndType(Uri.parse(filename), "video/*"); try { startActivity(videoIntent); } catch (ActivityNotFoundException e) { // NOP } }
From source file:com.f2prateek.dfg.ui.activities.MainActivity.java
@Subscribe public void onSingleImageProcessed(final Events.SingleImageProcessed event) { Snackbar.make(pager, getString(R.string.single_screenshot_saved, event.device.name()), Snackbar.LENGTH_LONG) .setAction(R.string.open, new View.OnClickListener() { @Override/*from w ww. j a v a2 s .c om*/ public void onClick(View v) { Intent launchIntent = new Intent(Intent.ACTION_VIEW); launchIntent.setDataAndType(event.uri, "image/png"); launchIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(launchIntent); } }).show(); }