List of usage examples for android.net Uri getScheme
@Nullable public abstract String getScheme();
From source file:doext.easemob.activity.ChatActivity.java
/** * ??/*from ww w . j a va 2 s . com*/ * * @param uri */ private void sendFile(Uri uri) { String filePath = null; if ("content".equalsIgnoreCase(uri.getScheme())) { String[] projection = { "_data" }; Cursor cursor = null; try { cursor = getContentResolver().query(uri, projection, null, null, null); int column_index = cursor.getColumnIndexOrThrow("_data"); if (cursor.moveToFirst()) { filePath = cursor.getString(column_index); } } catch (Exception e) { e.printStackTrace(); } } else if ("file".equalsIgnoreCase(uri.getScheme())) { filePath = uri.getPath(); } File file = new File(filePath); if (file == null || !file.exists()) { String st7 = getResources() .getString(DoResourcesHelper.getIdentifier("File_does_not_exist", "string", this)); Toast.makeText(getApplicationContext(), st7, 0).show(); return; } if (file.length() > 10 * 1024 * 1024) { String st6 = getResources().getString( DoResourcesHelper.getIdentifier("The_file_is_not_greater_than_10_m", "string", this)); Toast.makeText(getApplicationContext(), st6, 0).show(); return; } // ? EMMessage message = EMMessage.createSendMessage(EMMessage.Type.FILE); // ?chattype,?? if (chatType == CHATTYPE_GROUP) message.setChatType(ChatType.GroupChat); message.setReceipt(toChatUsername); // add message body NormalFileMessageBody body = new NormalFileMessageBody(new File(filePath)); message.addBody(body); conversation.addMessage(message); listView.setAdapter(adapter); adapter.refresh(); listView.setSelection(listView.getCount() - 1); setResult(RESULT_OK); }
From source file:com.android.music.MediaPlaybackActivity.java
private void startPlayback() { if (mService == null) return;//from ww w .j a va 2 s . c o m Intent intent = getIntent(); String filename = ""; Uri uri = intent.getData(); if (uri != null && uri.toString().length() > 0) { // If this is a file:// URI, just use the path directly instead // of going through the open-from-filedescriptor codepath. String scheme = uri.getScheme(); if ("file".equals(scheme)) { filename = uri.getPath(); } else { filename = uri.toString(); } try { mService.stop(); mService.openFile(filename); mService.play(); setIntent(new Intent()); } catch (Exception ex) { Log.d("MediaPlaybackActivity", "couldn't start playback: " + ex); } } updateTrackInfo(); long next = refreshNow(); queueNextRefresh(next); }
From source file:com.ccxt.whl.activity.ChatActivity.java
/** * ??//from w w w . jav a2 s. c o m * * @param uri */ private void sendFile(Uri uri) { String filePath = null; if ("content".equalsIgnoreCase(uri.getScheme())) { String[] projection = { "_data" }; Cursor cursor = null; try { cursor = getContentResolver().query(uri, projection, null, null, null); int column_index = cursor.getColumnIndexOrThrow("_data"); if (cursor.moveToFirst()) { filePath = cursor.getString(column_index); } } catch (Exception e) { e.printStackTrace(); } } else if ("file".equalsIgnoreCase(uri.getScheme())) { filePath = uri.getPath(); } File file = new File(filePath); if (file == null || !file.exists()) { Toast.makeText(getApplicationContext(), "?", 0).show(); return; } if (file.length() > 10 * 1024 * 1024) { Toast.makeText(getApplicationContext(), "?10M", 0).show(); return; } // ? EMMessage message = EMMessage.createSendMessage(EMMessage.Type.FILE); // ?chattype,?? if (chatType == CHATTYPE_GROUP) message.setChatType(ChatType.GroupChat); message.setReceipt(toChatUsername); // add message body NormalFileMessageBody body = new NormalFileMessageBody(new File(filePath)); message.addBody(body); conversation.addMessage(message); listView.setAdapter(adapter); adapter.refresh(); listView.setSelection(listView.getCount() - 1); setResult(RESULT_OK); }
From source file:com.intel.xdk.camera.Camera.java
/** * Get a 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./* ww w.j a v a2 s . c o m*/ * * @param context The context. * @param uri The Uri to query. * @author paulburke */ @SuppressLint("NewApi") public static String getPath(final Context context, final Uri uri) { 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]; } // TODO handle non-primary volumes } // DownloadsProvider else if (isDownloadsDocument(uri)) { final String id = DocumentsContract.getDocumentId(uri); final Uri contentUri = ContentUris.withAppendedId(Uri.parse("content://downloads/public_downloads"), Long.valueOf(id)); return getDataColumn(context, contentUri, null, null); } // MediaProvider else if (isMediaDocument(uri)) { final String docId = DocumentsContract.getDocumentId(uri); final String[] split = docId.split(":"); final 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; } final String selection = "_id=?"; final String[] selectionArgs = new String[] { split[1] }; return getDataColumn(context, contentUri, selection, selectionArgs); } } // MediaStore (and general) else if ("content".equalsIgnoreCase(uri.getScheme())) { return getDataColumn(context, uri, null, null); } // File else if ("file".equalsIgnoreCase(uri.getScheme())) { return uri.getPath(); } return null; }
From source file:com.polychrom.cordova.actionbar.ActionBarSherlock.java
private Drawable getDrawableForURI(String uri_string) { Uri uri = Uri.parse(uri_string); Context ctx = ((SherlockActivity) cordova); // Special case - TrueType fonts if (uri_string.endsWith(".ttf")) { /*for(String base: bases) {// ww w .ja v a 2s . c om String path = base + uri; // TODO: Font load / glyph rendering ("/blah/fontawesome.ttf:\f1234") }*/ } else if (uri_string.startsWith("R.drawable")) { String[] array = uri_string.split("\\."); String name = array[2]; int resourceId = ctx.getResources().getIdentifier(name, "drawable", ctx.getPackageName()); Drawable drawable = ctx.getResources().getDrawable(resourceId); return drawable; } // General bitmap else { if (uri.isAbsolute()) { if (uri.getScheme().startsWith("http")) { try { URL url = new URL(uri_string); InputStream stream = url.openConnection().getInputStream(); return new BitmapDrawable(ctx.getResources(), stream); } catch (MalformedURLException e) { return null; } catch (IOException e) { return null; } catch (Exception e) { return null; } } else { try { InputStream stream = ctx.getContentResolver().openInputStream(uri); return new BitmapDrawable(ctx.getResources(), stream); } catch (FileNotFoundException e) { return null; } } } else { for (String base : bases) { String path = base + uri; // Asset if (base.startsWith("file:///android_asset/")) { path = path.substring(22); try { InputStream stream = ctx.getAssets().open(path); return new BitmapDrawable(ctx.getResources(), stream); } catch (IOException e) { continue; } } // General URI else { try { InputStream stream = ctx.getContentResolver().openInputStream(Uri.parse(path)); return new BitmapDrawable(ctx.getResources(), stream); } catch (FileNotFoundException e) { continue; } } } } } return null; }
From source file:com.vuze.android.remote.SessionInfo.java
public void openTorrent(final Activity activity, final Uri uri) { if (AndroidUtils.DEBUG) { Log.d(TAG, "openTorrent " + uri); }//from w w w . j a va 2 s. com if (uri == null) { return; } String scheme = uri.getScheme(); if (AndroidUtils.DEBUG) { Log.d(TAG, "openTorrent " + scheme); } if ("file".equals(scheme) || "content".equals(scheme)) { AndroidUtilsUI.requestPermissions(activity, new String[] { Manifest.permission.READ_EXTERNAL_STORAGE }, new Runnable() { @Override public void run() { openTorrent_perms(activity, uri); } }, new Runnable() { @Override public void run() { Toast.makeText(activity, R.string.content_read_failed_perms_denied, Toast.LENGTH_LONG) .show(); } }); } else { openTorrent(activity, uri.toString(), (String) null); } }
From source file:com.givon.anhao.activity.ChatActivity.java
/** * ??/*from w ww.java 2s . c o m*/ * * @param uri */ private void sendFile(Uri uri) { addFriend(mUserBean, chatType); String filePath = null; if ("content".equalsIgnoreCase(uri.getScheme())) { String[] projection = { "_data" }; Cursor cursor = null; try { cursor = getContentResolver().query(uri, projection, null, null, null); int column_index = cursor.getColumnIndexOrThrow("_data"); if (cursor.moveToFirst()) { filePath = cursor.getString(column_index); } } catch (Exception e) { e.printStackTrace(); } } else if ("file".equalsIgnoreCase(uri.getScheme())) { filePath = uri.getPath(); } File file = new File(filePath); if (file == null || !file.exists()) { Toast.makeText(getApplicationContext(), "?", 0).show(); return; } if (file.length() > 10 * 1024 * 1024) { Toast.makeText(getApplicationContext(), "?10M", 0).show(); return; } // ? EMMessage message = EMMessage.createSendMessage(EMMessage.Type.FILE); // ?chattype,?? if (chatType == CHATTYPE_GROUP) { message.setChatType(ChatType.GroupChat); } message.setReceipt(toChatUsername); // add message body NormalFileMessageBody body = new NormalFileMessageBody(new File(filePath)); message.addBody(body); conversation.addMessage(initExtValue(message)); listView.setAdapter(adapter); adapter.refresh(); listView.setSelection(listView.getCount() - 1); setResult(RESULT_OK); }
From source file:com.interestfriend.activity.ChatActivity.java
/** * //w ww. j a v a 2s. c o m * * @param uri */ private void sendFile(Uri uri) { String filePath = null; if ("content".equalsIgnoreCase(uri.getScheme())) { String[] projection = { "_data" }; Cursor cursor = null; try { cursor = getContentResolver().query(uri, projection, null, null, null); int column_index = cursor.getColumnIndexOrThrow("_data"); if (cursor.moveToFirst()) { filePath = cursor.getString(column_index); } } catch (Exception e) { e.printStackTrace(); } } else if ("file".equalsIgnoreCase(uri.getScheme())) { filePath = uri.getPath(); } File file = new File(filePath); if (file == null || !file.exists()) { Toast.makeText(getApplicationContext(), "", 0).show(); return; } if (file.length() > 10 * 1024 * 1024) { Toast.makeText(getApplicationContext(), "10M", 0).show(); return; } // EMMessage message = EMMessage.createSendMessage(EMMessage.Type.FILE); // chattype, if (chatType == CHATTYPE_GROUP) message.setChatType(ChatType.GroupChat); message.setAttribute("user_name", SharedUtils.getAPPUserName()); message.setAttribute("user_avatar", SharedUtils.getAPPUserAvatar()); message.setAttribute("circle_name", MyApplation.getCircle_name()); message.setAttribute("user_id", SharedUtils.getIntUid()); message.setReceipt(toChatUsername); // add message body NormalFileMessageBody body = new NormalFileMessageBody(new File(filePath)); message.addBody(body); conversation.addMessage(message); listView.setAdapter(adapter); adapter.refresh(); listView.setSelection(listView.getCount() - 1); setResult(RESULT_OK); }
From source file:com.pavlospt.rxfile.RxFile.java
private static Observable<Bitmap> getThumbnailFromUriWithSizeAndKind(final Context context, final Uri data, final int requiredWidth, final int requiredHeight, final int kind) { return Observable.fromCallable(new Func0<Bitmap>() { @Override// w w w .j a v a 2 s . c o m public Bitmap call() { Bitmap bitmap = null; ParcelFileDescriptor parcelFileDescriptor; final BitmapFactory.Options options = new BitmapFactory.Options(); if (requiredWidth > 0 && requiredHeight > 0) { options.inJustDecodeBounds = true; options.inSampleSize = calculateInSampleSize(options, requiredWidth, requiredHeight); options.inJustDecodeBounds = false; } if (!isMediaUri(data)) { logDebug("Not a media uri:" + data); if (isGoogleDriveDocument(data)) { logDebug("Google Drive Uri:" + data); DocumentFile file = DocumentFile.fromSingleUri(context, data); if (file.getType().startsWith(Constants.IMAGE_TYPE) || file.getType().startsWith(Constants.VIDEO_TYPE)) { logDebug("Google Drive Uri:" + data + " (Video or Image)"); try { parcelFileDescriptor = context.getContentResolver().openFileDescriptor(data, Constants.READ_MODE); FileDescriptor fileDescriptor = parcelFileDescriptor.getFileDescriptor(); bitmap = BitmapFactory.decodeFileDescriptor(fileDescriptor, null, options); parcelFileDescriptor.close(); return bitmap; } catch (IOException e) { logError("Exception:" + e.getMessage() + " line: 209"); e.printStackTrace(); } } } else if (data.getScheme().equals(Constants.FILE)) { logDebug("Dropbox or other DocumentsProvider Uri:" + data); try { parcelFileDescriptor = context.getContentResolver().openFileDescriptor(data, Constants.READ_MODE); FileDescriptor fileDescriptor = parcelFileDescriptor.getFileDescriptor(); bitmap = BitmapFactory.decodeFileDescriptor(fileDescriptor, null, options); parcelFileDescriptor.close(); return bitmap; } catch (IOException e) { logError("Exception:" + e.getMessage() + " line: 223"); e.printStackTrace(); } } else { try { parcelFileDescriptor = context.getContentResolver().openFileDescriptor(data, Constants.READ_MODE); FileDescriptor fileDescriptor = parcelFileDescriptor.getFileDescriptor(); bitmap = BitmapFactory.decodeFileDescriptor(fileDescriptor, null, options); parcelFileDescriptor.close(); return bitmap; } catch (IOException e) { logError("Exception:" + e.getMessage() + " line: 235"); e.printStackTrace(); } } } else { logDebug("Uri for thumbnail:" + data); String[] parts = data.getLastPathSegment().split(":"); String fileId = parts[1]; Cursor cursor = null; try { cursor = context.getContentResolver().query(data, null, null, null, null); if (cursor != null) { logDebug("Cursor size:" + cursor.getCount()); if (cursor.moveToFirst()) { if (data.toString().contains(Constants.VIDEO)) { bitmap = MediaStore.Video.Thumbnails.getThumbnail(context.getContentResolver(), Long.parseLong(fileId), kind, options); } else if (data.toString().contains(Constants.IMAGE)) { bitmap = MediaStore.Images.Thumbnails.getThumbnail(context.getContentResolver(), Long.parseLong(fileId), kind, options); } } } return bitmap; } catch (Exception e) { logError("Exception:" + e.getMessage() + " line: 266"); } finally { if (cursor != null) cursor.close(); } } return bitmap; } }); }
From source file:com.ieeton.user.activity.ChatActivity.java
/** * ??//from w w w .ja v a2s . com * * @param uri */ private void sendFile(Uri uri) { String filePath = null; if ("content".equalsIgnoreCase(uri.getScheme())) { String[] projection = { "_data" }; Cursor cursor = null; try { cursor = getContentResolver().query(uri, projection, null, null, null); int column_index = cursor.getColumnIndexOrThrow("_data"); if (cursor.moveToFirst()) { filePath = cursor.getString(column_index); } } catch (Exception e) { e.printStackTrace(); } } else if ("file".equalsIgnoreCase(uri.getScheme())) { filePath = uri.getPath(); } File file = new File(filePath); if (file == null || !file.exists()) { Toast.makeText(getApplicationContext(), "?", Toast.LENGTH_SHORT).show(); return; } if (file.length() > 10 * 1024 * 1024) { Toast.makeText(getApplicationContext(), "?10M", Toast.LENGTH_SHORT).show(); return; } // ? EMMessage message = EMMessage.createSendMessage(EMMessage.Type.FILE); message.setReceipt(toChatUsername); // add message body NormalFileMessageBody body = new NormalFileMessageBody(new File(filePath)); message.addBody(body); conversation.addMessage(message); listView.setAdapter(adapter); adapter.refresh(); listView.setSelection(listView.getCount() - 1); setResult(RESULT_OK); }