List of usage examples for android.net Uri getPath
@Nullable public abstract String getPath();
From source file:com.breadwallet.tools.security.RequestHandler.java
public static void processBitIdResponse(final Activity app) { final byte[] phrase; final byte[] nulTermPhrase; final byte[] seed; if (app == null) { Log.e(TAG, "processBitIdResponse: app is null"); return;/*w w w . j av a2 s . c o m*/ } if (_bitUri == null) { Log.e(TAG, "processBitIdResponse: _bitUri is null"); return; } final Uri uri = Uri.parse(_bitUri); try { phrase = KeyStoreManager.getKeyStorePhrase(app, REQUEST_PHRASE_BITID); } catch (BRKeystoreErrorException e) { Log.e(TAG, "processBitIdResponse: failed to getKeyStorePhrase: " + e.getCause().getMessage()); return; } nulTermPhrase = TypesConverter.getNullTerminatedPhrase(phrase); seed = BRWalletManager.getSeedFromPhrase(nulTermPhrase); if (seed == null) { Log.e(TAG, "processBitIdResponse: seed is null!"); return; } //run the callback new Thread(new Runnable() { @Override public void run() { try { if (_strToSign == null) { //meaning it's a link handling String nonce = null; String scheme = "https"; String query = uri.getQuery(); if (query == null) { Log.e(TAG, "run: Malformed URI"); return; } String u = uri.getQueryParameter("u"); if (u != null && u.equalsIgnoreCase("1")) { scheme = "http"; } String x = uri.getQueryParameter("x"); if (Utils.isNullOrEmpty(x)) { nonce = newNonce(app, uri.getHost() + uri.getPath()); // we are generating our own nonce } else { nonce = x; // service is providing a nonce } String callbackUrl = String.format("%s://%s%s", scheme, uri.getHost(), uri.getPath()); // build a payload consisting of the signature, address and signed uri String uriWithNonce = String.format("bitid://%s%s?x=%s", uri.getHost(), uri.getPath(), nonce); final byte[] key = BRBIP32Sequence.getInstance().bip32BitIDKey(seed, _index, callbackUrl); if (key == null) { Log.d(TAG, "processBitIdResponse: key is null!"); return; } // Log.e(TAG, "run: uriWithNonce: " + uriWithNonce); final String sig = BRBitId.signMessage(_strToSign == null ? uriWithNonce : _strToSign, new BRKey(key)); final String address = new BRKey(key).address(); JSONObject postJson = new JSONObject(); try { postJson.put("address", address); postJson.put("signature", sig); if (_strToSign == null) postJson.put("uri", uriWithNonce); } catch (JSONException e) { e.printStackTrace(); } RequestBody requestBody = RequestBody.create(null, postJson.toString()); Request request = new Request.Builder().url(callbackUrl + "?x=" + nonce).post(requestBody) .header("Content-Type", "application/json").build(); Response res = APIClient.getInstance(app).sendRequest(request, true, 0); Log.e(TAG, "processBitIdResponse: res.code: " + res.code()); Log.e(TAG, "processBitIdResponse: res.code: " + res.message()); try { Log.e(TAG, "processBitIdResponse: body: " + res.body().string()); } catch (IOException e) { e.printStackTrace(); } } else { //meaning its the wallet plugin, glidera auth String biUri = uri.getHost() == null ? uri.toString() : uri.getHost(); final byte[] key = BRBIP32Sequence.getInstance().bip32BitIDKey(seed, _index, biUri); if (key == null) { Log.d(TAG, "processBitIdResponse: key is null!"); return; } // Log.e(TAG, "run: uriWithNonce: " + uriWithNonce); final String sig = BRBitId.signMessage(_strToSign, new BRKey(key)); final String address = new BRKey(key).address(); JSONObject postJson = new JSONObject(); try { postJson.put("address", address); postJson.put("signature", sig); } catch (JSONException e) { e.printStackTrace(); } WalletPlugin.handleBitId(postJson); } } finally { //release everything _bitUri = null; _strToSign = null; _bitCallback = null; _authString = null; _index = 0; if (phrase != null) Arrays.fill(phrase, (byte) 0); if (nulTermPhrase != null) Arrays.fill(nulTermPhrase, (byte) 0); if (seed != null) Arrays.fill(seed, (byte) 0); } } }).start(); }
From source file:Main.java
public static String getPhotoPathFromContentUri(Context context, Uri uri) { String photoPath = ""; if (context == null || uri == null) { return photoPath; }/*from ww w. java 2 s. c om*/ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT && DocumentsContract.isDocumentUri(context, uri)) { String docId = DocumentsContract.getDocumentId(uri); if (isExternalStorageDocument(uri)) { String[] split = docId.split(":"); if (split.length >= 2) { String type = split[0]; if ("primary".equalsIgnoreCase(type)) { photoPath = Environment.getExternalStorageDirectory() + "/" + split[1]; } } } else if (isDownloadsDocument(uri)) { Uri contentUri = ContentUris.withAppendedId(Uri.parse("content://downloads/public_downloads"), Long.valueOf(docId)); photoPath = getDataColumn(context, contentUri, null, null); } else if (isMediaDocument(uri)) { String[] split = docId.split(":"); if (split.length >= 2) { String type = split[0]; Uri contentUris = null; if ("image".equals(type)) { contentUris = MediaStore.Images.Media.EXTERNAL_CONTENT_URI; } else if ("video".equals(type)) { contentUris = MediaStore.Video.Media.EXTERNAL_CONTENT_URI; } else if ("audio".equals(type)) { contentUris = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI; } String selection = MediaStore.Images.Media._ID + "=?"; String[] selectionArgs = new String[] { split[1] }; photoPath = getDataColumn(context, contentUris, selection, selectionArgs); } } } else if ("file".equalsIgnoreCase(uri.getScheme())) { photoPath = uri.getPath(); } else { photoPath = getDataColumn(context, uri, null, null); } return photoPath; }
From source file:com.ibuildapp.romanblack.WebPlugin.WebPlugin.java
public void processResult(Intent data, int resultCode) { if (null == mUploadMessage) nullValueHandler();//from w w w .j ava2 s . c o m Uri result = data == null || resultCode != RESULT_OK ? null : data.getData(); String filePath = result.getPath(); Uri fileUri = Uri.fromFile(new File(filePath)); if (isMedia) { ContentResolver cR = WebPlugin.this.getContentResolver(); MimeTypeMap mime = MimeTypeMap.getSingleton(); String type = mime.getExtensionFromMimeType(cR.getType(result)); fileUri = Uri.parse(fileUri.toString() + "." + type); data.setData(fileUri); isMedia = false; } mUploadMessage.onReceiveValue(fileUri); mUploadMessage = null; }
From source file:com.fvd.nimbus.MainActivity.java
String getImagePath() { String[] projection = { MediaStore.Images.Thumbnails._ID, // The columns we want MediaStore.Images.Thumbnails.IMAGE_ID, MediaStore.Images.Thumbnails.KIND, MediaStore.Images.Thumbnails.DATA }; String selection = MediaStore.Images.Thumbnails.KIND + "=" + // Select only mini's MediaStore.Images.Thumbnails.MINI_KIND; String sort = MediaStore.Images.Thumbnails._ID + " DESC"; //At the moment, this is a bit of a hack, as I'm returning ALL images, and just taking the latest one. There is a better way to narrow this down I think with a WHERE clause which is currently the selection variable Cursor myCursor = this.managedQuery(MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI, projection, selection, null, sort);/*from ww w . j ava2 s.c o m*/ long imageId = 0l; long thumbnailImageId = 0l; String thumbnailPath = ""; try { myCursor.moveToFirst(); imageId = myCursor.getLong(myCursor.getColumnIndexOrThrow(MediaStore.Images.Thumbnails.IMAGE_ID)); thumbnailImageId = myCursor.getLong(myCursor.getColumnIndexOrThrow(MediaStore.Images.Thumbnails._ID)); thumbnailPath = myCursor.getString(myCursor.getColumnIndexOrThrow(MediaStore.Images.Thumbnails.DATA)); } finally { myCursor.close(); } //Create new Cursor to obtain the file Path for the large image String[] largeFileProjection = { MediaStore.Images.ImageColumns._ID, MediaStore.Images.ImageColumns.DATA }; String largeFileSort = MediaStore.Images.ImageColumns._ID + " DESC"; myCursor = this.managedQuery(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, largeFileProjection, null, null, largeFileSort); String largeImagePath = ""; try { myCursor.moveToFirst(); largeImagePath = myCursor .getString(myCursor.getColumnIndexOrThrow(MediaStore.Images.ImageColumns.DATA)); } finally { myCursor.close(); } // These are the two URI's you'll be interested in. They give you a handle to the actual images Uri uriLargeImage = Uri.withAppendedPath(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, String.valueOf(imageId)); Uri uriThumbnailImage = Uri.withAppendedPath(MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI, String.valueOf(thumbnailImageId)); if (largeImagePath.length() > 0) return largeImagePath; else if (uriLargeImage != null) return uriLargeImage.getPath(); else if (uriThumbnailImage != null) return uriThumbnailImage.getPath(); else return ""; }
From source file:com.fbbackup.ImageDetailActivity.java
private void setListener() { btn_share.setOnClickListener(new Button.OnClickListener() { @Override/*from w w w .jav a2s. c o m*/ public void onClick(View v) { // TODO Auto-generated method stub // Gets a handle to the clipboard service. ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE); clipboard.setText(clipBoardText); PackageManager pm = getPackageManager(); Intent intent = pm.getLaunchIntentForPackage("jp.naver.line.android"); File file = new File(extStorageDirectory + "/DCIM/FBBackup/test.jpg"); Uri outputFileUri = Uri.fromFile(file); String[] path = { extStorageDirectory + "/DCIM/FBBackup/test.jpg" }; // MediaScannerConnection.scanFile(this, path, null, // new MediaScannerConnection.OnScanCompletedListener() { // public void onScanCompleted(String path, Uri uri) { // Log.i("ExternalStorage", "Scanned " + path + ":"); // Log.i("ExternalStorage", "-> uri=" + uri); // } // }); MediaScannerConnection.scanFile(getApplicationContext(), path, null, null); Log.w("RyanWang", outputFileUri.getPath()); intent.setAction(Intent.ACTION_SEND); intent.putExtra(Intent.EXTRA_STREAM, outputFileUri); intent.setType("image/jpeg"); startActivity(intent); } }); btn_download_photo.setOnClickListener(new ImageButton.OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub DownloadSinglePicTask download = new DownloadSinglePicTask(); download.setContext(ImageDetailActivity.this); download.setAlbunPhotoUrl(clipBoardText); Log.w("downloadpic", "ImageDetail albumName:" + albumName); download.setPath( extStorageDirectory + "/DCIM/FBBackup/" + name + "/" + Utils.getDirName(albumName) + "/"); download.execute("test"); } }); }
From source file:com.handpoint.headstart.client.ui.MainActivity.java
Properties loadIniProperties(Intent iniIntent) throws IOException { InputStream attachment = null; Uri returnedUri = iniIntent.getData(); try {/*from w w w . ja v a 2 s. co m*/ if (iniIntent.getScheme().equals("file")) { attachment = new FileInputStream(returnedUri.getPath()); } else if (iniIntent.getScheme().equals("content")) { attachment = getContentResolver().openInputStream(returnedUri); } Properties p = new Properties(); p.load(attachment); return p; } finally { if (null != attachment) { try { attachment.close(); } catch (IOException ignore) { } } } }
From source file:com.layer.atlas.messenger.AtlasMessagesScreen.java
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (debug)//from w w w . ja va2s . c o m Log.w(TAG, "onActivityResult() requestCode: " + requestCode + ", resultCode: " + resultCode + ", uri: " + (data == null ? "" : data.getData()) + ", data: " + (data == null ? "" : MessengerApp.toString(data.getExtras()))); if (resultCode != Activity.RESULT_OK) return; final LayerClient layerClient = ((MessengerApp) getApplication()).getLayerClient(); switch (requestCode) { case REQUEST_CODE_CAMERA: if (photoFile == null) { if (debug) Log.w(TAG, "onActivityResult() taking photo, but output is undefined... "); return; } if (!photoFile.exists()) { if (debug) Log.w(TAG, "onActivityResult() taking photo, but photo file doesn't exist: " + photoFile.getPath()); return; } if (photoFile.length() == 0) { if (debug) Log.w(TAG, "onActivityResult() taking photo, but photo file is empty: " + photoFile.getPath()); return; } try { // prepare original final File originalFile = photoFile; FileInputStream fisOriginal = new FileInputStream(originalFile) { public void close() throws IOException { super.close(); boolean deleted = originalFile.delete(); if (debug) Log.w(TAG, "close() original file is" + (!deleted ? " not" : "") + " removed: " + originalFile.getName()); photoFile = null; } }; final MessagePart originalPart = layerClient.newMessagePart(Atlas.MIME_TYPE_IMAGE_JPEG, fisOriginal, originalFile.length()); File tempDir = getCacheDir(); MessagePart[] previewAndSize = Atlas.buildPreviewAndSize(originalFile, layerClient, tempDir); if (previewAndSize == null) { Log.e(TAG, "onActivityResult() cannot build preview, cancel send..."); return; } Message msg = layerClient.newMessage(originalPart, previewAndSize[0], previewAndSize[1]); if (debug) Log.w(TAG, "onActivityResult() sending photo... "); preparePushMetadata(msg); conv.send(msg); } catch (Exception e) { Log.e(TAG, "onActivityResult() cannot insert photo" + e); } break; case REQUEST_CODE_GALLERY: if (data == null) { if (debug) Log.w(TAG, "onActivityResult() insert from gallery: no data... :( "); return; } // first check media gallery Uri selectedImageUri = data.getData(); // TODO: Mi4 requires READ_EXTERNAL_STORAGE permission for such operation String selectedImagePath = getGalleryImagePath(selectedImageUri); String resultFileName = selectedImagePath; if (selectedImagePath != null) { if (debug) Log.w(TAG, "onActivityResult() image from gallery selected: " + selectedImagePath); } else if (selectedImageUri.getPath() != null) { if (debug) Log.w(TAG, "onActivityResult() image from file picker appears... " + selectedImageUri.getPath()); resultFileName = selectedImageUri.getPath(); } if (resultFileName != null) { String mimeType = Atlas.MIME_TYPE_IMAGE_JPEG; if (resultFileName.endsWith(".png")) mimeType = Atlas.MIME_TYPE_IMAGE_PNG; if (resultFileName.endsWith(".gif")) mimeType = Atlas.MIME_TYPE_IMAGE_GIF; // test file copy locally try { // create message and upload content InputStream fis = null; File fileToUpload = new File(resultFileName); if (fileToUpload.exists()) { fis = new FileInputStream(fileToUpload); } else { if (debug) Log.w(TAG, "onActivityResult() file to upload doesn't exist, path: " + resultFileName + ", trying ContentResolver"); fis = getContentResolver().openInputStream(data.getData()); if (fis == null) { if (debug) Log.w(TAG, "onActivityResult() cannot open stream with ContentResolver, uri: " + data.getData()); } } String fileName = "galleryFile" + System.currentTimeMillis() + ".jpg"; final File originalFile = new File( getExternalFilesDir(android.os.Environment.DIRECTORY_PICTURES), fileName); OutputStream fos = new FileOutputStream(originalFile); int totalBytes = Tools.streamCopyAndClose(fis, fos); if (debug) Log.w(TAG, "onActivityResult() copied " + totalBytes + " to file: " + originalFile.getName()); FileInputStream fisOriginal = new FileInputStream(originalFile) { public void close() throws IOException { super.close(); boolean deleted = originalFile.delete(); if (debug) Log.w(TAG, "close() original file is" + (!deleted ? " not" : "") + " removed: " + originalFile.getName()); } }; final MessagePart originalPart = layerClient.newMessagePart(mimeType, fisOriginal, originalFile.length()); File tempDir = getCacheDir(); MessagePart[] previewAndSize = Atlas.buildPreviewAndSize(originalFile, layerClient, tempDir); if (previewAndSize == null) { Log.e(TAG, "onActivityResult() cannot build preview, cancel send..."); return; } Message msg = layerClient.newMessage(originalPart, previewAndSize[0], previewAndSize[1]); if (debug) Log.w(TAG, "onActivityResult() uploaded " + originalFile.length() + " bytes"); preparePushMetadata(msg); conv.send(msg); } catch (Exception e) { Log.e(TAG, "onActivityResult() cannot upload file: " + resultFileName, e); return; } } break; default: break; } }
From source file:com.bt.download.android.gui.Librarian.java
public FileDescriptor getFileDescriptor(Uri uri) { FileDescriptor fd = null;//from w ww .jav a2 s. c o m try { if (uri != null) { if (uri.toString().startsWith("file://")) { fd = getFileDescriptor(new File(uri.getPath())); } else { TableFetcher fetcher = TableFetchers.getFetcher(uri); fd = new FileDescriptor(); fd.fileType = fetcher.getFileType(); fd.id = Integer.valueOf(uri.getLastPathSegment()); } } } catch (Throwable e) { fd = null; // sometimes uri.getLastPathSegment() is not an integer e.printStackTrace(); } return fd; }
From source file:nf.frex.android.FrexActivity.java
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (resultCode != Activity.RESULT_OK) { return;/*from w w w . j a v a 2 s .co m*/ } if (requestCode == R.id.manage_fractals && data.getAction().equals(Intent.ACTION_VIEW)) { final Uri imageUri = data.getData(); if (imageUri != null) { File imageFile = new File(imageUri.getPath()); String configName = FrexIO.getFilenameWithoutExt(imageFile); File paramFile = new File(imageFile.getParent(), configName + FrexIO.PARAM_FILE_EXT); try { FileInputStream fis = new FileInputStream(paramFile); try { readFrexDoc(fis, configName); } finally { fis.close(); } } catch (IOException e) { Toast.makeText(FrexActivity.this, getString(R.string.error_msg, e.getLocalizedMessage()), Toast.LENGTH_SHORT).show(); } } } else if (requestCode == R.id.settings) { view.getGenerator().setNumTasks(SettingsActivity.getNumTasks(this)); } else if (requestCode == SELECT_PICTURE_REQUEST_CODE) { final Uri imageUri = data.getData(); final ColorQuantizer colorQuantizer = new ColorQuantizer(); final ProgressDialog progressDialog = new ProgressDialog(FrexActivity.this); final DialogInterface.OnCancelListener cancelListener = new DialogInterface.OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { if (progressDialog.isShowing()) { progressDialog.dismiss(); } colorQuantizer.cancel(); } }; final ColorQuantizer.ProgressListener progressListener = new ColorQuantizer.ProgressListener() { @Override public void progress(final String msg, final int iter, final int maxIter) { runOnUiThread(new Runnable() { @Override public void run() { progressDialog.setMessage(msg); progressDialog.setProgress(iter); } }); } }; progressDialog.setTitle(getString(R.string.get_pal_from_img_title)); progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); progressDialog.setCancelable(true); progressDialog.setOnCancelListener(cancelListener); progressDialog.setMax(colorQuantizer.getMaxIterCount()); progressDialog.show(); Thread thread = new Thread(new Runnable() { @Override public void run() { Bitmap bitmap; try { bitmap = FrexIO.readBitmap(getContentResolver(), imageUri, 256); } catch (IOException e) { alert("I/O error: " + e.getLocalizedMessage()); return; } ColorScheme colorScheme = colorQuantizer.quantize(bitmap, progressListener); progressDialog.dismiss(); if (colorScheme != null) { Log.d(TAG, "SELECT_PICTURE_REQUEST_CODE: Got colorScheme"); String colorSchemeId = "$" + imageUri.toString(); colorSchemes.add(colorSchemeId, colorScheme); view.setColorSchemeId(colorSchemeId); view.setColorScheme(colorScheme); view.recomputeColors(); runOnUiThread(new Runnable() { @Override public void run() { Log.d(TAG, "SELECT_PICTURE_REQUEST_CODE: showDialog(R.id.colors)"); showDialog(R.id.colors); } }); } } }); thread.start(); } }
From source file:fr.cmoatoto.multishare.receiver.NanoHTTPDReceiver.java
public String addFile(Uri imageUri) { String hashPath = "" + imageUri.getPath().hashCode(); correspondances.put("/" + hashPath, imageUri); return hashPath; }