List of usage examples for android.net Uri getAuthority
@Nullable public abstract String getAuthority();
From source file:com.just.agentweb.AgentWebUtils.java
private static String getRealPathBelowVersion(Context context, Uri uri) { String filePath = null;//from w w w .j av a2 s . c om LogUtils.i(TAG, "method -> getRealPathBelowVersion " + uri + " path:" + uri.getPath() + " getAuthority:" + uri.getAuthority()); String[] projection = { MediaStore.Images.Media.DATA }; CursorLoader loader = new CursorLoader(context, uri, projection, null, null, null); Cursor cursor = loader.loadInBackground(); if (cursor != null) { cursor.moveToFirst(); filePath = cursor.getString(cursor.getColumnIndex(projection[0])); cursor.close(); } if (filePath == null) { filePath = uri.getPath(); } return filePath; }
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 www . j a v a 2 s . com 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:com.ultramegasoft.flavordex2.util.PhotoUtils.java
/** * Get an image media or file Uri based on its document Uri. * * @param context The Context//from ww w. ja v a2 s . com * @param uri The Uri to convert * @return The image or file Uri or the original Uri if it could not be converted */ @NonNull private static Uri getImageUri(@NonNull Context context, @NonNull Uri uri) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT && DocumentsContract.isDocumentUri(context, uri)) { final String docId = DocumentsContract.getDocumentId(uri); final String[] parts = docId.split(":"); if ("image".equals(parts[0])) { return Uri.withAppendedPath(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, parts[1]); } else if ("com.android.externalstorage.documents".equals(uri.getAuthority())) { return Uri.fromFile(new File(Environment.getExternalStorageDirectory(), parts[1])); } } return uri; }
From source file:com.dwdesign.tweetings.activity.NearbyMapViewerActivity.java
@Override protected void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.map_viewer); final Uri uri = getIntent().getData(); if (uri == null || !AUTHORITY_NEARBY.equals(uri.getAuthority())) { finish();/*w w w .ja v a 2s . co m*/ return; } final Bundle bundle = new Bundle(); mFragment = isNativeMapSupported() ? new NativeNearbyMapFragment() : new WebMapFragment(); mFragment.setArguments(bundle); final FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); ft.replace(R.id.map_frame, mFragment).commit(); }
From source file:org.mariotaku.twidere.activity.MapViewerActivity.java
@Override protected void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.map_viewer); final Uri uri = getIntent().getData(); if (uri == null || !AUTHORITY_MAP.equals(uri.getAuthority())) { finish();/*from ww w. j a v a2s . c o m*/ return; } final Bundle bundle = new Bundle(); final String param_lat = uri.getQueryParameter(QUERY_PARAM_LAT); final String param_lng = uri.getQueryParameter(QUERY_PARAM_LNG); if (param_lat == null || param_lng == null) { finish(); return; } try { bundle.putDouble(INTENT_KEY_LATITUDE, Double.valueOf(param_lat)); bundle.putDouble(INTENT_KEY_LONGITUDE, Double.valueOf(param_lng)); } catch (final NumberFormatException e) { finish(); return; } final Fragment fragment = isNativeMapSupported() ? new NativeMapFragment() : new WebMapFragment(); fragment.setArguments(bundle); final FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); ft.replace(R.id.map_frame, fragment).commit(); }
From source file:de.vanita5.twittnuker.activity.support.MapViewerActivity.java
@Override protected void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); getActionBar().setDisplayHomeAsUpEnabled(true); final Uri uri = getIntent().getData(); if (uri == null || !AUTHORITY_MAP.equals(uri.getAuthority())) { finish();/*from w ww . j a v a 2s .co m*/ return; } final Bundle bundle = new Bundle(); final String param_lat = uri.getQueryParameter(QUERY_PARAM_LAT); final String param_lng = uri.getQueryParameter(QUERY_PARAM_LNG); if (param_lat == null || param_lng == null) { finish(); return; } try { bundle.putDouble(EXTRA_LATITUDE, Double.valueOf(param_lat)); bundle.putDouble(EXTRA_LONGITUDE, Double.valueOf(param_lng)); } catch (final NumberFormatException e) { finish(); return; } final Fragment fragment = isNativeMapSupported() ? new NativeMapFragment() : new WebMapFragment(); fragment.setArguments(bundle); final FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); ft.replace(android.R.id.content, fragment).commit(); }
From source file:org.getlantern.firetweet.activity.support.GoogleMapViewerActivity.java
@Override protected void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); final Uri uri = getIntent().getData(); if (uri == null || !AUTHORITY_MAP.equals(uri.getAuthority())) { finish();//from ww w . jav a 2 s.co m return; } final Bundle bundle = new Bundle(); final double latitude = ParseUtils.parseDouble(uri.getQueryParameter(QUERY_PARAM_LAT), Double.NaN); final double longitude = ParseUtils.parseDouble(uri.getQueryParameter(QUERY_PARAM_LNG), Double.NaN); if (Double.isNaN(latitude) || Double.isNaN(longitude)) { finish(); return; } try { bundle.putDouble(EXTRA_LATITUDE, latitude); bundle.putDouble(EXTRA_LONGITUDE, longitude); } catch (final NumberFormatException e) { finish(); return; } final ActionBar actionBar = getSupportActionBar(); if (actionBar != null) { actionBar.setDisplayHomeAsUpEnabled(true); } final Fragment fragment = isNativeMapSupported() ? new GoogleMapFragment() : new WebMapFragment(); fragment.setArguments(bundle); final FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); ft.replace(android.R.id.content, fragment).commit(); }
From source file:com.dwdesign.tweetings.activity.MapViewerActivity.java
@Override protected void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.map_viewer); final Uri uri = getIntent().getData(); if (uri == null || !AUTHORITY_MAP.equals(uri.getAuthority())) { finish();/*from w ww. j a v a2 s . c o m*/ return; } final Bundle bundle = new Bundle(); final String param_lat = uri.getQueryParameter(QUERY_PARAM_LAT); final String param_lng = uri.getQueryParameter(QUERY_PARAM_LNG); if (param_lat == null || param_lng == null) { finish(); return; } try { bundle.putDouble(INTENT_KEY_LATITUDE, Double.valueOf(param_lat)); bundle.putDouble(INTENT_KEY_LONGITUDE, Double.valueOf(param_lng)); } catch (final NumberFormatException e) { finish(); return; } mFragment = isNativeMapSupported() ? new NativeMapFragment() : new WebMapFragment(); mFragment.setArguments(bundle); final FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); ft.replace(R.id.map_frame, mFragment).commit(); }
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 www. j av a 2 s. c o m // 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:org.getlantern.firetweet.activity.support.OpenStreetMapViewerActivity.java
@Override protected void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); final Uri uri = getIntent().getData(); if (uri == null || !AUTHORITY_MAP.equals(uri.getAuthority())) { finish();/*from w ww . j av a2 s. c om*/ return; } final double latitude = ParseUtils.parseDouble(uri.getQueryParameter(QUERY_PARAM_LAT), Double.NaN); final double longitude = ParseUtils.parseDouble(uri.getQueryParameter(QUERY_PARAM_LNG), Double.NaN); if (Double.isNaN(latitude) || Double.isNaN(longitude)) { finish(); return; } mLatitude = latitude; mLongitude = longitude; final ActionBar actionBar = getSupportActionBar(); if (actionBar != null) { actionBar.setDisplayHomeAsUpEnabled(true); } setContentView(R.layout.activity_osm_viewer); mMapView.setMultiTouchControls(true); mMapView.setBuiltInZoomControls(true); mMapView.setTilesScaledToDpi(true); final List<Overlay> overlays = mMapView.getOverlays(); final GeoPoint gp = new GeoPoint((int) (latitude * 1E6), (int) (longitude * 1E6)); final Drawable d = ResourcesCompat.getDrawable(getResources(), R.drawable.ic_map_marker, null); final Itemization markers = new Itemization(d, mMapView.getResourceProxy()); final OverlayItem overlayitem = new OverlayItem("", "", gp); markers.addOverlay(overlayitem); overlays.add(markers); final IMapController mc = mMapView.getController(); mc.setZoom(12); mc.setCenter(gp); }