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

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

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

Intent.putExtra介绍

暂无

代码示例

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

// initialize the progress dialog like in the first example

// this is how you fire the downloader
mProgressDialog.show();
Intent intent = new Intent(this, DownloadService.class);
intent.putExtra("url", "url of the file to download");
intent.putExtra("receiver", new DownloadReceiver(new Handler()));
startService(intent);

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

Intent i = new Intent(Intent.ACTION_SEND);
i.setType("message/rfc822");
i.putExtra(Intent.EXTRA_EMAIL  , new String[]{"recipient@example.com"});
i.putExtra(Intent.EXTRA_SUBJECT, "subject of email");
i.putExtra(Intent.EXTRA_TEXT   , "body of email");
try {
  startActivity(Intent.createChooser(i, "Send mail..."));
} catch (android.content.ActivityNotFoundException ex) {
  Toast.makeText(MyActivity.this, "There are no email clients installed.", Toast.LENGTH_SHORT).show();
}

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

Intent i = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
if (hasImageCaptureBug()) {
  i.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, Uri.fromFile(new File("/sdcard/tmp")));
} else {
  i.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
}
startActivityForResult(i, mRequestCode);

代码示例来源:origin: nickbutcher/plaid

public static void addToPocket(Context context,
                String url,
                String tweetStatusId) {
  Intent intent = new Intent(Intent.ACTION_SEND);
  intent.setPackage(PACKAGE);
  intent.setType(MIME_TYPE);
  intent.putExtra(Intent.EXTRA_TEXT, url);
  if (tweetStatusId != null && tweetStatusId.length() > 0) {
    intent.putExtra(EXTRA_TWEET_STATUS_ID, tweetStatusId);
  }
  intent.putExtra(EXTRA_SOURCE_PACKAGE, context.getPackageName());
  context.startActivity(intent);
}

代码示例来源:origin: Tencent/tinker

intentResult.putExtra(ShareIntentUtil.INTENT_PATCH_PACKAGE_PATCH_CHECK, ShareConstants.ERROR_PACKAGE_CHECK_LIB_META_CORRUPTED);
    ShareIntentUtil.setIntentReturnCode(intentResult, ShareConstants.ERROR_LOAD_PATCH_PACKAGE_CHECK_FAIL);
    return false;
File libraryDir = new File(libraryPath);
if (!libraryDir.exists() || !libraryDir.isDirectory()) {
  ShareIntentUtil.setIntentReturnCode(intentResult, ShareConstants.ERROR_LOAD_PATCH_VERSION_LIB_DIRECTORY_NOT_EXIST);
  return false;
  File libFile = new File(libraryPath + relative);
  if (!SharePatchFileUtil.isLegalFile(libFile)) {
    ShareIntentUtil.setIntentReturnCode(intentResult, ShareConstants.ERROR_LOAD_PATCH_VERSION_LIB_FILE_NOT_EXIST);
    intentResult.putExtra(ShareIntentUtil.INTENT_PATCH_MISSING_LIB_PATH, libFile.getAbsolutePath());
    return false;
intentResult.putExtra(ShareIntentUtil.INTENT_PATCH_LIBS_PATH, libs);
return true;

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

Intent intent = new Intent("com.android.camera.action.CROP");  
intent.setClassName("com.android.camera", "com.android.camera.CropImage");  
File file = new File(filePath);  
Uri uri = Uri.fromFile(file);  
intent.setData(uri);  
intent.putExtra("crop", "true");  
intent.putExtra("aspectX", 1);  
intent.putExtra("aspectY", 1);  
intent.putExtra("outputX", 96);  
intent.putExtra("outputY", 96);  
intent.putExtra("noFaceDetection", true);  
intent.putExtra("return-data", true);                                  
startActivityForResult(intent, REQUEST_CROP_ICON);

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

btn01.setOnClickListener(new OnClickListener() {
  @Override
  public void onClick(View v) {

    Intent imageIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    File imagesFolder = new File(Environment.getExternalStorageDirectory(), "MyImages");
    imagesFolder.mkdirs(); // <----
    File image = new File(imagesFolder, "image_001.jpg");
    Uri uriSavedImage = Uri.fromFile(image);
    imageIntent.putExtra(MediaStore.EXTRA_OUTPUT, uriSavedImage);
    startActivityForResult(imageIntent,0);
 }
});

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

public static void email(Context context, String emailTo, String emailCC,
  String subject, String emailText, List<String> filePaths)
{
  //need to "send multiple" to get more than one attachment
  final Intent emailIntent = new Intent(Intent.ACTION_SEND_MULTIPLE);
  emailIntent.setType("text/plain");
  emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, 
    new String[]{emailTo});
  emailIntent.putExtra(android.content.Intent.EXTRA_CC, 
    new String[]{emailCC});
  emailIntent.putExtra(Intent.EXTRA_SUBJECT, subject); 
  emailIntent.putExtra(Intent.EXTRA_TEXT, emailText);
  //has to be an ArrayList
  ArrayList<Uri> uris = new ArrayList<Uri>();
  //convert from paths to Android friendly Parcelable Uri's
  for (String file : filePaths)
  {
    File fileIn = new File(file);
    Uri u = Uri.fromFile(fileIn);
    uris.add(u);
  }
  emailIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
  context.startActivity(Intent.createChooser(emailIntent, "Send mail..."));
}

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

private void initShareIntent(String type) {
  boolean found = false;
  Intent share = new Intent(android.content.Intent.ACTION_SEND);
  share.setType("image/jpeg");

  // gets the list of intents that can be loaded.
  List<ResolveInfo> resInfo = getPackageManager().queryIntentActivities(share, 0);
  if (!resInfo.isEmpty()){
    for (ResolveInfo info : resInfo) {
      if (info.activityInfo.packageName.toLowerCase().contains(type) || 
          info.activityInfo.name.toLowerCase().contains(type) ) {
        share.putExtra(Intent.EXTRA_SUBJECT,  "subject");
        share.putExtra(Intent.EXTRA_TEXT,     "your text");
        share.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File(myPath)) ); // Optional, just if you wanna share an image.
        share.setPackage(info.activityInfo.packageName);
        found = true;
        break;
      }
    }
    if (!found)
      return;

    startActivity(Intent.createChooser(share, "Select"));
  }
}

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

Intent intent = new Intent(this,MyAppWidgetProvider.class);
intent.setAction(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
// Use an array and EXTRA_APPWIDGET_IDS instead of AppWidgetManager.EXTRA_APPWIDGET_ID,
// since it seems the onUpdate() is only fired on that:
int[] ids = {widgetId};
intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS,ids);
sendBroadcast(intent);

代码示例来源:origin: square/leakcanary

private void startShareIntentChooser(Uri heapDumpUri) {
 Intent intent = new Intent(Intent.ACTION_SEND);
 intent.setType("application/octet-stream");
 intent.putExtra(Intent.EXTRA_STREAM, heapDumpUri);
 startActivity(Intent.createChooser(intent, getString(R.string.leak_canary_share_with)));
}

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

Intent i = new Intent(Intent.ACTION_SENDTO, Uri.parse("content://com.android.contacts/data/" + c.getString(0)));
i.setType("text/plain");
i.setPackage("com.whatsapp");           // so that only Whatsapp reacts and not the chooser
i.putExtra(Intent.EXTRA_SUBJECT, "Subject");
i.putExtra(Intent.EXTRA_TEXT, "I'm the body.");
startActivity(i);

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

Intent intent = new Intent();
 intent.setType("image/*");
 intent.setAction(Intent.ACTION_GET_CONTENT);
 intent.putExtra(Intent.EXTRA_LOCAL_ONLY, true);
 startActivityForResult(Intent.createChooser(intent,
     "Complete action using"), PHOTO_PICKER_ID);

代码示例来源:origin: Tencent/tinker

intentResult.putExtra(ShareIntentUtil.INTENT_PATCH_PACKAGE_PATCH_CHECK, ShareConstants.ERROR_PACKAGE_CHECK_DEX_META_CORRUPTED);
    ShareIntentUtil.setIntentReturnCode(intentResult, ShareConstants.ERROR_LOAD_PATCH_PACKAGE_CHECK_FAIL);
    return false;
File dexDir = new File(dexDirectory);
if (!dexDir.exists() || !dexDir.isDirectory()) {
  ShareIntentUtil.setIntentReturnCode(intentResult, ShareConstants.ERROR_LOAD_PATCH_VERSION_DEX_DIRECTORY_NOT_EXIST);
  return false;
File optimizeDexDirectoryFile = new File(optimizeDexDirectory);
  File dexFile = new File(dexDirectory + name);
    intentResult.putExtra(ShareIntentUtil.INTENT_PATCH_MISSING_DEX_PATH, dexFile.getAbsolutePath());
    ShareIntentUtil.setIntentReturnCode(intentResult, ShareConstants.ERROR_LOAD_PATCH_VERSION_DEX_FILE_NOT_EXIST);
    return false;
      continue;
    intentResult.putExtra(ShareIntentUtil.INTENT_PATCH_MISSING_DEX_PATH, dexOptFile.getAbsolutePath());
    ShareIntentUtil.setIntentReturnCode(intentResult, ShareConstants.ERROR_LOAD_PATCH_VERSION_DEX_OPT_FILE_NOT_EXIST);
    return false;
intentResult.putExtra(ShareIntentUtil.INTENT_PATCH_DEXES_PATH, dexes);
return true;

代码示例来源:origin: jaydenxiao2016/AndroidFire

private void crop(String imagePath) {
  File file = new File(FileUtils.createRootPath(this) + "/" + System.currentTimeMillis() + ".jpg");
  cropImagePath = file.getAbsolutePath();
  Intent intent = new Intent("com.android.camera.action.CROP");
  intent.setDataAndType(Uri.fromFile(new File(imagePath)), "image/*");
  intent.putExtra("crop", "true");
  intent.putExtra("aspectX", config.aspectX);
  intent.putExtra("aspectY", config.aspectY);
  intent.putExtra("outputX", config.outputX);
  intent.putExtra("outputY", config.outputY);
  intent.putExtra("return-data", false);
  intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(file));
  startActivityForResult(intent, IMAGE_CROP_CODE);
}

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

File newdir = new File(dir);
newdir.mkdirs();
    File newfile = new File(file);
    try {
      newfile.createNewFile();
    cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);

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

Intent picMessageIntent = new Intent(android.content.Intent.ACTION_SEND);
picMessageIntent.setType("image/jpeg");

File downloadedPic =  new File(
  Environment.getExternalStoragePublicDirectory(
  Environment.DIRECTORY_DOWNLOADS),
  "q.jpeg");

picMessageIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(downloadedPic));

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

private void share(String nameApp, String imagePath) {
  List<Intent> targetedShareIntents = new ArrayList<Intent>();
  Intent share = new Intent(android.content.Intent.ACTION_SEND);
  share.setType("image/jpeg");
  List<ResolveInfo> resInfo = getPackageManager().queryIntentActivities(share, 0);
  if (!resInfo.isEmpty()){
    for (ResolveInfo info : resInfo) {
      Intent targetedShare = new Intent(android.content.Intent.ACTION_SEND);
      targetedShare.setType("image/jpeg"); // put here your mime type

      if (info.activityInfo.packageName.toLowerCase().contains(nameApp) || 
          info.activityInfo.name.toLowerCase().contains(nameApp)) {
        targetedShare.putExtra(Intent.EXTRA_TEXT,     "My body of post/email");
        targetedShare.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File(imagePath)) );
        targetedShare.setPackage(info.activityInfo.packageName);
        targetedShareIntents.add(targetedShare);
      }
    }

    Intent chooserIntent = Intent.createChooser(targetedShareIntents.remove(0), "Select app to share");
    chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, targetedShareIntents.toArray(new Parcelable[]{}));
    startActivity(chooserIntent);
  }
}

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

private void handleMediaCaptureRequest(Intent intent) {
  Uri uri = intent.getParcelableExtra(MediaStore.EXTRA_OUTPUT);
  if (uri == null || !SCHEME_FILE.equals(uri.getScheme())) {
    return;
  }
  String path = uri.getPath();
  String newPath = NativeEngine.getRedirectedPath(path);
  if (newPath == null) {
    return;
  }
  File realFile = new File(newPath);
  Uri newUri = Uri.fromFile(realFile);
  intent.putExtra(MediaStore.EXTRA_OUTPUT, newUri);
}

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

Intent i = new Intent();
i.putExtra("name_of_extra", myParcelableObject);

相关文章

Intent类方法