Example usage for android.net Uri getScheme

List of usage examples for android.net Uri getScheme

Introduction

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

Prototype

@Nullable
public abstract String getScheme();

Source Link

Document

Gets the scheme of this URI.

Usage

From source file:Main.java

public static boolean isAssetUri(Uri paramUri) {
    if ((paramUri.getScheme().equals("file")) && (paramUri.getPath().startsWith(ANDROID_ASSET_PREFIX))) {
    }//from   ww  w .j  av  a  2  s .  c  o m
    for (boolean bool = true;; bool = false) {
        return bool;
    }
}

From source file:Main.java

/**
 * @param uri uri to extract scheme from, possibly null
 * @return null if uri is null, result of uri.getScheme() otherwise
 *///www. j a  va  2 s .  c o  m
public static String getSchemeOrNull(Uri uri) {
    return uri == null ? null : uri.getScheme();
}

From source file:Main.java

/**
 * Returns true if the URI is a path to a local file or a reference to a local file.
 *
 * @param uri The uri to test./*from ww w .j  a  v  a  2  s. c o m*/
 */
public static boolean isLocalFileUri(Uri uri) {
    String scheme = uri.getScheme();
    return TextUtils.isEmpty(scheme) || scheme.equals("file");
}

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   ww w  . java  2  s .  c  om
        return idOrUrl;
    }
}

From source file:Main.java

public static Uri LocationToUri(String location) {
    Uri uri = Uri.parse(location);
    if (uri.getScheme() == null)
        throw new IllegalArgumentException("location has no scheme");
    return uri;//from  w ww .java  2 s.com
}

From source file:Main.java

public static String uriToString(Context context, Uri uri) {
    String scheme = uri.getScheme();
    if (scheme != null) {
        if (scheme.equals("http") || scheme.equals("https")) {
            return uri.toString();
        } else if (scheme.equals("content") || scheme.equals("file")) {
            Cursor cursor = context.getContentResolver().query(uri,
                    new String[] { OpenableColumns.DISPLAY_NAME }, null, null, null);
            if (cursor.moveToNext()) {
                String name = cursor.getString(0);
                cursor.close();/*from www .  j  a va  2s . com*/
                return name;
            }
            cursor.close();
            return uri.getPath();
        }
    }
    return uri.toString();
}

From source file:Main.java

public static Uri getValidUri(String s) {
    Uri uri1 = Uri.parse(s);
    Uri uri = uri1;/*from   ww w . j a v a 2  s .com*/
    if (uri1.getScheme() == null) {
        uri = Uri.parse((new StringBuilder("http://")).append(s).toString());
    }
    return uri;
}

From source file:Main.java

static void assertUriSafe(@Nullable Uri uri) {
    if (uri == null || TextUtils.isEmpty(uri.getScheme()) || TextUtils.isEmpty(uri.getHost())) {
        throw new RuntimeException("Unsafe uri provided");
    }/*w w  w .  java2 s .  co m*/
}

From source file:Main.java

private static boolean isValid(Uri uri) {
    return uri != null
            && (uri.getScheme().equalsIgnoreCase("file") || uri.getScheme().equalsIgnoreCase("content"));
}

From source file:Main.java

private static String getFileName(Context context, Uri uri) {
    Log.d("suka", uri.getScheme() + " : " + context.getContentResolver().getType(uri));
    String result = null;//from  ww w. j av  a 2s.c  o m
    if (uri.getScheme().equals("content")) {
        Cursor cursor = context.getContentResolver().query(uri, null, null, null, null);
        try {
            if (cursor != null && cursor.moveToFirst()) {
                result = cursor.getString(cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME));
            }
        } finally {
            cursor.close();
        }
    }
    if (result == null) {
        Log.d("suka", "res " + uri.getPath());
        result = uri.getPath();
        int cut = result.lastIndexOf('/');
        if (cut != -1) {
            result = result.substring(cut + 1);
        }
    }
    return result;
}