Example usage for android.net Uri parse

List of usage examples for android.net Uri parse

Introduction

In this page you can find the example usage for android.net Uri parse.

Prototype

public static Uri parse(String uriString) 

Source Link

Document

Creates a Uri which parses the given encoded URI string.

Usage

From source file:Main.java

@TargetApi(Build.VERSION_CODES.M)
public static List<String> getCustomTabSupportingPackages(Context context) {
    PackageManager pm = context.getPackageManager();
    Intent activityIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.example.com"));
    // Get all apps that can handle VIEW intents.
    List<ResolveInfo> resolvedActivityList = pm.queryIntentActivities(activityIntent, PackageManager.MATCH_ALL);
    List<String> packagesSupportingCustomTabs = new ArrayList<>();
    for (ResolveInfo info : resolvedActivityList) {
        Intent serviceIntent = new Intent();
        serviceIntent.setAction(ACTION_CUSTOM_TABS_CONNECTION);
        serviceIntent.setPackage(info.activityInfo.packageName);
        if (pm.resolveService(serviceIntent, 0) != null) {
            packagesSupportingCustomTabs.add(info.activityInfo.packageName);
        }/*  w w  w .  j a v  a  2  s  .co  m*/
    }
    return packagesSupportingCustomTabs;
}

From source file:Main.java

public static String getYouTubeIdFromIdOrUrl(String idOrUrl) {
    Uri uri = Uri.parse(idOrUrl);
    if (uri.getScheme() != null) {
        return uri.getLastPathSegment();
    } else {/*from w  w w  . java 2  s  .c om*/
        return idOrUrl;
    }
}

From source file:Main.java

/**
 * Method to send review/*from   ww w .j  ava  2  s. c o  m*/
 * 
 * @param context
 */
public static void sendReview(Context context) {
    Intent intent = new Intent(Intent.ACTION_VIEW,
            Uri.parse("market://details?id=" + context.getPackageName()));
    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();
    }
}

From source file:Main.java

public static void shiftTableUriIds(HashMap<String, ArrayList<ContentValues>> operationMap, String tableName,
        String idColumnName, String authority, String path, long topTableId) {
    ArrayList<ContentValues> restoreOperations = operationMap.get(tableName);
    if (null == restoreOperations) {
        return;/*www  . ja va 2 s  . c om*/
    }
    for (ContentValues restoreCv : restoreOperations) {
        if (restoreCv.containsKey(idColumnName) && null != restoreCv.getAsString(idColumnName)) {

            Uri uri = Uri.parse(restoreCv.getAsString(idColumnName));
            if ("content".equalsIgnoreCase(uri.getScheme()) && authority.equals(uri.getAuthority())
                    && uri.getPath().substring(0, uri.getPath().lastIndexOf('/')).equals(path)) {
                Uri.Builder newUri = uri.buildUpon()
                        .path(uri.getPath().substring(0, uri.getPath().lastIndexOf('/')))
                        .appendPath(String.valueOf(
                                Long.parseLong(uri.getPath().substring(uri.getPath().lastIndexOf('/') + 1))
                                        + topTableId));

                //               Log.v("URI", uri.getPath().substring(uri.getPath().lastIndexOf('/')+1));
                //               Log.v("URI", String.valueOf(Long.parseLong(uri.getPath().substring(uri.getPath().lastIndexOf('/')+1)) + topTableId));

                restoreCv.put(idColumnName, newUri.build().toString());
            }
        }
    }
}

From source file:Main.java

public static Uri getAlbumArtUri(long paramInt) {
    return ContentUris.withAppendedId(Uri.parse("content://media/external/audio/albumart"), paramInt);
}

From source file:Main.java

private static Uri getMoreAppsUri(String publisherName) {
    return Uri.parse("market://search?q=pub:" + publisherName);
}

From source file:Main.java

public static byte[] toByteArray(final String uri) {
    try {//from   w ww .  j av  a  2 s  .  c  o m
        if (Uri.parse(uri).getScheme() != null) {
            return toByteArray(new URL(uri).openStream());
        } else {
            return toByteArray(new FileInputStream(uri));
        }
    } catch (Exception e) {
    }
    return null;
}

From source file:Main.java

public static Intent openLink(String url) {
    return new Intent(Intent.ACTION_VIEW, Uri.parse(url));
}

From source file:Main.java

public static Intent openDialer(String number) {
    return new Intent(Intent.ACTION_DIAL, Uri.parse("tel:" + number));
}

From source file:Main.java

private static Uri getCursorUri(Cursor cursor, String column) {
    return Uri.parse(getCursorString(cursor, column));
}