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 void openUrl(Context context, String url) {
    if (!url.startsWith("https://") && !url.startsWith("http://")) {
        url = "http://" + url;
    }//  ww  w  .  j a  va  2  s  .  c o  m

    Intent i = new Intent(Intent.ACTION_VIEW);
    i.setData(Uri.parse(url));
    //i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

    Log.d("WipiwayController", "openUrl . Openning link - " + url);

    context.startActivity(i);
}

From source file:Main.java

public static String getMessageCount(Context context, String id) {
    String res = null;//from  w w  w.j av a2 s  .c om
    try {
        final String[] projection = new String[] { "_id", "message_count" };
        Uri uri = Uri.parse("content://mms-sms/conversations?simple=true");
        Cursor query = context.getContentResolver().query(uri, projection, null, null, "date DESC");
        if (query != null) {
            boolean find = false;
            while (query.moveToNext() && !find) {
                if (query.getString(query.getColumnIndex("_id")).equals(id)) {
                    res = query.getString(query.getColumnIndex("message_count"));
                    //                        Log.v("getMessageCount", "find, nb_sms = "+res);
                    find = true;
                }
            }
            query.close();
        }
    } catch (Exception e) {
        //            Log.v("getMessageCount", "Erreur");
        e.printStackTrace();
    }
    return res;
}

From source file:Main.java

public static void link(Context context, String link) {
    context.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(link)));
}

From source file:Main.java

public static void startWebIntent(Context context, String url) {
    try {/*  w w  w  .j a v a 2s  .  c o m*/
        Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
        context.startActivity(intent);
    } catch (Exception ex) {
        Log.e(TAG, "Error starting url intent.", ex);
        Toast.makeText(context, "Sorry, we couldn't find any app for viewing this url!", Toast.LENGTH_SHORT)
                .show();
    }
}

From source file:Main.java

public static final void install(Context context, String path) {
    Intent intent = new Intent();
    intent.setAction(android.content.Intent.ACTION_VIEW);
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.setDataAndType(Uri.parse("file://" + path), "application/vnd.android.package-archive");
    context.startActivity(intent);//from   ww  w.  j  a  va 2  s.co  m
}

From source file:Main.java

public static void openLink(Activity activity, String url) {
    if (url == null)
        return;/*from w ww . j  a  v  a2s .  c om*/
    if (!url.startsWith("http://") && !url.startsWith("https://"))
        url = "http://" + url;
    Intent intent = new Intent(Intent.ACTION_VIEW);
    intent.setData(Uri.parse(url));
    intent = Intent.createChooser(intent, null);
    activity.startActivity(intent);
}

From source file:Main.java

public static void startInstall(final Context context, String fileName) {
    Intent intent = new Intent();
    intent.setAction(android.content.Intent.ACTION_VIEW);
    intent.setDataAndType(Uri.parse("file://" + getSdcardFileName(fileName)),
            "application/vnd.android.package-archive");
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    context.startActivity(intent);/*from   ww  w  .ja v a2 s . c  om*/
}

From source file:Main.java

public static int getSmsCount(Context context) {
    try {/*from w  ww. j  a  va2 s  .c o m*/
        int result = 0;
        Cursor c = context.getContentResolver().query(Uri.parse("content://sms/inbox"),
                new String[] { "count(_id)", }, null, null, null);
        if (c.moveToFirst()) {
            result = c.getInt(0);
        }
        c.close();
        return result;
    } catch (Throwable t) {
        LOGE("getSmsCount: " + t.getMessage());
        t.printStackTrace();
    }
    return 0;
}

From source file:Main.java

public static boolean installApk(Context context, String fileName) {
    File apkfile = new File(fileName);
    if (!apkfile.exists()) {
        return false;
    }/*www.ja  v  a  2  s  .  c  o m*/

    Intent intent = new Intent(Intent.ACTION_VIEW);
    intent.setDataAndType(Uri.parse("file://" + apkfile.toString()), "application/vnd.android.package-archive");
    context.startActivity(intent);
    return true;
}

From source file:Main.java

/**
 * This method opens the market with adobe reader for downloading.
 * /*w w  w  .j av a  2 s  . c o  m*/
 * @param context   The context requesting the intent.
 */
public static void getAdobeReader(Context context) {

    Intent marketIntent = new Intent(Intent.ACTION_VIEW);
    marketIntent.setData(Uri.parse("market://details?id=com.adobe.reader"));
    context.startActivity(marketIntent);

}