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 Intent getSysAppDetailIntent(Context context) {
    return new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + context.getPackageName()));
}

From source file:Main.java

public static void ShowSoftInfoDialog(final Context context, String title, String msg) {
    AlertDialog alertDialog = new AlertDialog.Builder(context).setIcon(android.R.attr.alertDialogIcon)
            .setTitle(title).setMessage(msg).setPositiveButton("ok", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {

                    /* User clicked OK so do some stuff */
                }// w ww. ja  va2 s. c  om
            }).setNeutralButton("Email", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                    Uri uri = Uri.parse("mailto:atgczcl@163.com");
                    Intent emailIntent = new Intent(Intent.ACTION_SENDTO, uri);
                    context.startActivity(emailIntent);
                    /* User clicked Something so do some stuff */
                }
            }).create();
    alertDialog.show();

}

From source file:Main.java

public static String getInstagramId(String in) {

    Uri uri = Uri.parse(in);

    final String host = uri.getHost();

    if (TextUtils.isEmpty(host) == false && host.indexOf("instagram") >= 0) {
        return in;
    }//from w  w  w  .ja  va2  s  . c om

    return null;
}

From source file:Main.java

public static String encodeQuery(String url) {
    Uri uri = Uri.parse(url);

    try {/*w  w  w  .j  av  a2 s .c  om*/
        String query = uri.getQuery();
        String encodedQuery = query != null ? URLEncoder.encode(query, "UTF-8") : null;
        URI tmp = new URI(uri.getScheme(), uri.getAuthority(), uri.getPath(), null, uri.getFragment());
        return tmp + (encodedQuery != null && encodedQuery.length() > 0 ? "?" + encodedQuery : "");
    } catch (UnsupportedEncodingException ignore) {
    } catch (URISyntaxException ignore) {
    }

    return uri.toString();
}

From source file:Main.java

public static void CallPhone(Context context, String phone) {
    Intent intent = new Intent(Intent.ACTION_DIAL);
    Uri data = Uri.parse("tel:" + phone);
    intent.setData(data);//from   w  w  w  . j  a v a  2  s .c  om
    context.startActivity(intent);
}

From source file:Main.java

public static void downloadFile(Context context, String fileurl) {
    DownloadManager.Request request = new DownloadManager.Request(Uri.parse(fileurl));
    request.setDestinationInExternalPublicDir("/Download/", fileurl.substring(fileurl.lastIndexOf("/") + 1));
    DownloadManager downloadManager = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);
    downloadManager.enqueue(request);/*from ww  w .  j  av  a2 s  . c  o m*/
}

From source file:Main.java

public static void dial(Context ctx, String telephone) {
    try {//w w  w.  ja  v a 2  s .  c om
        if (telephone != null && !telephone.equals("")) {
            Uri uri = Uri.parse("tel:" + telephone);
            Intent intent = new Intent(Intent.ACTION_DIAL, uri);
            ctx.startActivity(intent);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }

}

From source file:Main.java

public static boolean showMap(Context context, String address) {
    Uri addressUri = Uri.parse("geo:0,0?q=" + address);
    Intent searchAddress = new Intent(Intent.ACTION_VIEW, addressUri);

    boolean ret = true;
    try {//from  ww  w  .ja  v  a2 s . com
        context.startActivity(searchAddress);
    } catch (Exception e) {
        ret = false;
    }
    return ret;
}

From source file:Main.java

/**
 * When doing a web search, there are two situations.
 *
 * If user type in a url or something similar to a url, we need to
 * open the url directly for user. Otherwise, we just search the
 * content user type in with default search engine.
 *
 * @param str content user want to search or url user want to visit
 * @return intent/*from  w ww  .  j  ava 2  s . c om*/
 */
public static Intent getWebSearchIntent(String str) {
    Intent intent;
    // if search content contain ".", we think it's a url
    if (str.contains(".")) {
        if (!str.startsWith("http://") && !str.startsWith("https://"))
            str = "http://" + str;
        intent = new Intent(Intent.ACTION_VIEW, Uri.parse(str));
    } else {
        intent = new Intent(Intent.ACTION_WEB_SEARCH);
        intent.putExtra(SearchManager.QUERY, str);
    }
    return intent;
}

From source file:Main.java

/** Parses a string into a URI and returns null if the given string is null. */
public static Uri parseUriOrNull(String uriString) {
    if (uriString == null) {
        return null;
    }// ww  w.  j  a va  2s .  c o  m
    return Uri.parse(uriString);
}