List of usage examples for android.net Uri getScheme
@Nullable public abstract String getScheme();
From source file:com.appbase.androidquery.callback.AbstractAjaxCallback.java
private static String extractUrl(Uri uri) { String result = uri.getScheme() + "://" + uri.getAuthority() + uri.getPath(); String fragment = uri.getFragment(); if (fragment != null) result += "#" + fragment; return result; }
From source file:com.aimfire.gallery.cardboard.PhotoActivity.java
private String getFilePathFromUri(Uri uri) { String filePath = null;/* ww w. j av a 2 s . c om*/ if ("content".equals(uri.getScheme())) { return null; /* String[] filePathColumn = { MediaColumns.DATA }; ContentResolver contentResolver = getContentResolver(); Cursor cursor = contentResolver.query(uri, filePathColumn, null, null, null); cursor.moveToFirst(); //int columnIndex = cursor.getColumnIndex(filePathColumn[0]); int columnIndex = cursor.getColumnIndex(DownloadManager.COLUMN_LOCAL_URI); filePath = cursor.getString(columnIndex); cursor.close(); */ } else if ("file".equals(uri.getScheme())) { filePath = new File(uri.getPath()).getAbsolutePath(); } return filePath; }
From source file:Main.java
/** * Get a GhostMySelfie file path from a Uri. This will get the the path * for Storage Access Framework Documents, as well as the _data * field for the MediaStore and other file-based ContentProviders. * //from w w w. j av a 2 s . c om * @param context The context. * @param uri The Uri to query. * * return selfieFilePath */ public static String getPath(final Context context, final Uri uri) { // Check if the version of current device is greater // than API 19 (KitKat). final boolean isKitKat = Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT; // DocumentProvider. if (isKitKat && DocumentsContract.isDocumentUri(context, uri)) { // ExternalStorageProvider if (isExternalStorageDocument(uri)) { final String docId = DocumentsContract.getDocumentId(uri); final String[] split = docId.split(":"); final String type = split[0]; if ("primary".equalsIgnoreCase(type)) { return Environment.getExternalStorageDirectory() + "/" + split[1]; } } // DownloadsProvider else if (isDownloadsDocument(uri)) { final String id = DocumentsContract.getDocumentId(uri); final Uri contentUri = ContentUris.withAppendedId(Uri.parse(DOWNLOADS_PROVIDER_PATH), Long.valueOf(id)); return getGhostMySelfieDataColumn(context, contentUri, null, null); } // MediaProvider else if (isMediaDocument(uri)) { final String docId = DocumentsContract.getDocumentId(uri); final String[] split = docId.split(":"); final Uri contentUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI; final String selection = "_id = ?"; final String[] selectionArgs = new String[] { split[1] }; // Get the FilePath from GhostMySelfie MediStore // for given Uri, selection, selectionArgs. return getGhostMySelfieDataColumn(context, contentUri, selection, selectionArgs); } } // MediaStore (and general) . else if ("content".equalsIgnoreCase(uri.getScheme())) return getGhostMySelfieDataColumn(context, uri, null, null); // File else if ("file".equalsIgnoreCase(uri.getScheme())) return uri.getPath(); return null; }
From source file:edu.mit.mobile.android.locast.data.Sync.java
private void sync(Uri toSync, SyncProgressNotifier syncProgress, Bundle extras) throws SyncException, IOException { Uri localUri;/*from w w w. j av a 2s .c o m*/ if ("http".equals(toSync.getScheme()) || "https".equals(toSync.getScheme())) { if (!extras.containsKey(EXTRA_DESTINATION_URI)) { throw new IllegalArgumentException("missing EXTRA_DESTINATION_URI when syncing HTTP URIs"); } localUri = (Uri) extras.get(EXTRA_DESTINATION_URI); if (!MediaProvider.canSync(localUri)) { throw new IllegalArgumentException("URI " + toSync + " is not syncable."); } } else { localUri = toSync; } if (!MediaProvider.canSync(localUri)) { throw new IllegalArgumentException("URI " + toSync + " is not syncable."); } sync(toSync, getSyncItem(localUri), syncProgress, extras); }
From source file:Main.java
public static String getPhotoPathFromContentUri(Context context, Uri uri) { String photoPath = ""; if (context == null || uri == null) { return photoPath; }//from w w w.ja va 2 s. c o m 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:net.sf.asap.Player.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Uri uri = getIntent().getData(); filename = uri.getLastPathSegment(); ZipFile zip = null;//from ww w . j a va 2s. c om final byte[] module = new byte[ASAPInfo.MAX_MODULE_LENGTH]; int moduleLen; try { InputStream is; if (Util.isZip(filename)) { zip = new ZipFile(uri.getPath()); filename = uri.getFragment(); is = zip.getInputStream(zip.getEntry(filename)); } else { try { is = getContentResolver().openInputStream(uri); } catch (FileNotFoundException ex) { if (uri.getScheme().equals("http")) is = httpGet(uri); else throw ex; } } moduleLen = readAndClose(is, module); } catch (IOException ex) { showError(R.string.error_reading_file); return; } finally { Util.close(zip); } try { asap.load(filename, module, moduleLen); } catch (Exception ex) { showError(R.string.invalid_file); return; } info = asap.getInfo(); setTitle(R.string.playing_title); setContentView(R.layout.playing); setTag(R.id.name, info.getTitleOrFilename()); setTag(R.id.author, info.getAuthor()); setTag(R.id.date, info.getDate()); findViewById(R.id.stop_button).setOnClickListener(new OnClickListener() { public void onClick(View v) { finish(); } }); mediaController = new MediaController(this, false); mediaController.setAnchorView(getContentView()); mediaController.setMediaPlayer(new MediaController.MediaPlayerControl() { public boolean canPause() { return !isPaused(); } public boolean canSeekBackward() { return false; } public boolean canSeekForward() { return false; } public int getBufferPercentage() { return 100; } public int getCurrentPosition() { return asap.getPosition(); } public int getDuration() { return info.getDuration(song); } public boolean isPlaying() { return !isPaused(); } public void pause() { audioTrack.pause(); } public void seekTo(int pos) { seek(pos); } public void start() { resume(); } }); if (info.getSongs() > 1) { mediaController.setPrevNextListeners(new OnClickListener() { public void onClick(View v) { playNextSong(); } }, new OnClickListener() { public void onClick(View v) { playPreviousSong(); } }); } new Handler().postDelayed(new Runnable() { public void run() { mediaController.show(); } }, 500); stop = false; playSong(info.getDefaultSong()); new Thread(this).start(); }
From source file:com.cerema.cloud2.ui.activity.Uploader.java
public void uploadFiles() { try {/*from w w w . j a v a2 s . c om*/ // ArrayList for files with path in external storage ArrayList<String> local = new ArrayList<String>(); ArrayList<String> remote = new ArrayList<String>(); // this checks the mimeType for (Parcelable mStream : mStreamsToUpload) { Uri uri = (Uri) mStream; String data = null; String filePath = ""; if (uri != null) { if (uri.getScheme().equals("content")) { String mimeType = getContentResolver().getType(uri); if (mimeType.contains("image")) { String[] CONTENT_PROJECTION = { Images.Media.DATA, Images.Media.DISPLAY_NAME, Images.Media.MIME_TYPE, Images.Media.SIZE }; Cursor c = getContentResolver().query(uri, CONTENT_PROJECTION, null, null, null); c.moveToFirst(); int index = c.getColumnIndex(Images.Media.DATA); data = c.getString(index); local.add(data); remote.add(mUploadPath + c.getString(c.getColumnIndex(Images.Media.DISPLAY_NAME))); } else if (mimeType.contains("video")) { String[] CONTENT_PROJECTION = { Video.Media.DATA, Video.Media.DISPLAY_NAME, Video.Media.MIME_TYPE, Video.Media.SIZE, Video.Media.DATE_MODIFIED }; Cursor c = getContentResolver().query(uri, CONTENT_PROJECTION, null, null, null); c.moveToFirst(); int index = c.getColumnIndex(Video.Media.DATA); data = c.getString(index); local.add(data); remote.add(mUploadPath + c.getString(c.getColumnIndex(Video.Media.DISPLAY_NAME))); } else if (mimeType.contains("audio")) { String[] CONTENT_PROJECTION = { Audio.Media.DATA, Audio.Media.DISPLAY_NAME, Audio.Media.MIME_TYPE, Audio.Media.SIZE }; Cursor c = getContentResolver().query(uri, CONTENT_PROJECTION, null, null, null); c.moveToFirst(); int index = c.getColumnIndex(Audio.Media.DATA); data = c.getString(index); local.add(data); remote.add(mUploadPath + c.getString(c.getColumnIndex(Audio.Media.DISPLAY_NAME))); } else { filePath = Uri.decode(uri.toString()).replace(uri.getScheme() + "://", ""); // cut everything whats before mnt. It occured to me that sometimes apps send // their name into the URI if (filePath.contains("mnt")) { String splitedFilePath[] = filePath.split("/mnt"); filePath = splitedFilePath[1]; } final File file = new File(filePath); local.add(file.getAbsolutePath()); remote.add(mUploadPath + file.getName()); } } else if (uri.getScheme().equals("file")) { filePath = Uri.decode(uri.toString()).replace(uri.getScheme() + "://", ""); if (filePath.contains("mnt")) { String splitedFilePath[] = filePath.split("/mnt"); filePath = splitedFilePath[1]; } final File file = new File(filePath); data = file.getAbsolutePath(); filePath = mUploadPath + file.getName(); } else { throw new SecurityException(); } if (data == null) { mRemoteCacheData.add(filePath); CopyTmpFileAsyncTask copyTask = new CopyTmpFileAsyncTask(this); Object[] params = { uri, filePath, mRemoteCacheData.size() - 1, getAccount().name, getContentResolver() }; mNumCacheFile++; showWaitingCopyDialog(); copyTask.execute(params); } } else { throw new SecurityException(); } Intent intent = new Intent(getApplicationContext(), FileUploader.class); intent.putExtra(FileUploader.KEY_UPLOAD_TYPE, FileUploader.UPLOAD_MULTIPLE_FILES); intent.putExtra(FileUploader.KEY_LOCAL_FILE, local.toArray(new String[local.size()])); intent.putExtra(FileUploader.KEY_REMOTE_FILE, remote.toArray(new String[remote.size()])); intent.putExtra(FileUploader.KEY_ACCOUNT, getAccount()); startService(intent); //Save the path to shared preferences SharedPreferences.Editor appPrefs = PreferenceManager .getDefaultSharedPreferences(getApplicationContext()).edit(); appPrefs.putString("last_upload_path", mUploadPath); appPrefs.apply(); finish(); } } catch (SecurityException e) { String message = String.format(getString(R.string.uploader_error_forbidden_content), getString(R.string.app_name)); Toast.makeText(this, message, Toast.LENGTH_LONG).show(); } }
From source file:Main.java
@TargetApi(19) public static String getImageAbsolutePath(Context context, Uri imageUri) { if (context == null || imageUri == null) return null; if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT && DocumentsContract.isDocumentUri(context, imageUri)) { if (isExternalStorageDocument(imageUri)) { String docId = DocumentsContract.getDocumentId(imageUri); String[] split = docId.split(":"); String type = split[0]; if ("primary".equalsIgnoreCase(type)) { return Environment.getExternalStorageDirectory() + "/" + split[1]; }//from www . ja v a2 s. co m } else if (isDownloadsDocument(imageUri)) { String id = DocumentsContract.getDocumentId(imageUri); Uri contentUri = ContentUris.withAppendedId(Uri.parse("content://downloads/public_downloads"), Long.valueOf(id)); return getDataColumn(context, contentUri, null, null); } else if (isMediaDocument(imageUri)) { String docId = DocumentsContract.getDocumentId(imageUri); 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); } } // MediaStore (and general) else if ("content".equalsIgnoreCase(imageUri.getScheme())) { // Return the remote address if (isGooglePhotosUri(imageUri)) return imageUri.getLastPathSegment(); return getDataColumn(context, imageUri, null, null); } // File else if ("file".equalsIgnoreCase(imageUri.getScheme())) { return imageUri.getPath(); } return null; }
From source file:Main.java
@TargetApi(19) public static String getImageAbsolutePath(Activity context, Uri imageUri) { if (context == null || imageUri == null) return null; if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT && DocumentsContract.isDocumentUri(context, imageUri)) { if (isExternalStorageDocument(imageUri)) { String docId = DocumentsContract.getDocumentId(imageUri); String[] split = docId.split(":"); String type = split[0]; if ("primary".equalsIgnoreCase(type)) { return Environment.getExternalStorageDirectory() + "/" + split[1]; }//from www . j a va 2s.c o m } else if (isDownloadsDocument(imageUri)) { String id = DocumentsContract.getDocumentId(imageUri); Uri contentUri = ContentUris.withAppendedId(Uri.parse("content://downloads/public_downloads"), Long.valueOf(id)); return getDataColumn(context, contentUri, null, null); } else if (isMediaDocument(imageUri)) { String docId = DocumentsContract.getDocumentId(imageUri); 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); } } // MediaStore (and general) else if ("content".equalsIgnoreCase(imageUri.getScheme())) { // Return the remote address if (isGooglePhotosUri(imageUri)) return imageUri.getLastPathSegment(); return getDataColumn(context, imageUri, null, null); } // File else if ("file".equalsIgnoreCase(imageUri.getScheme())) { return imageUri.getPath(); } return null; }
From source file:Main.java
@TargetApi(Build.VERSION_CODES.KITKAT) public static String getImageAbsolutePath19(Activity context, Uri imageUri) { if (context == null || imageUri == null) return null; if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT && DocumentsContract.isDocumentUri(context, imageUri)) { if (isExternalStorageDocument(imageUri)) { String docId = DocumentsContract.getDocumentId(imageUri); String[] split = docId.split(":"); String type = split[0]; if ("primary".equalsIgnoreCase(type)) { return Environment.getExternalStorageDirectory() + "/" + split[1]; }/* ww w . java2 s.c o m*/ } else if (isDownloadsDocument(imageUri)) { String id = DocumentsContract.getDocumentId(imageUri); Uri contentUri = ContentUris.withAppendedId(Uri.parse("content://downloads/public_downloads"), Long.valueOf(id)); return getDataColumn(context, contentUri, null, null); } else if (isMediaDocument(imageUri)) { String docId = DocumentsContract.getDocumentId(imageUri); 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); } } // MediaStore (and general) if ("content".equalsIgnoreCase(imageUri.getScheme())) { // Return the remote address if (isGooglePhotosUri(imageUri)) return imageUri.getLastPathSegment(); return getDataColumn(context, imageUri, null, null); } // File else if ("file".equalsIgnoreCase(imageUri.getScheme())) { return imageUri.getPath(); } return null; }