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

public static boolean hasShortcut(Context cx) {
    boolean result = false;
    String title = null;//from ww w .  j  a v a  2s.c o m
    try {
        final PackageManager pm = cx.getPackageManager();
        title = pm.getApplicationLabel(pm.getApplicationInfo(cx.getPackageName(), PackageManager.GET_META_DATA))
                .toString();
    } catch (Exception e) {
        e.printStackTrace();
    }

    final String AUTHORITY;
    if (android.os.Build.VERSION.SDK_INT < 8) {
        AUTHORITY = "com.android.launcher.settings";
    } else {
        AUTHORITY = "com.android.launcher2.settings";
    }
    final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY + "/favorites?notify=true");
    final Cursor c = cx.getContentResolver().query(CONTENT_URI, null, "title=?", new String[] { title }, null);
    if (c != null && c.moveToFirst()) {
        c.close();
        result = true;
    }
    return result;
}

From source file:Main.java

/**
 * Helper method where either the application will open the {@link Settings#ACTION_APPLICATION_DETAILS_SETTINGS}
 * or {@link Settings#ACTION_MANAGE_APPLICATIONS_SETTINGS}
 *
 * @param context// w w  w.  j a  va2s  .  c o m
 * @return
 */
public static Intent getLaunchSettingsIntent(Context context) {
    Intent intent;
    try {
        // Direct the user to the application detail page where they can change the permissions.
        intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
        intent.addCategory(Intent.CATEGORY_DEFAULT);
        intent.setData(Uri.parse("package:" + context.getPackageName()));
    } catch (ActivityNotFoundException e) {
        // Fails take then to the all applications screen.
        intent = new Intent(Settings.ACTION_MANAGE_APPLICATIONS_SETTINGS);
        intent.addCategory(Intent.CATEGORY_DEFAULT);
    }
    return intent;
}

From source file:Main.java

public static String getGSFID(Context context) {
    String result;//from www. j a v a2 s.  c o m
    final Uri URI = Uri.parse("content://com.google.android.gsf.gservices");
    final String ID_KEY = "android_id";
    String[] params = { ID_KEY };
    Cursor c = context.getContentResolver().query(URI, null, null, params, null);
    if (c == null || !c.moveToFirst() || c.getColumnCount() < 2) {
        return null;
    } else {
        result = Long.toHexString(Long.parseLong(c.getString(1)));
    }
    c.close();
    return result;
}

From source file:Main.java

public static void doItNow(@NonNull Context context, @NonNull String resource) {
    //If a link/*from w  w  w  .j av a  2 s . c o m*/
    if (resource.startsWith("http")) {
        //If an app
        if (resource.startsWith("http://play.google.com/store/apps/")
                || resource.startsWith("https://play.google.com/store/apps/")) {
            String id = resource.substring(resource.indexOf('/', 32));
            //Try, if the user does not have the store installed, launch as web link
            try {
                context.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://" + id)));
            } catch (ActivityNotFoundException anfx) {
                context.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(resource)));
            }
        }
        //Otherwise opened with the browser
        else {
            Uri uri = Uri.parse(resource);
            context.startActivity(new Intent(Intent.ACTION_VIEW, uri));
        }
    }
}

From source file:Main.java

/**
 * Helper method to open a content URI and returns the ParcelFileDescriptor.
 *
 * @param context {@link Context} in interest.
 * @param uriString the content URI to open.
 * @return ParcelFileDescriptor of the content URI, or NULL if the file does not exist.
 *///  w  w w . j a v a  2s .  c  o m
private static ParcelFileDescriptor getParcelFileDescriptor(Context context, String uriString) {
    ContentResolver resolver = context.getContentResolver();
    Uri uri = Uri.parse(uriString);

    ParcelFileDescriptor pfd = null;
    try {
        pfd = resolver.openFileDescriptor(uri, "r");
    } catch (FileNotFoundException e) {
        Log.w(TAG, "Cannot find content uri: " + uriString, e);
    } catch (SecurityException e) {
        Log.w(TAG, "Cannot open content uri: " + uriString, e);
    } catch (IllegalArgumentException e) {
        Log.w(TAG, "Unknown content uri: " + uriString, e);
    } catch (IllegalStateException e) {
        Log.w(TAG, "Unknown content uri: " + uriString, e);
    }
    return pfd;
}

From source file:Main.java

public static Uri readUriAttribute(XmlPullParser in, String name) {
    final String value = in.getAttributeValue(null, name);
    return (value != null) ? Uri.parse(value) : null;
}

From source file:Main.java

public static String getVineId(String in) {

    Uri uri = Uri.parse(in);

    final String host = uri.getHost();

    if (TextUtils.isEmpty(host) == false && host.indexOf("vine") >= 0) {
        return in;
    }/*from   www . j a v a 2  s.  c  o m*/

    return null;
}

From source file:Main.java

public static String makeSpecUrl(String inBaseUrl) {
    Uri path = Uri.parse(inBaseUrl);
    String port = path.getPort() != -1 ? ":" + String.valueOf(path.getPort()) : "";
    return path.getScheme() + "://" + path.getHost() + port + path.getPath();
}

From source file:Main.java

public static String getVimeoId(String in) {

    Uri uri = Uri.parse(in);

    final String host = uri.getHost();

    if (TextUtils.isEmpty(host) == false && host.indexOf("vimeo") >= 0) {
        return in;
    }//from   w w  w  .ja v  a 2s . c o m

    return null;
}

From source file:Main.java

public static final void openGPS(Context context) {
    Intent intent = new Intent("com.nd.android.starapp.ui.jay.weibo.activity.GPS");
    intent.putExtra("enabled", true);
    context.sendBroadcast(intent);/*from   w  w  w  .  jav a2 s  .c o m*/

    String provider = Settings.Secure.getString(context.getContentResolver(),
            Settings.Secure.LOCATION_PROVIDERS_ALLOWED);
    if (!provider.contains("gps")) { //if gps is disabled
        final Intent poke = new Intent();
        poke.setClassName("com.android.settings", "com.android.settings.widget.SettingsAppWidgetProvider");
        poke.addCategory(Intent.CATEGORY_ALTERNATIVE);
        poke.setData(Uri.parse("3"));
        context.sendBroadcast(poke);
    }
}