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