List of usage examples for android.net Uri getPath
@Nullable public abstract String getPath();
From source file:com.karura.framework.plugins.Capture.java
/** * Queries the media store to find out what the file path is for the Uri we supply * /* w w w . j a v a2s . c om*/ * @param contentUri * the Uri of the audio/image/video * @param context * the current application context * @return the full path to the file */ @SuppressWarnings("deprecation") public static String getRealPathFromURI(Uri contentUri, Activity context) { final String scheme = contentUri.getScheme(); if (scheme == null) { return contentUri.toString(); } else if (scheme.compareTo("content") == 0) { String[] proj = { DATA }; Cursor cursor = context.managedQuery(contentUri, proj, null, null, null); int column_index = cursor.getColumnIndexOrThrow(DATA); cursor.moveToFirst(); return cursor.getString(column_index); } else if (scheme.compareTo("file") == 0) { return contentUri.getPath(); } else { return contentUri.toString(); } }
From source file:com.just.agentweb.AgentWebUtils.java
@TargetApi(19) static String getFileAbsolutePath(Activity context, Uri fileUri) { if (context == null || fileUri == null) { return null; }//w w w .j a v a 2 s . co m LogUtils.i(TAG, "getAuthority:" + fileUri.getAuthority() + " getHost:" + fileUri.getHost() + " getPath:" + fileUri.getPath() + " getScheme:" + fileUri.getScheme() + " query:" + fileUri.getQuery()); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT && DocumentsContract.isDocumentUri(context, fileUri)) { if (isExternalStorageDocument(fileUri)) { String docId = DocumentsContract.getDocumentId(fileUri); String[] split = docId.split(":"); String type = split[0]; if ("primary".equalsIgnoreCase(type)) { return Environment.getExternalStorageDirectory() + "/" + split[1]; } } else if (isDownloadsDocument(fileUri)) { String id = DocumentsContract.getDocumentId(fileUri); Uri contentUri = ContentUris.withAppendedId(Uri.parse("content://downloads/public_downloads"), Long.valueOf(id)); return getDataColumn(context, contentUri, null, null); } else if (isMediaDocument(fileUri)) { String docId = DocumentsContract.getDocumentId(fileUri); String[] split = docId.split(":"); String type = split[0]; Uri contentUri = null; if ("image".equals(type)) { contentUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI; } else if ("video".equals(type)) { contentUri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI; } else if ("audio".equals(type)) { contentUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI; } String selection = MediaStore.Images.Media._ID + "=?"; String[] selectionArgs = new String[] { split[1] }; return getDataColumn(context, contentUri, selection, selectionArgs); } else { } } // MediaStore (and general) else if (fileUri.getAuthority().equalsIgnoreCase(context.getPackageName() + ".AgentWebFileProvider")) { String path = fileUri.getPath(); int index = path.lastIndexOf("/"); return getAgentWebFilePath(context) + File.separator + path.substring(index + 1, path.length()); } else if ("content".equalsIgnoreCase(fileUri.getScheme())) { // Return the remote address if (isGooglePhotosUri(fileUri)) { return fileUri.getLastPathSegment(); } return getDataColumn(context, fileUri, null, null); } // File else if ("file".equalsIgnoreCase(fileUri.getScheme())) { return fileUri.getPath(); } return null; }
From source file:ca.rmen.android.networkmonitor.app.savetostorage.SaveToStorageActivity.java
@Override public void onFileSelected(int actionId, File file) { Log.v(TAG, "onFileSelected: file = " + file); NetMonPreferences.getInstance(this).setExportFolder(file); Uri uri = getIntent().getParcelableExtra(Intent.EXTRA_STREAM); File sourceFile = new File(uri.getPath()); // If the user picked a file, we'll save to that file. // If the user picked a folder, we'll save in that folder, with the original file name. final File destFile; if (file.isDirectory()) destFile = new File(file, sourceFile.getName()); else/*from ww w . j a va 2s. co m*/ destFile = file; Intent intent = new Intent(this, SaveToStorageService.class); intent.putExtra(SaveToStorageService.EXTRA_SOURCE_FILE, sourceFile); intent.putExtra(SaveToStorageService.EXTRA_DESTINATION_FILE, destFile); startService(intent); finish(); }
From source file:com.rafamaya.imagesearch.DataLayerListenerService.java
@Override public void onDataChanged(DataEventBuffer dataEvents) { LOGD(TAG, "onDataChanged: " + dataEvents); final List<DataEvent> events = FreezableUtils.freezeIterable(dataEvents); dataEvents.close();/*from w ww . j av a2s .com*/ if (!mGoogleApiClient.isConnected()) { ConnectionResult connectionResult = mGoogleApiClient.blockingConnect(30, TimeUnit.SECONDS); if (!connectionResult.isSuccess()) { Log.e(TAG, "DataLayerListenerService failed to connect to GoogleApiClient."); return; } } // Loop through the events and send a message back to the node that created the data item. for (DataEvent event : events) { Uri uri = event.getDataItem().getUri(); String path = uri.getPath(); if (COUNT_PATH.equals(path)) { // Get the node id of the node that created the data item from the host portion of // the uri. String nodeId = uri.getHost(); // Set the data of the message to be the bytes of the Uri. byte[] payload = uri.toString().getBytes(); // Send the rpc Wearable.MessageApi.sendMessage(mGoogleApiClient, nodeId, DATA_ITEM_RECEIVED_PATH, payload); } } }
From source file:com.my.seams_carv.view.ImagePreviewerDialogFragment.java
@Nullable @Override/* w w w . j a v a 2 s . co m*/ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View layout = inflater.inflate(R.layout.fragment_image_previewer, container, false); SimpleDraweeView imageView = (SimpleDraweeView) layout.findViewById(R.id.image); TextView imageUriView = (TextView) layout.findViewById(R.id.image_uri); Uri uri = getArguments().getParcelable(EXTRA_URI); if (uri != null) { imageView.setImageURI(uri); imageUriView.setText(uri.getPath()); } return layout; }
From source file:com.duy.pascal.ui.file.FileManager.java
/** * get path from uri//from w ww . j av a2 s. c o m */ @Nullable public static String getPathFromUri(Context context, Uri uri) throws URISyntaxException { if ("content".equalsIgnoreCase(uri.getScheme())) { String[] projection = { "_data" }; Cursor cursor; try { cursor = context.getContentResolver().query(uri, projection, null, null, null); if (cursor == null) { return null; } int index = cursor.getColumnIndexOrThrow("_data"); if (cursor.moveToFirst()) { String path = cursor.getString(index); cursor.close(); return path; } } catch (Exception e) { e.printStackTrace(); } } else if ("file".equalsIgnoreCase(uri.getScheme())) { return uri.getPath(); } return null; }
From source file:com.barryku.android.boxnet.BrowseActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.browse);/*ww w. j ava2 s . co m*/ restUri = getString(R.string.rest_uri); apiKey = getString(R.string.api_key); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); String folderId = prefs.getString(LAST_VIEWED_FOLDER, "0"); authToken = prefs.getString(AUTH_TOKEN_KEY, ""); Uri uri = this.getIntent().getData(); if (uri != null) { folderId = uri.getPath().substring(1); } Log.d(LOG_TAG, "loading folder from onCreate()"); loadFolder(folderId); }
From source file:com.facebook.internal.DialogPresenter.java
public static void setupAppCallForWebFallbackDialog(AppCall appCall, Bundle parameters, DialogFeature feature) { Validate.hasFacebookActivity(FacebookSdk.getApplicationContext()); Validate.hasInternetPermissions(FacebookSdk.getApplicationContext()); String featureName = feature.name(); Uri fallbackUrl = getDialogWebFallbackUri(feature); if (fallbackUrl == null) { throw new FacebookException("Unable to fetch the Url for the DialogFeature : '" + featureName + "'"); }//from w ww .j av a 2 s. c om // Since we're talking to the server here, let's use the latest version we know about. // We know we are going to be communicating over a bucketed protocol. int protocolVersion = NativeProtocol.getLatestKnownVersion(); Bundle webParams = ServerProtocol.getQueryParamsForPlatformActivityIntentWebFallback( appCall.getCallId().toString(), protocolVersion, parameters); if (webParams == null) { throw new FacebookException("Unable to fetch the app's key-hash"); } // Now form the Uri if (fallbackUrl.isRelative()) { fallbackUrl = Utility.buildUri(ServerProtocol.getDialogAuthority(), fallbackUrl.toString(), webParams); } else { fallbackUrl = Utility.buildUri(fallbackUrl.getAuthority(), fallbackUrl.getPath(), webParams); } Bundle intentParameters = new Bundle(); intentParameters.putString(NativeProtocol.WEB_DIALOG_URL, fallbackUrl.toString()); intentParameters.putBoolean(NativeProtocol.WEB_DIALOG_IS_FALLBACK, true); Intent webDialogIntent = new Intent(); NativeProtocol.setupProtocolRequestIntent(webDialogIntent, appCall.getCallId().toString(), feature.getAction(), NativeProtocol.getLatestKnownVersion(), intentParameters); webDialogIntent.setClass(FacebookSdk.getApplicationContext(), FacebookActivity.class); webDialogIntent.setAction(FacebookDialogFragment.TAG); appCall.setRequestIntent(webDialogIntent); }
From source file:com.barryku.android.boxnet.BrowseActivity.java
@Override protected void onNewIntent(Intent intent) { super.onNewIntent(intent); Uri uri = intent.getData(); Log.d(LOG_TAG, "loading folder from onNewIntent() from:" + uri); loadFolder(uri.getPath().substring(1)); //remove leading slash }
From source file:com.socialize.util.ImageUtils.java
private InputStream retrieveStream(Uri url) { String path = url == null ? null : url.getPath(); if (path == null) { Log.w(getClass().getSimpleName(), "Error in received url: it's null => " + url); return null; } else {// ww w . ja va 2 s. c om Log.w(getClass().getSimpleName(), "Path to the picture received => " + path); } DefaultHttpClient client = new DefaultHttpClient(); HttpGet httpRequest = new HttpGet(path); try { HttpResponse httpResponse = client.execute(httpRequest); final int statusCode = httpResponse.getStatusLine().getStatusCode(); if (statusCode != HttpStatus.SC_OK) { Log.w(getClass().getSimpleName(), "Error => " + statusCode + " => for URL " + url); return null; } HttpEntity httpEntity = httpResponse.getEntity(); return httpEntity.getContent(); } catch (IOException e) { httpRequest.abort(); Log.w(getClass().getSimpleName(), "Error for URL =>" + url, e); } return null; }