private void openScreenshot(File imageFile) { Intent intent = new Intent(); intent.setAction(Intent.ACTION_VIEW); Uri uri = Uri.fromFile(imageFile); intent.setDataAndType(uri, "image/*"); startActivity(intent); }
Intent intent = new Intent(Intent.ACTION_VIEW); intent.setDataAndType(Uri.fromFile(new File(Environment.getExternalStorageDirectory() + "/download/" + "app.apk")), "application/vnd.android.package-archive"); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(intent);
Intent intent = new Intent(); intent.setAction(android.content.Intent.ACTION_VIEW); File file = new File(YOUR_SONG_URI); intent.setDataAndType(Uri.fromFile(file), "audio/*"); startActivity(intent);
@Override public void onClick(View v) { Uri video=Uri.fromFile(new File(videoUri)); Intent i=new Intent(Intent.ACTION_VIEW); i.setDataAndType(video, videoMimeType); title.getContext().startActivity(i); }
File file = new File(dir, "App.apk"); Intent intent = new Intent(Intent.ACTION_VIEW); intent.setDataAndType(Uri.fromFile(file), "application/vnd.android.package-archive"); startActivity(intent);
String absolutepath = MyApplication.appRootDir + relpath;//change for your application Intent intent = new Intent(Intent.ACTION_ATTACH_DATA); MimeTypeMap map = MimeTypeMap.getSingleton(); String ext = absolutepath.substring(absolutepath.lastIndexOf('.') + 1); String mimeType = map.getMimeTypeFromExtension(ext); Uri uri = Uri.fromFile(new File(absolutepath)); intent.setDataAndType(uri, mimeType); intent.putExtra("mimeType", mimeType); intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); Activity activity = (Activity) this; activity.startActivity(Intent.createChooser( intent, activity.getString(R.string.set_as)));
private void performCrop(Uri picUri) { try { Intent cropIntent = new Intent("com.android.camera.action.CROP"); // indicate image type and Uri cropIntent.setDataAndType(picUri, "image/*"); // set crop properties here cropIntent.putExtra("crop", true); // indicate aspect of desired crop cropIntent.putExtra("aspectX", 1); cropIntent.putExtra("aspectY", 1); // indicate output X and Y cropIntent.putExtra("outputX", 128); cropIntent.putExtra("outputY", 128); // retrieve data on return cropIntent.putExtra("return-data", true); // start the activity - we handle returning in onActivityResult startActivityForResult(cropIntent, PIC_CROP); } // respond to users whose devices do not support the crop action catch (ActivityNotFoundException anfe) { // display an error message String errorMessage = "Whoops - your device doesn't support the crop action!"; Toast toast = Toast.makeText(this, errorMessage, Toast.LENGTH_SHORT); toast.show(); } }
@Override public void onClick(View v) { Intent i=new Intent(Intent.ACTION_VIEW); i.setDataAndType(videoUri, videoMimeType); title.getContext().startActivity(i); }
/** * 调用自带的视频播放器 * * @param context * @param path */ private static void openVideo(Context context, String path) { Uri uri = Uri.parse(path); Intent intent = new Intent(Intent.ACTION_VIEW); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.setDataAndType(uri, "video/mp4");// "video/mp4" context.startActivity(intent); }
Intent viewIntent = new Intent(Intent.ACTION_VIEW); Intent editIntent = new Intent(Intent.ACTION_EDIT); viewIntent.setDataAndType(uri, type); editIntent.setDataAndType(uri, type); Intent chooserIntent = Intent.createChooser(editIntent, "Open in..."); chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[] { viewIntent }); startActivity(chooserIntent);
Intent intent = new Intent(Intent.ACTION_VIEW); intent.setDataAndType(path, "application/pdf"); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); try { startActivity(intent); } catch (ActivityNotFoundException e) { Toast.makeText(OpenPdf.this, "No Application Available to View PDF", Toast.LENGTH_SHORT).show(); }
public static Intent getInstallApkIntent(File file) { Intent intent = new Intent(); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.setAction(Intent.ACTION_VIEW); intent.setDataAndType(Uri.fromFile(file), "application/vnd.android.package-archive"); return intent; }
File file = new File(Environment.getExternalStorageDirectory().getAbsolutePath()+"/example.pdf"); Intent intent = new Intent(Intent.ACTION_VIEW); intent.setDataAndType(Uri.fromFile(file), "application/pdf"); intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY); startActivity(intent);
@Override public void onClick(View v) { Uri video=Uri.fromFile(new File(videoUri)); Intent i=new Intent(Intent.ACTION_VIEW); i.setDataAndType(video, videoMimeType); title.getContext().startActivity(i); }
protected void openFile(String fileName) { Intent install = new Intent(Intent.ACTION_VIEW); install.setDataAndType(Uri.fromFile(new File(fileName)),"MIME-TYPE"); startActivity(install); }
/**照片裁剪 * @param context * @param requestCode * @param fromFile * @param width * @param height */ public static void startPhotoZoom(Activity context, int requestCode, Uri fileUri, int width, int height) { Intent intent = new Intent("com.android.camera.action.CROP"); intent.setDataAndType(fileUri, "image/*"); // crop为true是设置在开启的intent中设置显示的view可以剪裁 intent.putExtra("crop", "true"); // aspectX aspectY 是宽高的比例 intent.putExtra("aspectX", 1); intent.putExtra("aspectY", 1); // outputX,outputY 是剪裁图片的宽高 intent.putExtra("outputX", width); intent.putExtra("outputY", height); intent.putExtra("return-data", true); Log.i(TAG, "startPhotoZoom"+ fileUri +" uri"); toActivity(context, intent, requestCode); }
@Override public void onClick(View v) { Intent i=new Intent(Intent.ACTION_VIEW); i.setDataAndType(videoUri, videoMimeType); title.getContext().startActivity(i); }
Intent intent = new Intent(); intent.setAction(Intent.ACTION_VIEW); intent.setDataAndType(Uri.parse("file://" + "/sdcard/test.jpg"), "image/*"); startActivity(intent);
public static Intent getInstallAppIntent(Context context, File appFile) { try { Intent intent = new Intent(Intent.ACTION_VIEW); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { //区别于 FLAG_GRANT_READ_URI_PERMISSION 跟 FLAG_GRANT_WRITE_URI_PERMISSION, URI权限会持久存在即使重启,直到明确的用 revokeUriPermission(Uri, int) 撤销。 这个flag只提供可能持久授权。但是接收的应用必须调用ContentResolver的takePersistableUriPermission(Uri, int)方法实现 intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION); Uri fileUri = FileProvider.getUriForFile(context, context.getApplicationContext().getPackageName() + ".fileProvider", appFile); intent.setDataAndType(fileUri, "application/vnd.android.package-archive"); } else { intent.setDataAndType(Uri.fromFile(appFile), "application/vnd.android.package-archive"); } return intent; } catch (Exception e) { ExceptionHandler exceptionHandler = ExceptionHandlerHelper.getInstance(); if (exceptionHandler != null) { exceptionHandler.onException(e); } } return null; }
String resolvedType = (String) args[intentIndex + 1]; Intent intent = (Intent) args[intentIndex]; intent.setDataAndType(intent.getData(), resolvedType); IBinder resultTo = resultToIndex >= 0 ? (IBinder) args[resultToIndex] : null; int userId = VUserHandle.myUserId(); intent.putExtra(Constants.EXTRA_USER_HANDLE, userId); intent.putExtra(ChooserActivity.EXTRA_DATA, options); intent.putExtra(ChooserActivity.EXTRA_WHO, resultWho); intent.putExtra(ChooserActivity.EXTRA_REQUEST_CODE, requestCode); return method.invoke(who, args);