List of usage examples for android.net Uri fromFile
public static Uri fromFile(File file)
From source file:com.zertinteractive.wallpaper.activities.DetailActivity.java
public void shareImage() { String path = Environment.getExternalStorageDirectory().toString(); File file = new File(path, "/" + TEMP_WALLPAPER_DIR + "/" + TEMP_WALLPAPER_NAME + ".png"); Uri imageUri = Uri.fromFile(file); if (file.exists()) { ;/*w w w. ja v a 2 s .co m*/ Log.e("FILE - ", file.getAbsolutePath()); } else { Log.e("ERROR - ", file.getAbsolutePath()); } Intent intent = new Intent(); intent.setAction(Intent.ACTION_SEND); intent.putExtra(Intent.EXTRA_TEXT, "Mood Wallpaper"); intent.putExtra(Intent.EXTRA_STREAM, imageUri); intent.setType("image/*"); startActivity(intent); }
From source file:com.mobantica.DriverItRide.activities.ActivityProfile.java
public Uri getOutputMediaFileUri(int type) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { return FileProvider.getUriForFile(ActivityProfile.this, BuildConfig.APPLICATION_ID + ".provider", getOutputMediaFile(type)); } else {/*from w w w . ja va 2s. co m*/ return Uri.fromFile(getOutputMediaFile(type)); } }
From source file:eu.intermodalics.tango_ros_streamer.activities.RunningActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.settings: if (mParameterNode != null) { try { mParameterNode.setPreferencesFromParameterServer(); } catch (RuntimeException e) { e.printStackTrace();//from w w w.j av a 2 s. c o m } } Intent settingsActivityIntent = new Intent(this, SettingsActivity.class); settingsActivityIntent.putExtra(getString(R.string.uuids_names_map), mUuidsNamesHashMap); startActivityForResult(settingsActivityIntent, StartSettingsActivityRequest.STANDARD_RUN); return true; case R.id.share: mLogger.saveLogToFile(); Intent shareFileIntent = new Intent(Intent.ACTION_SEND); shareFileIntent.setType("text/plain"); shareFileIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(mLogger.getLogFile())); startActivity(shareFileIntent); return true; default: return super.onOptionsItemSelected(item); } }
From source file:com.wikitude.virtualhome.AugmentedActivity.java
public void shareSnapShot() { Log.e(this.getClass().getName(), " VIRTUALHOME: calling captureSnapShot method"); architectView.captureScreen(ArchitectView.CaptureScreenCallback.CAPTURE_MODE_CAM_AND_WEBVIEW, new ArchitectView.CaptureScreenCallback() { @Override/* ww w. jav a 2 s .c o m*/ public void onScreenCaptured(final Bitmap screenCapture) { // store screenCapture into external cache directory final File screenCaptureFile = new File( Environment.getExternalStorageDirectory().toString(), "screenCapture_" + System.currentTimeMillis() + ".jpg"); // 1. Save bitmap to file & compress to jpeg. You may use PNG too try { final FileOutputStream out = new FileOutputStream(screenCaptureFile); screenCapture.compress(Bitmap.CompressFormat.JPEG, 90, out); out.flush(); out.close(); // 2. create send intent final Intent share = new Intent(Intent.ACTION_SEND); share.setType("image/jpg"); share.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(screenCaptureFile)); // 3. launch intent-chooser final String chooserTitle = "Share Snapshot"; startActivity(Intent.createChooser(share, chooserTitle)); } catch (final Exception e) { // should not occur when all permissions are set runOnUiThread(new Runnable() { @Override public void run() { Log.e(this.getClass().getName(), " VIRTUALHOME: Share Snapshot failed "); // show toast message in case something went wrong //Toast.makeText(this, " Unexpected error", Toast.LENGTH_SHORT).show(); } }); } } }); }
From source file:com.ccxt.whl.activity.SettingsFragmentCopy.java
/** * ?/*ww w.j a v a 2s . co m*/ */ public void selectPicFromCamera() { if (!CommonUtils.isExitsSdcard()) { Toast.makeText(getActivity(), "SD????", 0).show(); return; } // cameraFile = new File(PathUtil.getInstance().getImagePath(), DemoApplication.getInstance().getUserName() cameraFile = new File(PathUtil.getInstance().getImagePath(), DemoApplication.getInstance().getUser() + System.currentTimeMillis() + ".jpg"); cameraFile.getParentFile().mkdirs(); startActivityForResult(new Intent(MediaStore.ACTION_IMAGE_CAPTURE).putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(cameraFile)), USERPIC_REQUEST_CODE_CAMERA); }
From source file:com.dwdesign.tweetings.activity.ComposeActivity.java
@SuppressWarnings("deprecation") @Override/*from w w w . j a v a 2s.com*/ public boolean onMenuItemClick(final MenuItem item) { switch (item.getItemId()) { case MENU_TAKE_PHOTO: { if (item.getTitle().equals(getString(R.string.remove_photo))) { if (mImageUri == null) return false; removeAttachments(); } else { takePhoto(); } break; } case MENU_LAST_PHOTO: { String[] projection = new String[] { MediaStore.Images.ImageColumns._ID, MediaStore.Images.ImageColumns.DATA, MediaStore.Images.ImageColumns.BUCKET_DISPLAY_NAME, MediaStore.Images.ImageColumns.DATE_TAKEN, MediaStore.Images.ImageColumns.MIME_TYPE }; final Cursor cursor = managedQuery(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, projection, null, null, MediaStore.Images.ImageColumns.DATE_TAKEN + " DESC"); if (cursor.moveToFirst()) { String imageLocation = cursor.getString(1); File imageFile = new File(imageLocation); if (imageFile != null && imageFile.exists()) { // TODO: is there a better way to do this? mImageUri = Uri.fromFile(imageFile); mIsPhotoAttached = false; mIsImageAttached = true; mImageThumbnailPreview.setVisibility(View.VISIBLE); reloadAttachedImageThumbnail(imageFile); } else { mIsImageAttached = false; } setMenu(); boolean isAutoUpload = mPreferences.getBoolean(PREFERENCE_KEY_AUTO_UPLOAD, false); if (!isNullOrEmpty(mUploadProvider) && mIsImageAttached && isAutoUpload) { postMedia(); } } break; } case MENU_ADD_IMAGE: { if (item.getTitle().equals(getString(R.string.remove_image))) { if (mImageUri == null) return false; removeAttachments(); } else { pickImage(); } break; } case MENU_SHORTEN_LINKS: { String s = parseString(mEditText.getText()); new UrlShortenerTask().execute(s); break; } case MENU_ADD_TO_BUFFER: { if (mIsBuffer) { mIsBuffer = false; } else { mIsBuffer = true; } setMenu(); break; } case MENU_SCHEDULE_TWEET: { if (mScheduleDate != null) { mScheduleDate = null; setMenu(); } else { Intent intent = new Intent(INTENT_ACTION_SCHEDULE_TWEET); if (mScheduleDate != null) { Bundle bundle = new Bundle(); bundle.putString(INTENT_KEY_SCHEDULE_DATE_TIME, mScheduleDate); intent.putExtras(bundle); } startActivityForResult(intent, REQUEST_SCHEDULE_DATE); } break; } case MENU_UPLOAD: { if (!isNullOrEmpty(mUploadProvider) && mIsImageAttached) { postMedia(true); } break; } case MENU_ADD_LOCATION: { final boolean attach_location = mPreferences.getBoolean(PREFERENCE_KEY_ATTACH_LOCATION, false); if (!attach_location) { getLocation(); } mPreferences.edit().putBoolean(PREFERENCE_KEY_ATTACH_LOCATION, !attach_location).commit(); setMenu(); break; } case MENU_DRAFTS: { startActivity(new Intent(INTENT_ACTION_DRAFTS)); break; } case MENU_DELETE: { if (mImageUri == null) return false; removeAttachments(); break; } case MENU_EDIT: { if (mImageUri == null) return false; final Intent intent = new Intent(INTENT_ACTION_EXTENSION_EDIT_IMAGE); intent.setData(mImageUri); startActivityForResult(Intent.createChooser(intent, getString(R.string.open_with_extensions)), REQUEST_EDIT_IMAGE); // Create the intent needed to start feather /*Intent newIntent = new Intent( this, FeatherActivity.class ); // set the source image uri newIntent.setData( mImageUri ); // pass the required api key ( http://developers.aviary.com/ ) newIntent.putExtra( "API_KEY", AVIARY_SDK_API_KEY ); // pass the uri of the destination image file (optional) // This will be the same uri you will receive in the onActivityResult //newIntent.putExtra( "output", mImageUri); // format of the destination image (optional) newIntent.putExtra( "output-format", Bitmap.CompressFormat.JPEG.name() ); // output format quality (optional) newIntent.putExtra( "output-quality", 85 ); // you can force feather to display only a certain tools // newIntent.putExtra( "tools-list", new String[]{"ADJUST", "BRIGHTNESS" } ); // enable fast rendering preview newIntent.putExtra( "effect-enable-fast-preview", true ); // limit the image size // You can pass the current display size as max image size because after // the execution of Aviary you can save the HI-RES image so you don't need a big // image for the preview // newIntent.putExtra( "max-image-size", 800 ); // you want to hide the exit alert dialog shown when back is pressed // without saving image first // newIntent.putExtra( "hide-exit-unsave-confirmation", true ); // ..and start feather startActivityForResult( newIntent, ACTION_REQUEST_FEATHER );*/ break; } case MENU_VIEW: { openImage(this, mImageUri, false); break; } case MENU_TOGGLE_SENSITIVE: { final boolean has_media = (mIsImageAttached || mIsPhotoAttached) && mImageUri != null; if (!has_media) return false; mIsPossiblySensitive = !mIsPossiblySensitive; setMenu(); break; } } return true; }
From source file:com.abc.driver.TruckActivity.java
/** * start to take picture//w w w . j a v a 2 s .c o m */ private void startToCameraActivity(int actionId) { Intent localIntent = new Intent("android.media.action.IMAGE_CAPTURE"); String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date()); File mediaFile = new File(app.regUserPath + File.separator + "IMG_" + timeStamp + ".png"); localIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(mediaFile)); imageUri = Uri.fromFile(mediaFile); // isCameraCapture = true; startActivityForResult(localIntent, actionId); }
From source file:com.grass.caishi.cc.activity.AdAddActivity.java
/** * onActivityResult//from ww w . j av a 2 s .c om */ protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (resultCode == RESULT_OK) { // ? if (requestCode == REQUEST_CODE_CAMERA) { // ?? if (cameraFile != null && cameraFile.exists()) if (select_type == 1) cropImageUri(Uri.fromFile(cameraFile), 450, 150, USERPIC_REQUEST_CODE_CUT); else addToListImage(cameraFile.getAbsolutePath()); // img_list.add(cameraFile.getAbsolutePath()); } else if (requestCode == REQUEST_CODE_IMAGES) { // ?? if (data != null) { Uri selectedImage = data.getData(); if (selectedImage != null) { if (select_type == 1) cropImageUri(selectedImage, 450, 150, USERPIC_REQUEST_CODE_CUT); else addToListImage(getPicByUri(selectedImage)); // img_list.add(getPicByUri(selectedImage)); } } } else if (requestCode == USERPIC_REQUEST_CODE_CUT) {// ? // ? if (data != null) { Bitmap bitmap = data.getParcelableExtra("data"); img_logo.setImageBitmap(bitmap); System.err.println(cameraFile.getAbsolutePath()); cameraFile = saveJPGE_After(bitmap, cameraFile); // // ???? addToListImage(cameraFile.getAbsolutePath()); } else { } } } }
From source file:com.ccxt.whl.activity.SettingsFragmentCopy.java
/** * onActivityResult//from ww w .ja v a 2 s. c o m */ public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (requestCode == USERPIC_REQUEST_CODE_CAMERA) { // ?? if (cameraFile != null && cameraFile.exists()) { //sendPicture(cameraFile.getAbsolutePath()); Log.d("log", "cameraFile" + cameraFile.getAbsolutePath()); //?uri imageUri = Uri.fromFile(cameraFile); imageUri = Uri.fromFile(cameraFile); cropImageUri(imageUri, 200, 200, USERPIC_REQUEST_CODE_CUT); } } else if (requestCode == USERPIC_REQUEST_CODE_LOCAL) { // ?? if (data != null) { Uri selectedImage = data.getData(); if (selectedImage != null) { //?uri imageUri = selectedImage; sendPicByUri(selectedImage); //Log.d("log","selectedImage"+cameraFile.getAbsolutePath()); } } } else if (requestCode == USERPIC_REQUEST_CODE_CUT) {//? // ? if (data != null) { Log.d("log", "imageUribundle==>" + imageUri); iv_user_photo.setImageURI(imageUri); RequestParams params = new RequestParams(); final String contentType = RequestParams.APPLICATION_OCTET_STREAM; File file = Uritofile(imageUri); //File file = new File(imageUri.getPath()); if (file.exists()) { try { params.put("headurl", file, "image/jpeg"); params.put("user", DemoApplication.getInstance().getUser()); params.put("param", "headurl"); HttpRestClient.post(Constant.UPDATE_USER_URL, params, responseHandler); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } } else { Toast toast = Toast.makeText(getActivity(), "?SD??", Toast.LENGTH_SHORT); } //params.put(key, file, ) //**??data //Bitmap bitmap = data.getParcelableExtra("data"); // Bitmap bitmap = data.getExtras().getParcelable("data"); /* // ByteArrayOutputStream out = new ByteArrayOutputStream(); // bitmap.compress(Bitmap.CompressFormat.JPEG, 100, out); */ //this.iv_image.setImageBitmap(bitmap); } else { Toast toast = Toast.makeText(getActivity(), "?SD??", Toast.LENGTH_SHORT); } /* try { // // tempFile.delete(); } catch (Exception e) { e.printStackTrace(); } */ RequestParams params = new RequestParams(); final String contentType = RequestParams.APPLICATION_OCTET_STREAM; // params.put(key, file, contentType) //HttpRestClient.post(url, params, responseHandler) } }
From source file:com.remobile.camera.CameraLauncher.java
/** * Called when the camera view exits./*from w w w . j ava 2s. co m*/ * * @param requestCode The request code originally supplied to startActivityForResult(), * allowing you to identify who this result came from. * @param resultCode The integer result code returned by the child activity through its setResult(). * @param intent An Intent, which can return result data to the caller (various data can be attached to Intent "extras"). */ public void onActivityResult(int requestCode, int resultCode, Intent intent) { if (requestCode >= cordova.IMAGE_PICKER_RESULT) { return; } // Get src and dest types from request code for a Camera Activity int srcType = (requestCode / 16) - 1; int destType = (requestCode % 16) - 1; // If Camera Crop if (requestCode >= CROP_CAMERA) { if (resultCode == Activity.RESULT_OK) { // Because of the inability to pass through multiple intents, this hack will allow us // to pass arcane codes back. destType = requestCode - CROP_CAMERA; try { processResultFromCamera(destType, intent); } catch (IOException e) { e.printStackTrace(); FLog.e(LOG_TAG, "Unable to write to file"); } } // If cancelled else if (resultCode == Activity.RESULT_CANCELED) { this.failPicture("Camera cancelled."); } // If something else else { this.failPicture("Did not complete!"); } } // If CAMERA else if (srcType == CAMERA) { // If image available if (resultCode == Activity.RESULT_OK) { try { if (this.allowEdit) { Uri tmpFile = Uri.fromFile(new File(getTempDirectoryPath(), ".Pic.jpg")); performCrop(tmpFile, destType, intent); } else { this.processResultFromCamera(destType, intent); } } catch (IOException e) { e.printStackTrace(); this.failPicture("Error capturing image."); } } // If cancelled else if (resultCode == Activity.RESULT_CANCELED) { this.failPicture("Camera cancelled."); } // If something else else { this.failPicture("Did not complete!"); } } // If retrieving photo from library else if ((srcType == PHOTOLIBRARY) || (srcType == SAVEDPHOTOALBUM)) { if (resultCode == Activity.RESULT_OK && intent != null) { this.processResultFromGallery(destType, intent); } else if (resultCode == Activity.RESULT_CANCELED) { this.failPicture("Selection cancelled."); } else { this.failPicture("Selection did not complete!"); } } }