List of usage examples for android.net Uri fromFile
public static Uri fromFile(File file)
From source file:com.mifos.mifosxdroid.online.ClientDetailsFragment.java
public void captureClientImage() { Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(capturedClientImageFile)); startActivityForResult(intent, CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE); }
From source file:org.jnegre.android.osmonthego.service.ExportService.java
/** * Handle export in the provided background thread *///from w ww . j a v a2 s .co m private void handleOsmExport(boolean includeAddress, boolean includeFixme) { //TODO handle empty survey //TODO handle bounds around +/-180 if (!isExternalStorageWritable()) { notifyUserOfError(); return; } int id = 0; double minLat = 200; double minLng = 200; double maxLat = -200; double maxLng = -200; StringBuilder builder = new StringBuilder(); if (includeAddress) { Uri uri = AddressTableMetaData.CONTENT_URI; Cursor cursor = getContentResolver().query(uri, new String[] { //projection AddressTableMetaData.LATITUDE, AddressTableMetaData.LONGITUDE, AddressTableMetaData.NUMBER, AddressTableMetaData.STREET }, null, //selection string null, //selection args array of strings null); //sort order if (cursor == null) { notifyUserOfError(); return; } try { int iLat = cursor.getColumnIndex(AddressTableMetaData.LATITUDE); int iLong = cursor.getColumnIndex(AddressTableMetaData.LONGITUDE); int iNumber = cursor.getColumnIndex(AddressTableMetaData.NUMBER); int iStreet = cursor.getColumnIndex(AddressTableMetaData.STREET); for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) { //Gather values double lat = cursor.getDouble(iLat); double lng = cursor.getDouble(iLong); String number = cursor.getString(iNumber); String street = cursor.getString(iStreet); minLat = Math.min(minLat, lat); maxLat = Math.max(maxLat, lat); minLng = Math.min(minLng, lng); maxLng = Math.max(maxLng, lng); builder.append("<node id=\"-").append(++id).append("\" lat=\"").append(lat).append("\" lon=\"") .append(lng).append("\" version=\"1\" action=\"modify\">\n"); addOsmTag(builder, "addr:housenumber", number); addOsmTag(builder, "addr:street", street); builder.append("</node>\n"); } } finally { cursor.close(); } } if (includeFixme) { Uri uri = FixmeTableMetaData.CONTENT_URI; Cursor cursor = getContentResolver().query(uri, new String[] { //projection FixmeTableMetaData.LATITUDE, FixmeTableMetaData.LONGITUDE, FixmeTableMetaData.COMMENT }, null, //selection string null, //selection args array of strings null); //sort order if (cursor == null) { notifyUserOfError(); return; } try { int iLat = cursor.getColumnIndex(FixmeTableMetaData.LATITUDE); int iLong = cursor.getColumnIndex(FixmeTableMetaData.LONGITUDE); int iComment = cursor.getColumnIndex(FixmeTableMetaData.COMMENT); for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) { //Gather values double lat = cursor.getDouble(iLat); double lng = cursor.getDouble(iLong); String comment = cursor.getString(iComment); minLat = Math.min(minLat, lat); maxLat = Math.max(maxLat, lat); minLng = Math.min(minLng, lng); maxLng = Math.max(maxLng, lng); builder.append("<node id=\"-").append(++id).append("\" lat=\"").append(lat).append("\" lon=\"") .append(lng).append("\" version=\"1\" action=\"modify\">\n"); addOsmTag(builder, "fixme", comment); builder.append("</node>\n"); } } finally { cursor.close(); } } try { File destinationFile = getDestinationFile(); destinationFile.getParentFile().mkdirs(); PrintWriter writer = new PrintWriter(destinationFile, "UTF-8"); writer.println("<?xml version='1.0' encoding='UTF-8' standalone='yes' ?>"); writer.println("<osm version=\"0.6\" generator=\"OsmOnTheGo\">"); writer.print("<bounds minlat=\""); writer.print(minLat - MARGIN); writer.print("\" minlon=\""); writer.print(minLng - MARGIN); writer.print("\" maxlat=\""); writer.print(maxLat + MARGIN); writer.print("\" maxlon=\""); writer.print(maxLng + MARGIN); writer.println("\" />"); writer.println(builder); writer.print("</osm>"); writer.close(); if (writer.checkError()) { notifyUserOfError(); } else { //FIXME i18n the subject and content Intent emailIntent = new Intent(Intent.ACTION_SEND); emailIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); emailIntent.setType(HTTP.OCTET_STREAM_TYPE); //emailIntent.putExtra(Intent.EXTRA_EMAIL, new String[]{"johndoe@exemple.com"}); emailIntent.putExtra(Intent.EXTRA_SUBJECT, "OSM On The Go"); emailIntent.putExtra(Intent.EXTRA_TEXT, "Your last survey."); emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(destinationFile)); startActivity(emailIntent); } } catch (IOException e) { Log.e(TAG, "Could not write to file", e); notifyUserOfError(); } }
From source file:com.zia.freshdocs.widget.adapter.CMISAdapter.java
/** * Send the content using a built-in Android activity which can handle the * content type./*w ww.ja va 2s. c o m*/ * * @param position */ public void shareContent(int position) { final NodeRef ref = getItem(position); downloadContent(ref, new Handler() { public void handleMessage(Message msg) { Context context = getContext(); boolean done = msg.getData().getBoolean("done"); if (done) { dismissProgressDlg(); File file = (File) mDlThread.getResult(); if (file != null) { Resources res = context.getResources(); Uri uri = Uri.fromFile(file); Intent emailIntent = new Intent(Intent.ACTION_SEND); emailIntent.putExtra(Intent.EXTRA_STREAM, uri); emailIntent.putExtra(Intent.EXTRA_SUBJECT, ref.getName()); emailIntent.putExtra(Intent.EXTRA_TEXT, res.getString(R.string.email_text)); emailIntent.setType(ref.getContentType()); try { context.startActivity( Intent.createChooser(emailIntent, res.getString(R.string.email_title))); } catch (ActivityNotFoundException e) { String text = "No suitable applications registered to send " + ref.getContentType(); int duration = Toast.LENGTH_SHORT; Toast toast = Toast.makeText(context, text, duration); toast.show(); } } } else { int value = msg.getData().getInt("progress"); if (value > 0) { mProgressDlg.setProgress(value); } } } }); }
From source file:com.ruesga.rview.misc.ActivityHelper.java
@SuppressWarnings("ResultOfMethodCallIgnored") public static void downloadUri(Context context, Uri uri, String fileName, @Nullable String mimeType) { // Create the destination location File destination = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS); destination.mkdirs();/* w w w.j a v a 2 s. com*/ Uri destinationUri = Uri.fromFile(new File(destination, fileName)); // Use the download manager to perform the download DownloadManager downloadManager = (DownloadManager) context.getSystemService(Activity.DOWNLOAD_SERVICE); Request request = new Request(uri).setNotificationVisibility(Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED) .setDestinationUri(destinationUri); if (mimeType != null) { request.setMimeType(mimeType); } request.allowScanningByMediaScanner(); downloadManager.enqueue(request); }
From source file:me.piebridge.prevent.ui.UserGuideActivity.java
private void refreshQrCode(File qrCode) { Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE); mediaScanIntent.setData(Uri.fromFile(qrCode)); sendBroadcast(mediaScanIntent);//w ww . j av a 2 s.co m }
From source file:com.nit.vicky.servicelayer.NoteService.java
/** * Considering the field is new, if it has media handle it * //from www .ja v a 2s. co m * @param field */ private static void importMediaToDirectory(IField field, Context context) { String tmpMediaPath = null; switch (field.getType()) { case AUDIO: tmpMediaPath = field.getAudioPath(); break; case IMAGE: tmpMediaPath = field.getImagePath(); break; case TEXT: default: break; } if (tmpMediaPath != null) { try { File inFile = new File(tmpMediaPath); if (inFile.exists()) { Collection col = AnkiDroidApp.getCol(); String mediaDir = col.getMedia().getDir() + "/"; File mediaDirFile = new File(mediaDir); File parent = inFile.getParentFile(); // If already there. if (mediaDirFile.getAbsolutePath().contentEquals(parent.getAbsolutePath())) { return; } //File outFile = new File(mediaDir + inFile.getName().replaceAll(" ", "_")); //if (outFile.exists()) { File outFile = null; if (field.getType() == EFieldType.IMAGE) { outFile = File.createTempFile("imggallery", ".jpg", DiskUtil.getStoringDirectory()); } else if (field.getType() == EFieldType.AUDIO) { outFile = File.createTempFile("soundgallery", ".mp3", DiskUtil.getStoringDirectory()); } //} if (field.hasTemporaryMedia()) { // Move inFile.renameTo(outFile); } else { // Copy InputStream in = new FileInputStream(tmpMediaPath); OutputStream out = new FileOutputStream(outFile.getAbsolutePath()); byte[] buf = new byte[1024]; int len; while ((len = in.read(buf)) > 0) { out.write(buf, 0, len); } in.close(); out.close(); } switch (field.getType()) { case AUDIO: field.setAudioPath(outFile.getAbsolutePath()); break; case IMAGE: field.setImagePath(outFile.getAbsolutePath()); break; default: break; } Intent scanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE); scanIntent.setData(Uri.fromFile(inFile)); context.sendBroadcast(scanIntent); } } catch (IOException e) { throw new RuntimeException(e); } } }
From source file:com.remobile.file.LocalFilesystem.java
@Override public JSONObject getFileMetadataForLocalURL(LocalFilesystemURL inputURL) throws FileNotFoundException { File file = new File(filesystemPathForURL(inputURL)); if (!file.exists()) { throw new FileNotFoundException("File at " + inputURL.uri + " does not exist."); }//from w ww .j a va2 s . c o m JSONObject metadata = new JSONObject(); try { // Ensure that directories report a size of 0 metadata.put("size", file.isDirectory() ? 0 : file.length()); metadata.put("type", resourceApi.getMimeType(Uri.fromFile(file))); metadata.put("name", file.getName()); metadata.put("fullPath", inputURL.path); metadata.put("lastModifiedDate", file.lastModified()); } catch (JSONException e) { return null; } return metadata; }
From source file:com.sxt.superqq.activity.RegisterActivity.java
/** * ?Activity// w w w . ja v a 2 s. c o m */ @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (resultCode != RESULT_OK) { return; } String userName = getUserName(); switch (requestCode) { case OnSetAvatarClickListener.REQUEST_TAKE_PHOTO: if (!TextUtils.isEmpty(userName)) { Uri uri = Uri.fromFile(mOnSetAvatarListener.getAvatarFile(RegisterActivity.this, userName)); //??Activity mOnSetAvatarListener.startCropPhoto(uri, 200, 200, OnSetAvatarClickListener.REQUEST_CROP_PHOTO, true); } break; case OnSetAvatarClickListener.REQEUST_CHOOS_PHOTO: //??Activity mOnSetAvatarListener.startCropPhoto(data.getData(), 200, 200, OnSetAvatarClickListener.REQUEST_CROP_PHOTO, true); break; case OnSetAvatarClickListener.REQUEST_CROP_PHOTO://??Activity mOnSetAvatarListener.closePopuAvatar(); //ImageView?sd? mOnSetAvatarListener.saveCropPhoto(mivAvatar, data, userName); break; } }
From source file:com.oe.phonegap.plugins.AutoRecordVideo.java
/** * Creates a JSONObject that represents a File from the Uri * * @param data the Uri of the audio/image/video * @return a JSONObject that represents a File * @throws IOException//from ww w . j av a2 s .c o m */ private JSONObject createMediaFile(Uri data) { File fp = webView.getResourceApi().mapUriToFile(data); JSONObject obj = new JSONObject(); Class webViewClass = webView.getClass(); PluginManager pm = null; try { Method gpm = webViewClass.getMethod("getPluginManager"); pm = (PluginManager) gpm.invoke(webView); } catch (NoSuchMethodException e) { } catch (IllegalAccessException e) { } catch (InvocationTargetException e) { } if (pm == null) { try { Field pmf = webViewClass.getField("pluginManager"); pm = (PluginManager) pmf.get(webView); } catch (NoSuchFieldException e) { } catch (IllegalAccessException e) { } } FileUtils filePlugin = (FileUtils) pm.getPlugin("File"); LocalFilesystemURL url = filePlugin.filesystemURLforLocalPath(fp.getAbsolutePath()); try { // File properties obj.put("name", fp.getName()); obj.put("fullPath", fp.toURI().toString()); if (url != null) { obj.put("localURL", url.toString()); } // Because of an issue with MimeTypeMap.getMimeTypeFromExtension() all .3gpp files // are reported as video/3gpp. I'm doing this hacky check of the URI to see if it // is stored in the audio or video content store. if (fp.getAbsoluteFile().toString().endsWith(".3gp") || fp.getAbsoluteFile().toString().endsWith(".3gpp")) { if (data.toString().contains("/audio/")) { obj.put("type", AUDIO_3GPP); } else { obj.put("type", VIDEO_3GPP); } } else { obj.put("type", FileHelper.getMimeType(Uri.fromFile(fp), cordova)); } obj.put("lastModifiedDate", fp.lastModified()); obj.put("size", fp.length()); } catch (JSONException e) { // this will never happen e.printStackTrace(); } return obj; }
From source file:com.googlecode.android_scripting.facade.CameraFacade.java
@Rpc(description = "Starts the image capture application to take a picture and saves it to the specified path.") public void cameraInteractiveCapturePicture(@RpcParameter(name = "targetPath") final String targetPath) { Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); File file = new File(targetPath); intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(file)); AndroidFacade facade = mManager.getReceiver(AndroidFacade.class); facade.startActivityForResult(intent); }