List of usage examples for android.content Intent setDataAndType
public @NonNull Intent setDataAndType(@Nullable Uri data, @Nullable String type)
From source file:com.littlepancake.glpk.HelpFragment.java
private void openGplTxt() { AssetManager assetManager = getActivity().getAssets(); File file = new File(getActivity().getFilesDir(), gplv3FileName); if (!file.exists()) { InputStream in = null;//from w w w. j a v a2 s. com OutputStream out = null; try { in = assetManager.open(gplv3FileName); /* Note that "MODE_WORLD_READABLE" is "dangerous". It seems the alternative is * for me to write a few hundred more lines of code or something. Guess I'll * remain dangerous for this app. * See: * https://github.com/commonsguy/cw-omnibus/tree/master/ContentProvider/Files * for the proper, code-intensive way to handle this. */ out = getActivity().openFileOutput(file.getName(), Context.MODE_WORLD_READABLE); byte[] buffer = new byte[buff_size]; int read; while ((read = in.read(buffer)) != -1) { out.write(buffer, 0, read); Log.d("tag", "Read and wrote " + read + " bytes."); } in.close(); out.flush(); out.close(); } catch (IOException e) { Log.e("tag", e.getMessage()); } } else { //Log.d("tag", gplv3FileName+" already exists."); } Intent intent = new Intent(Intent.ACTION_VIEW); intent.setDataAndType(Uri.parse("file://" + getActivity().getFilesDir() + "/" + gplv3FileName), "text/plain"); startActivity(intent); }
From source file:com.littlepancake.glpk.HelpFragment.java
private void openGlpkPdf() { AssetManager assetManager = getActivity().getAssets(); File file = new File(getActivity().getFilesDir(), glpkPdfName); if (!file.exists()) { InputStream in = null;//from ww w . j ava 2s. co m OutputStream out = null; try { in = assetManager.open(glpkPdfName); /* Note that "MODE_WORLD_READABLE" is "dangerous". It seems the alternative is * for me to write a few hundred more lines of code or something. Guess I'll * remain dangerous for this app. * See: * https://github.com/commonsguy/cw-omnibus/tree/master/ContentProvider/Files * for the proper, code-intensive way to handle this. */ out = getActivity().openFileOutput(file.getName(), Context.MODE_WORLD_READABLE); byte[] buffer = new byte[buff_size]; int read; while ((read = in.read(buffer)) != -1) { out.write(buffer, 0, read); } in.close(); out.flush(); out.close(); out = null; in = null; } catch (IOException e) { Log.e("tag", e.getMessage()); } } else { //Log.d("tag", glpkPdfName+" already exists."); } Intent intent = new Intent(Intent.ACTION_VIEW); intent.setDataAndType(Uri.parse("file://" + getActivity().getFilesDir() + "/" + glpkPdfName), "application/pdf"); startActivity(intent); }
From source file:com.amo.meer.APPVersion.java
private void update() { Intent intent = new Intent(Intent.ACTION_VIEW); intent.setDataAndType(Uri.fromFile(new File(Environment.getExternalStorageDirectory(), UPDATE_SAVENAME)), "application/vnd.android.package-archive"); context.startActivity(intent);/*from w ww .j a va 2 s .co m*/ }
From source file:com.github.se_bastiaan.torrentstreamer.sample.MainActivity.java
@Override public void onStreamReady(Torrent torrent) { progressBar.setProgress(100);//from w w w. j a v a2 s . c o m Log.d(TORRENT, "onStreamReady: " + torrent.getVideoFile()); Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(torrent.getVideoFile().toString())); intent.setDataAndType(Uri.parse(torrent.getVideoFile().toString()), "video/mp4"); startActivity(intent); }
From source file:butter.droid.base.ButterApplication.java
@Override public void updateAvailable(String updateFile) { NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); if (updateFile.length() > 0) { NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_notif_logo).setContentTitle(getString(R.string.update_available)) .setContentText(getString(R.string.press_install)).setAutoCancel(true) .setDefaults(NotificationCompat.DEFAULT_ALL); Intent notificationIntent = new Intent(Intent.ACTION_VIEW); notificationIntent.setDataAndType(Uri.parse("file://" + updateFile), ButterUpdater.ANDROID_PACKAGE); notificationBuilder.setContentIntent(PendingIntent.getActivity(this, 0, notificationIntent, 0)); nm.notify(ButterUpdater.NOTIFICATION_ID, notificationBuilder.build()); }/*ww w . jav a2s .c om*/ }
From source file:com.google.android.demos.jamendo.app.AlbumActivity.java
@Override public boolean onPrepareOptionsMenu(Menu menu) { super.onPrepareOptionsMenu(menu); int groupId = MENU_GROUP_INTENT_OPTIONS; int itemId = Menu.NONE; int order = Menu.NONE; ComponentName caller = getComponentName(); Intent[] specifics = null;/*from w w w . j a v a 2 s . co m*/ Intent intent = new Intent(); long id = ContentUris.parseId(getIntent().getData()); intent.setDataAndType(JamendoContract.createPlaylistUri(JamendoContract.FORMAT_M3U, Albums.ID, id), JamendoContract.CONTENT_TYPE_M3U); intent.addCategory(Intent.CATEGORY_ALTERNATIVE); int flags = 0; MenuItem[] outSpecificItems = null; menu.addIntentOptions(groupId, itemId, order, caller, specifics, intent, flags, outSpecificItems); return menu.hasVisibleItems(); }
From source file:com.commonsware.android.camcon.MainActivity.java
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == CONTENT_REQUEST) { if (resultCode == RESULT_OK) { Intent i = new Intent(Intent.ACTION_VIEW); Uri outputUri = FileProvider.getUriForFile(this, AUTHORITY, output); i.setDataAndType(outputUri, "image/jpeg"); i.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); try { startActivity(i);/*from w ww. jav a 2 s .com*/ } catch (ActivityNotFoundException e) { Toast.makeText(this, R.string.msg_no_viewer, Toast.LENGTH_LONG).show(); } finish(); } } }
From source file:com.dycody.android.idealnote.GalleryActivity.java
private void viewMedia() { Attachment attachment = images.get(mViewPager.getCurrentItem()); Intent intent = new Intent(Intent.ACTION_VIEW); intent.setDataAndType(attachment.getUri(), StorageHelper.getMimeType(this, attachment.getUri())); startActivity(intent);// w w w .j a v a 2 s . c o m }
From source file:com.geekandroid.sdk.sample.crop.ResultActivity.java
private void showNotification(@NonNull File file) { Intent intent = new Intent(Intent.ACTION_VIEW); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.setDataAndType(Uri.fromFile(file), "image/*"); NotificationCompat.Builder mNotification = new NotificationCompat.Builder(this); mNotification.setContentTitle(getString(R.string.app_name)) .setContentText(getString(R.string.notification_image_saved_click_to_preview)) .setTicker(getString(R.string.notification_image_saved)).setSmallIcon(R.drawable.ic_done) .setOngoing(false).setContentIntent(PendingIntent.getActivity(this, 0, intent, 0)) .setAutoCancel(true);/* w w w.j av a 2 s . c om*/ ((NotificationManager) getSystemService(NOTIFICATION_SERVICE)).notify(DOWNLOAD_NOTIFICATION_ID_DONE, mNotification.build()); }
From source file:com.github.se_bastiaan.torrentstreamerserver.sample.MainActivity.java
@Override public void onServerReady(String url) { Log.d(TORRENT, "onServerReady: " + url); videoLocationText.setText(url);//from ww w . j a v a 2s. co m Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); intent.setDataAndType(Uri.parse(url), "video/mp4"); startActivity(intent); }