List of usage examples for android.net Uri parse
public static Uri parse(String uriString)
From source file:Main.java
public static Uri pathToContentUri(Context context, String imagePath) { Cursor cursor = context.getContentResolver().query(Media.EXTERNAL_CONTENT_URI, new String[] { "_id" }, "_data=? ", new String[] { imagePath }, null); if (cursor != null && cursor.moveToFirst()) { int imageFile1 = cursor.getInt(cursor.getColumnIndex("_id")); Uri values1 = Uri.parse("content://media/external/images/media"); return Uri.withAppendedPath(values1, "" + imageFile1); } else {//from w w w. j av a 2 s. com File imageFile = new File(imagePath); if (imageFile.exists()) { ContentValues values = new ContentValues(); values.put("_data", imagePath); Uri baseUri = Media.EXTERNAL_CONTENT_URI; return context.getContentResolver().insert(baseUri, values); } else { return null; } } }
From source file:Main.java
public static void addImage(final Context context, final String url, final String fileName) { if (!getAppDownloadsDirectory().exists()) { getAppDownloadsDirectory().mkdirs(); }//from ww w.ja v a2 s . com DownloadManager downloadManager = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE); DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url)); request.setAllowedNetworkTypes( DownloadManager.Request.NETWORK_WIFI | DownloadManager.Request.NETWORK_MOBILE) .setAllowedOverRoaming(true).setTitle("Pics-on-Tumblr") .setDescription("Pics-on-Tumblr is saving picture to your device") .setDestinationInExternalPublicDir(DOWNLOADS_DIRECTORY, fileName).setVisibleInDownloadsUi(false) .setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED); downloadManager.enqueue(request); }
From source file:Main.java
/** * Shortcut intent for icon on homescreen. * @param context Context used to create the intent. * @param url Url of the bookmark./*from www . jav a 2 s . c o m*/ * @return Intent for onclick action of the shortcut. */ public static Intent createShortcutIntent(Context context, String url) { Intent shortcutIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); shortcutIntent.putExtra(REUSE_URL_MATCHING_TAB_ELSE_NEW_TAB, true); return shortcutIntent; }
From source file:Main.java
/** * Retrieve an Uri shared preference.//from w ww.j a va 2s. co m * * @param preferenceId the id of the shared preference. * @return the corresponding preference value. */ public static Uri getSharedPreferenceUri(final int preferenceId) { String uriString = getSharedPreferences().getString(applicationContext.getString(preferenceId), null); if (uriString == null) { return null; } else { return Uri.parse(uriString); } }
From source file:Main.java
public static void callPhoneNumber(@NonNull Context context, @NonNull String resource) { //First of all, the number needs to be extracted from the resource String number = ""; for (int i = 0; i < resource.length(); i++) { char digit = resource.charAt(i); if (digit >= '0' && digit <= '9') { number += digit;/*from w ww.j av a 2 s . com*/ } } context.startActivity(new Intent(Intent.ACTION_DIAL, Uri.parse("tel:" + number))); }
From source file:Main.java
/** * A wrapper around {@link Uri#parse} that returns null if the input is null. * * @param uriAsString the uri as a string * @return the parsed Uri or null if the input was null *//*from www . ja va 2 s .co m*/ public static Uri parseUriOrNull(@Nullable String uriAsString) { return uriAsString != null ? Uri.parse(uriAsString) : null; }
From source file:Main.java
public static Uri getAudioContentUri(Context context, File file) { String filePath = file.getAbsolutePath(); Cursor cursor = context.getContentResolver().query(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, new String[] { MediaStore.Audio.Media._ID }, MediaStore.Audio.Media.DATA + "=?", new String[] { filePath }, null); cursor.moveToFirst();/*w ww.j a va2 s. co m*/ int id = cursor.getInt(cursor.getColumnIndex(MediaStore.MediaColumns._ID)); Uri baseUri = Uri.parse("content://media/external/audio/media"); return Uri.withAppendedPath(baseUri, "" + id); }
From source file:Main.java
public static Uri getPhoneAccountSettingUri() { return Uri.parse("https://www.google.com/settings/phone"); }
From source file:Main.java
private static void showAppInMarket(Context context, String desiredPackageName) { String url = ""; try {//from w w w . j a v a 2 s. co m //Check whether Google Play store is installed or not: context.getPackageManager().getPackageInfo("com.android.vending", 0); url = "market://details?id=" + desiredPackageName; } catch (final Exception e) { url = "https://play.google.com/store/apps/details?id=" + desiredPackageName; } //Open the app page in Google Play store: final Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(intent); }
From source file:Main.java
/** * Method to open app//from www . ja va2 s .co m * * @param context */ public static void openApp(Context context, String appPackage) { Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + appPackage)); if (isConnectionAvailable(context) && isIntentAvailable(context, intent)) { // SET THAT REVIEW IS DONE SharedPreferences sharedPreferences = context.getSharedPreferences(REVIEW_DONE, Context.MODE_PRIVATE); Editor edit = sharedPreferences.edit(); edit.putBoolean(REVIEW_DONE, true); edit.commit(); // START REVIEW ACTIVITY context.startActivity(intent); } else { Toast.makeText(context, "Network Error", Toast.LENGTH_LONG).show(); } }