List of usage examples for android.net Uri getScheme
@Nullable public abstract String getScheme();
From source file:com.applozic.mobicommons.file.FileUtils.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.<br> * <br>//from ww w . j av a 2 s . c om * Callers should check whether the path is local before assuming it * represents a local file. * * @param context The context. * @param uri The Uri to query. * @author paulburke * @see #isLocal(String) * @see #getFile(android.content.Context, android.net.Uri) */ public static String getPath(final Context context, final Uri uri) { if (DEBUG) Log.d(TAG + " File -", "Authority: " + uri.getAuthority() + ", Fragment: " + uri.getFragment() + ", Port: " + uri.getPort() + ", Query: " + uri.getQuery() + ", Scheme: " + uri.getScheme() + ", Host: " + uri.getHost() + ", Segments: " + uri.getPathSegments().toString()); final boolean isKitKat = Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT; // DocumentProvider if (isKitKat && DocumentsContract.isDocumentUri(context, uri)) { // LocalStorageProvider if (isLocalStorageDocument(uri)) { // The path is the id return DocumentsContract.getDocumentId(uri); } // ExternalStorageProvider else 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 the remote address if (isGooglePhotosUri(uri)) return uri.getLastPathSegment(); return getDataColumn(context, uri, null, null); } // File else if ("file".equalsIgnoreCase(uri.getScheme())) { return uri.getPath(); } return null; }
From source file:Main.java
/** * Get the real file path from URI registered in media store * @param contentUri URI registered in media store *///from w w w.j a v a2 s . c o m @SuppressWarnings("deprecation") public static String getRealPathFromURI(Activity activity, Uri contentUri) { String releaseNumber = Build.VERSION.RELEASE; if (releaseNumber != null) { /* ICS, JB Version */ if (releaseNumber.length() > 0 && releaseNumber.charAt(0) == '4') { // URI from Gallery(MediaStore) String[] proj = { MediaStore.Images.Media.DATA }; String strFileName = ""; CursorLoader cursorLoader = new CursorLoader(activity, contentUri, proj, null, null, null); Cursor cursor = cursorLoader.loadInBackground(); if (cursor != null) { int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); cursor.moveToFirst(); if (cursor.getCount() > 0) strFileName = cursor.getString(column_index); cursor.close(); } // URI from Others(Dropbox, etc.) if (strFileName == null || strFileName.isEmpty()) { if (contentUri.getScheme().compareTo("file") == 0) strFileName = contentUri.getPath(); } return strFileName; } /* GB Version */ else if (releaseNumber.startsWith("2.3")) { // URI from Gallery(MediaStore) String[] proj = { MediaStore.Images.Media.DATA }; String strFileName = ""; Cursor cursor = activity.managedQuery(contentUri, proj, null, null, null); if (cursor != null) { int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); cursor.moveToFirst(); if (cursor.getCount() > 0) strFileName = cursor.getString(column_index); cursor.close(); } // URI from Others(Dropbox, etc.) if (strFileName == null || strFileName.isEmpty()) { if (contentUri.getScheme().compareTo("file") == 0) strFileName = contentUri.getPath(); } return strFileName; } } //--------------------- // Undefined Version //--------------------- /* GB, ICS Common */ String[] proj = { MediaStore.Images.Media.DATA }; String strFileName = ""; Cursor cursor = activity.managedQuery(contentUri, proj, null, null, null); if (cursor != null) { int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); // Use the Cursor manager in ICS activity.startManagingCursor(cursor); cursor.moveToFirst(); if (cursor.getCount() > 0) strFileName = cursor.getString(column_index); //cursor.close(); // If the cursor close use , This application is terminated .(In ICS Version) activity.stopManagingCursor(cursor); } return strFileName; }
From source file:edu.stanford.mobisocial.dungbeetle.feed.objects.LinkObj.java
private boolean fileAvailable(String mimeType, Uri uri) { if (uri != null && uri.getScheme().startsWith("http")) { return true; }// w w w .j a v a 2s. com Log.d(TAG, "TODO: Content corral for " + uri); return false; }
From source file:me.xingrz.prox.tcp.TcpProxySession.java
public void setDestination(Uri proxy) { if (proxy.getScheme().equals(AutoConfigManager.PROXY_TYPE_HTTP)) { outgoingTunnel.setProxy(/* w ww.j a v a2 s.c o m*/ new HttpConnectHandler(outgoingTunnel, getRemoteAddress().getHostAddress(), getRemotePort())); logger.v("Use HTTP proxy %s:%d", proxy.getHost(), proxy.getPort()); destination = new InetSocketAddress(proxy.getHost(), proxy.getPort()); } else { logger.v("Unsupported proxy scheme %s, ignored", proxy.getScheme()); } }
From source file:com.xabber.android.data.account.WLMManager.java
@Override public boolean isValidUri(Uri uri) { return WLM_SCHEME.equals(uri.getScheme()) && WLM_AUTHORITY.equals(uri.getAuthority()) && WLM_REDIRECT_PATH.equals(uri.getPath()); }
From source file:dev.ukanth.ufirewall.broadcast.PackageBroadcast.java
@Override public void onReceive(Context context, Intent intent) { Uri inputUri = Uri.parse(intent.getDataString()); if (!inputUri.getScheme().equals("package")) { Log.d("AFWall+", "Intent scheme was not 'package'"); return;//w w w. j a v a2s .c o m } if (Intent.ACTION_PACKAGE_REMOVED.equals(intent.getAction())) { // Ignore application updates final boolean replacing = intent.getBooleanExtra(Intent.EXTRA_REPLACING, false); if (!replacing) { // Update the Firewall if necessary final int uid = intent.getIntExtra(Intent.EXTRA_UID, -123); Api.applicationRemoved(context, uid); Api.removeCacheLabel(intent.getData().getSchemeSpecificPart(), context); // Force app list reload next time Api.applications = null; } } else if (Intent.ACTION_PACKAGE_ADDED.equals(intent.getAction())) { final boolean updateApp = intent.getBooleanExtra(Intent.EXTRA_REPLACING, false); if (updateApp) { // dont do anything //1 check the package already added in firewall } else { // Force app list reload next time Api.applications = null; SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); boolean isNotify = prefs.getBoolean("notifyAppInstall", false); if (isNotify && Api.isEnabled(context)) { String added_package = intent.getData().getSchemeSpecificPart(); final PackageManager pkgmanager = context.getPackageManager(); String label = null; try { label = pkgmanager.getApplicationLabel(pkgmanager.getApplicationInfo(added_package, 0)) .toString(); } catch (NameNotFoundException e) { } if (PackageManager.PERMISSION_GRANTED == pkgmanager .checkPermission(Manifest.permission.INTERNET, added_package)) { notifyApp(context, intent, label); } } } } }
From source file:dev.ukanth.ufirewall.PackageBroadcast.java
@Override public void onReceive(Context context, Intent intent) { Uri inputUri = Uri.parse(intent.getDataString()); if (!inputUri.getScheme().equals("package")) { Log.d("AFWall+", "Intent scheme was not 'package'"); return;/*ww w . j a v a 2s . co m*/ } if (Intent.ACTION_PACKAGE_REMOVED.equals(intent.getAction())) { // Ignore application updates final boolean replacing = intent.getBooleanExtra(Intent.EXTRA_REPLACING, false); if (!replacing) { // Update the Firewall if necessary final int uid = intent.getIntExtra(Intent.EXTRA_UID, -123); Api.applicationRemoved(context, uid); /*Api.applicationRemoved(context, inputUri.getSchemeSpecificPart());*/ // Force app list reload next time Api.applications = null; } } else if (Intent.ACTION_PACKAGE_ADDED.equals(intent.getAction())) { final boolean updateApp = intent.getBooleanExtra(Intent.EXTRA_REPLACING, false); if (updateApp) { // dont do anything //1 check the package already added in firewall } else { // Force app list reload next time Api.applications = null; SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); boolean isNotify = prefs.getBoolean("notifyAppInstall", false); if (isNotify && Api.isEnabled(context)) { String added_package = intent.getData().getSchemeSpecificPart(); if (PackageManager.PERMISSION_GRANTED == context.getPackageManager() .checkPermission(Manifest.permission.INTERNET, added_package)) { notifyApp(context, intent, added_package); } } } } }
From source file:com.scm.reader.resultPage.webview.ShortcutWebViewClient.java
public boolean shouldOverrideUrlLoading(WebView view, Uri uri) { if ("copy".equals(uri.getScheme())) { overrideCopy(view.getUrl());/* w ww.java 2s. c om*/ return true; } else if ("sms".equals(uri.getScheme())) { overrideSMS(uri.getQuery()); return true; } else if ("mailto".equals(uri.getScheme())) { overrideEmail(uri); return true; } else if ("tel".equals(uri.getScheme())) { overrideTel(uri); return true; } return false; }
From source file:com.geekandroid.sdk.sample.crop.ResultActivity.java
private void saveCroppedImage() { if (ActivityCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { requestPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE, getString(R.string.permission_write_storage_rationale), REQUEST_STORAGE_WRITE_ACCESS_PERMISSION); } else {/* w w w . ja v a 2 s .c o m*/ Uri imageUri = getIntent().getData(); if (imageUri != null && imageUri.getScheme().equals("file")) { try { copyFileToDownloads(getIntent().getData()); } catch (Exception e) { Toast.makeText(ResultActivity.this, e.getMessage(), Toast.LENGTH_SHORT).show(); Log.e(TAG, imageUri.toString(), e); } } else { Toast.makeText(ResultActivity.this, getString(R.string.toast_unexpected_error), Toast.LENGTH_SHORT) .show(); } } }
From source file:com.just.agentweb.AgentWebUtils.java
@TargetApi(19) static String getFileAbsolutePath(Activity context, Uri fileUri) { if (context == null || fileUri == null) { return null; }//from w w w. j ava 2 s .c o 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; }