android.content.Intent.setDataAndType()方法的使用及代码示例

x33g5p2x  于2022-01-20 转载在 其他  
字(8.1k)|赞(0)|评价(0)|浏览(250)

本文整理了Java中android.content.Intent.setDataAndType()方法的一些代码示例,展示了Intent.setDataAndType()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Intent.setDataAndType()方法的具体详情如下:
包路径:android.content.Intent
类名称:Intent
方法名:setDataAndType

Intent.setDataAndType介绍

暂无

代码示例

代码示例来源:origin: stackoverflow.com

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);
}

代码示例来源:origin: stackoverflow.com

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);

代码示例来源:origin: stackoverflow.com

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);

代码示例来源:origin: commonsguy/cw-omnibus

@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);
}

代码示例来源:origin: stackoverflow.com

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);

代码示例来源:origin: stackoverflow.com

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)));

代码示例来源:origin: stackoverflow.com

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();
  }
}

代码示例来源:origin: commonsguy/cw-omnibus

@Override
public void onClick(View v) {
 Intent i=new Intent(Intent.ACTION_VIEW);
 i.setDataAndType(videoUri, videoMimeType);
 title.getContext().startActivity(i);
}

代码示例来源:origin: GitLqr/LQRWeChat

/**
 * 调用自带的视频播放器
 *
 * @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);
}

代码示例来源:origin: stackoverflow.com

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);

代码示例来源:origin: stackoverflow.com

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();
}

代码示例来源:origin: JessYanCoding/MVPArms

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;
}

代码示例来源:origin: stackoverflow.com

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);

代码示例来源:origin: commonsguy/cw-omnibus

@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);
}

代码示例来源:origin: stackoverflow.com

protected void openFile(String fileName) {
  Intent install = new Intent(Intent.ACTION_VIEW);
  install.setDataAndType(Uri.fromFile(new File(fileName)),"MIME-TYPE");
  startActivity(install);
}

代码示例来源:origin: TommyLemon/APIJSON

/**照片裁剪
 * @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);
}

代码示例来源:origin: commonsguy/cw-omnibus

@Override
public void onClick(View v) {
 Intent i=new Intent(Intent.ACTION_VIEW);
 i.setDataAndType(videoUri, videoMimeType);
 title.getContext().startActivity(i);
}

代码示例来源:origin: stackoverflow.com

Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse("file://" + "/sdcard/test.jpg"), "image/*");
startActivity(intent);

代码示例来源:origin: WVector/AppUpdate

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;
}

代码示例来源:origin: android-hacker/VirtualXposed

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);

相关文章

Intent类方法