List of usage examples for android.net Uri fromFile
public static Uri fromFile(File file)
From source file:com.royclarkson.springagram.PhotoAddFragment.java
private void dispatchTakePictureIntent() { Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); // Ensure that there's a camera activity to handle the intent if (takePictureIntent.resolveActivity(getActivity().getPackageManager()) != null) { // Create the File where the photo should go File photoFile = null;//from ww w . j a va 2s. c o m try { photoFile = createImageFile(); } catch (IOException ex) { // Error occurred while creating the File } // Continue only if the File was successfully created if (photoFile != null) { takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photoFile)); startActivityForResult(takePictureIntent, REQUEST_TAKE_PHOTO); } } }
From source file:com.phonegap.customcamera.NativeCameraLauncher.java
public void takePicture() { // Save the number of images currently on disk for later Intent intent = new Intent(this.cordova.getActivity().getApplicationContext(), CameraActivity.class); this.photo = createCaptureFile(); this.imageUri = Uri.fromFile(photo); intent.putExtra(MediaStore.EXTRA_OUTPUT, this.imageUri); intent.putExtra(CAPTURE_BUTTON_COLOR_ID, this.captureButtonColor); intent.putExtra(CAPTURE_BUTTON_BORDER_COLOR_ID, this.captureButtonBorderColor); intent.putExtra(BRIGHTNESS_THRESHOLD_ID, this.brightnessThreshold); this.cordova.startActivityForResult((CordovaPlugin) this, intent, 1); }
From source file:com.krayzk9s.imgurholo.services.DownloadService.java
@Override protected void onHandleIntent(Intent intent) { final NotificationManager notificationManager = (NotificationManager) this .getSystemService(Context.NOTIFICATION_SERVICE); ids = intent.getParcelableArrayListExtra("ids"); albumName = "/"; downloaded = 0;//from ww w.ja va2 s . co m if (ids.size() > 0) { albumName += intent.getStringExtra("albumName") + "/"; File myDirectory = new File( android.os.Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), albumName); if (!myDirectory.exists()) { myDirectory.mkdirs(); } } for (int i = 0; i < ids.size(); i++) { try { final String type = ids.get(i).getJSONObject().getString(ImgurHoloActivity.IMAGE_DATA_TYPE) .split("/")[1]; final String id = ids.get(i).getJSONObject().getString("id"); final String link = ids.get(i).getJSONObject().getString(ImgurHoloActivity.IMAGE_DATA_LINK); Log.d("data", ids.get(i).getJSONObject().toString()); Log.d(ImgurHoloActivity.IMAGE_DATA_TYPE, ids.get(0).getJSONObject().getString(ImgurHoloActivity.IMAGE_DATA_TYPE).split("/")[1]); Log.d("id", ids.get(i).getJSONObject().getString("id")); Log.d(ImgurHoloActivity.IMAGE_DATA_LINK, ids.get(0).getJSONObject().getString(ImgurHoloActivity.IMAGE_DATA_LINK)); final NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this); notificationBuilder.setContentTitle(getString(R.string.picture_download)) .setContentText(getString(R.string.download_in_progress)) .setSmallIcon(R.drawable.icon_desaturated); Ion.with(getApplicationContext(), link).progress(new ProgressCallback() { @Override public void onProgress(int i, int i2) { notificationBuilder.setProgress(i2, i, false); } }).write(new File( android.os.Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES) + albumName + id + "." + type)) .setCallback(new FutureCallback<File>() { @Override public void onCompleted(Exception e, File file) { if (file == null) return; downloaded += 1; if (downloaded == ids.size()) { NotificationCompat.Builder notificationComplete = new NotificationCompat.Builder( getApplicationContext()); if (ids.size() == 1) { Intent viewImageIntent = new Intent(Intent.ACTION_VIEW); viewImageIntent.setDataAndType(Uri.fromFile(file), "image/*"); Intent shareIntent = new Intent(Intent.ACTION_SEND); shareIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET); shareIntent.setType("image/*"); shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file)); PendingIntent viewImagePendingIntent = PendingIntent.getActivity( getApplicationContext(), (int) System.currentTimeMillis(), viewImageIntent, 0); PendingIntent sharePendingIntent = PendingIntent.getActivity( getApplicationContext(), (int) System.currentTimeMillis(), shareIntent, 0); notificationComplete.setContentTitle(getString(R.string.download_complete)) .setSmallIcon(R.drawable.icon_desaturated) .setContentText(String.format(getString(R.string.download_progress), downloaded)) .setContentIntent(viewImagePendingIntent) .addAction(R.drawable.dark_social_share, getString(R.string.share), sharePendingIntent); } else { Intent i = new Intent(Intent.ACTION_PICK); i.setDataAndType( Uri.fromFile(new File( android.os.Environment.getExternalStoragePublicDirectory( Environment.DIRECTORY_PICTURES) + albumName)), "image/*"); PendingIntent viewImagePendingIntent = PendingIntent.getActivity( getApplicationContext(), (int) System.currentTimeMillis(), i, 0); notificationComplete.setContentTitle(getString(R.string.download_complete)) .setSmallIcon(R.drawable.icon_desaturated).setContentText(String .format(getString(R.string.download_progress), downloaded)) .setContentIntent(viewImagePendingIntent); } notificationManager.cancel(0); notificationManager.cancel(1); notificationManager.notify(1, notificationComplete.build()); } MediaScannerConnection.scanFile(getApplicationContext(), new String[] { android.os.Environment.getExternalStoragePublicDirectory( Environment.DIRECTORY_PICTURES) + albumName + id + "." + type }, null, new MediaScannerConnection.OnScanCompletedListener() { @Override public void onScanCompleted(final String path, final Uri uri) { Log.i("Scanning", String.format("Scanned path %s -> URI = %s", path, uri.toString())); } }); } }); notificationManager.notify(0, notificationBuilder.build()); } catch (JSONException e) { Log.e("Error!", e.toString()); } } }
From source file:net.mutina.uclimb.ForegroundCameraLauncher.java
/** * Take a picture with the camera.//w w w. ja va 2 s . c o m * When an image is captured or the camera view is cancelled, the result is returned * in CordovaActivity.onActivityResult, which forwards the result to this.onActivityResult. * * The image can either be returned as a base64 string or a URI that points to the file. * To display base64 string in an img tag, set the source to: * img.src="data:image/jpeg;base64,"+result; * or to display URI in an img tag * img.src=result; * */ public void takePicture() { // Save the number of images currently on disk for later this.numPics = queryImgDB().getCount(); Intent intent = new Intent(this.ctx.getContext(), CameraActivity.class); this.photo = createCaptureFile(); this.imageUri = Uri.fromFile(photo); intent.putExtra(MediaStore.EXTRA_OUTPUT, this.imageUri); this.ctx.startActivityForResult((Plugin) this, intent, 1); }
From source file:edu.mit.mobile.android.imagecache.test.ImageCacheJunitTest.java
/** * Loads a file from the assets and saves it to a public location. * * @return// w ww . ja v a 2 s . c o m * @throws IOException */ private Uri loadLocalFile() throws IOException { final String testfile = "logo_locast.png"; final Context contextInst = getInstrumentation().getContext(); final Context context = getInstrumentation().getTargetContext(); final InputStream is = contextInst.getAssets().open(testfile); assertNotNull(is); final FileOutputStream fos = context.openFileOutput(testfile, Context.MODE_PRIVATE); assertNotNull(fos); int read = 0; final byte[] bytes = new byte[1024]; while ((read = is.read(bytes)) != -1) { fos.write(bytes, 0, read); } is.close(); fos.close(); final File outFile = context.getFileStreamPath(testfile); final Uri fileUri = Uri.fromFile(outFile); assertNotNull(fileUri); return fileUri; }
From source file:com.photocitygame.android.ImageActivity.java
protected void doCapture() { File f = Environment.getExternalStorageDirectory(); File dir = new File(f, "photocity"); if (!dir.exists()) { dir.mkdir();/* w w w .j a v a 2 s. c o m*/ } Uri captureUri = Uri.fromFile(new File(dir, "image.jpg")); Intent i = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); i.putExtra(MediaStore.EXTRA_OUTPUT, captureUri); startActivityForResult(i, TAKE_IMAGE); }
From source file:com.phonegap.CameraLauncher.java
/** * Take a picture with the camera.//from ww w. j av a2 s .co m * When an image is captured or the camera view is cancelled, the result is returned * in PhonegapActivity.onActivityResult, which forwards the result to this.onActivityResult. * * The image can either be returned as a base64 string or a URI that points to the file. * To display base64 string in an img tag, set the source to: * img.src="data:image/jpeg;base64,"+result; * or to display URI in an img tag * img.src=result; * * @param quality Compression quality hint (0-100: 0=low quality & high compression, 100=compress of max quality) * @param returnType Set the type of image to return. */ public void takePicture(int quality, int returnType) { this.mQuality = quality; // Display camera Intent intent = new Intent("android.media.action.IMAGE_CAPTURE"); // Specify file so that large image is captured and returned // TODO: What if there isn't any external storage? File photo = new File(Environment.getExternalStorageDirectory(), "Pic.jpg"); intent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, Uri.fromFile(photo)); this.imageUri = Uri.fromFile(photo); this.ctx.startActivityForResult((Plugin) this, intent, (CAMERA + 1) * 16 + returnType + 1); }
From source file:com.doplgangr.secrecy.FileSystem.storage.java
public static Uri saveThumbnail(Context context, Uri uri, String filename) { InputStream stream = null;//from www. java 2 s .com try { stream = context.getContentResolver().openInputStream(uri); java.io.File thumbpath = new java.io.File(getAbsTempFolder() + "/" + "_thumb" + filename); if (thumbpath.exists()) storage.purgeFile(thumbpath); thumbpath.createNewFile(); FileOutputStream out = new FileOutputStream(thumbpath); Bitmap bitmap = decodeSampledBitmapFromPath(getPath(context, uri), 150, 150); if (bitmap == null) { //If photo fails, try Video Util.log(getPath(context, uri)); bitmap = ThumbnailUtils.createVideoThumbnail(getPath(context, uri), MediaStore.Video.Thumbnails.MICRO_KIND); } if (bitmap == null) { out.close(); storage.purgeFile(thumbpath); return null; } bitmap.compress(Bitmap.CompressFormat.JPEG, 90, out); out.close(); return Uri.fromFile(thumbpath); } catch (Exception e) { e.printStackTrace(); } finally { if (stream != null) try { stream.close(); } catch (Exception e) { e.printStackTrace(); } } return null; }
From source file:com.partner.common.updater.ApkDownloadUtil.java
public static void installBundledApps(File file) { Intent intent = new Intent(Intent.ACTION_VIEW); intent.setDataAndType(Uri.fromFile(file), "application/vnd.android.package-archive"); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); PartnerApplication.getInstance().startActivity(intent); }
From source file:co.mwater.foregroundcameraplugin.ForegroundCameraLauncher.java
/** * Take a picture with the camera. When an image is captured or the camera * view is cancelled, the result is returned in * CordovaActivity.onActivityResult, which forwards the result to * this.onActivityResult./*w w w. j a v a 2 s. com*/ * * The image can either be returned as a base64 string or a URI that points * to the file. To display base64 string in an img tag, set the source to: * img.src="data:image/jpeg;base64,"+result; or to display URI in an img tag * img.src=result; * */ public void takePicture() { // Save the number of images currently on disk for later this.numPics = queryImgDB().getCount(); Intent intent = new Intent(this.cordova.getActivity().getApplicationContext(), CameraActivity.class); this.photo = createCaptureFile(); this.imageUri = Uri.fromFile(photo); intent.putExtra(MediaStore.EXTRA_OUTPUT, this.imageUri); this.cordova.startActivityForResult((CordovaPlugin) this, intent, 1); }