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

/**
 * install app/*w  w w.  j  a v a2  s  .  c  om*/
 * 
 * @param context
 * @param filePath
 * @return whether apk exist
 */
public static boolean install(Context context, String filePath) {
    Intent i = new Intent(Intent.ACTION_VIEW);
    File file = new File(filePath);
    if (file != null && file.length() > 0 && file.exists() && file.isFile()) {
        i.setDataAndType(Uri.parse("file://" + filePath), "application/vnd.android.package-archive");
        i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(i);
        return true;
    }
    return false;
}

From source file:Main.java

public static Uri writeToTempImageAndGetPathUri(Context inContext, Bitmap inImage) {
    ByteArrayOutputStream bytes = new ByteArrayOutputStream();
    inImage.compress(Bitmap.CompressFormat.JPEG, 100, bytes);
    String path = MediaStore.Images.Media.insertImage(inContext.getContentResolver(), inImage, "Title", null);
    return Uri.parse(path);
}

From source file:Main.java

/**
 * Returns a title suitable for display for a link. If |title| is non-empty, this simply returns
 * it. Otherwise, returns a shortened form of the URL.
 *//*from  ww w .j av  a2s . c o  m*/
static String getTitleForDisplay(@Nullable String title, @Nullable String url) {
    if (!TextUtils.isEmpty(title) || TextUtils.isEmpty(url)) {
        return title;
    }

    Uri uri = Uri.parse(url);
    String host = uri.getHost();
    if (host == null)
        host = "";
    String path = uri.getPath();
    if (path == null || path.equals("/"))
        path = "";
    title = host + path;
    return title;
}

From source file:Main.java

public static String e(Context context) {
    if (c == null) {
        StringBuilder stringbuilder = new StringBuilder();
        PackageManager packagemanager = context.getPackageManager();
        List list = packagemanager.queryIntentActivities(
                new Intent("android.intent.action.VIEW", Uri.parse("geo:0,0?q=donuts")), 0x10000);
        if (list == null || list.size() == 0)
            stringbuilder.append("m");
        List list1 = packagemanager.queryIntentActivities(
                new Intent("android.intent.action.VIEW", Uri.parse("market://search?q=pname:com.google")),
                0x10000);// w ww . j ava2 s. c  o m
        if (list1 == null || list1.size() == 0) {
            if (stringbuilder.length() > 0)
                stringbuilder.append(",");
            stringbuilder.append("a");
        }
        List list2 = packagemanager.queryIntentActivities(
                new Intent("android.intent.action.VIEW", Uri.parse("tel://6509313940")), 0x10000);
        if (list2 == null || list2.size() == 0) {
            if (stringbuilder.length() > 0)
                stringbuilder.append(",");
            stringbuilder.append("t");
        }
        c = stringbuilder.toString();
    }
    return c;
}

From source file:Main.java

/**
 * Propose user to send an email with pre-filled fields.
 *//*from   w  w w . j  a  va2 s .  com*/
public static void sendEMail(final Context context, final String dialogTitle, final String to,
        final String subject, final String body) {
    final Intent send = new Intent(Intent.ACTION_SENDTO);
    final String uriText = "mailto:" + Uri.encode(to) + "?subject=" + Uri.encode(subject) + "&body="
            + Uri.encode(body);
    send.setData(Uri.parse(uriText));
    context.startActivity(Intent.createChooser(send, dialogTitle));
}

From source file:Main.java

public static final void openGPS(Context context) {
    try {//from   w w w.  ja va 2 s . c o m
        if (!isOpenGPS(context)) {
            Intent GPSIntent = new Intent();
            GPSIntent.setClassName("com.android.settings",
                    "com.android.settings.widget.SettingsAppWidgetProvider");
            GPSIntent.addCategory("android.intent.category.ALTERNATIVE");
            GPSIntent.setData(Uri.parse("custom:3"));
            PendingIntent.getBroadcast(context, 0, GPSIntent, 0).send();
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:Main.java

/**
 * Get bitmap from a URI./*from  ww  w . j a  v  a  2 s  .c om*/
 *
 * @param context The context.
 * @param uriString The URI as a string.
 *
 * @return The bitmap.
 */
public static Bitmap getBitmapFromUri(final Context context, String uriString) {
    Bitmap bitmap = null;
    if (uriString == null) {
        return null;
    }

    Uri uri = Uri.parse(uriString);
    if (uri != null) {
        try {
            bitmap = MediaStore.Images.Media.getBitmap(context.getContentResolver(), uri);
            if (bitmap != null) {
                // We use default density for all bitmaps to avoid scaling.
                bitmap.setDensity(DisplayMetrics.DENSITY_DEFAULT);
            }
        } catch (IOException e) {

        }
    }
    return bitmap;
}

From source file:Main.java

public static void sendFeedback(Context context, String to, String subject, String body) {
    StringBuilder builder = new StringBuilder("mailto:" + Uri.encode(to));
    if (subject != null) {
        builder.append("?subject=" + Uri.encode(Uri.encode(subject)));
        if (body != null) {
            builder.append("&body=" + Uri.encode(Uri.encode(body)));
        }/*w  w w.  j a v a2s .c om*/
    }
    String uri = builder.toString();
    Intent intent = new Intent(Intent.ACTION_SENDTO, Uri.parse(uri));
    context.startActivity(intent);
}

From source file:Main.java

/**
 * Starts Google Play application for this application.
 * @param context/*from  w w w  .java 2 s  .c om*/
 */
public static void startGooglePlay(Context context) {
    final String appPackageName = context.getPackageName();// context.getPackageName();
    // //
    // getPackageName()
    // from Context
    // or Activity
    // object
    try {
        context.startActivity(
                new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + appPackageName)));
    } catch (android.content.ActivityNotFoundException anfe) {
        context.startActivity(new Intent(Intent.ACTION_VIEW,
                Uri.parse("http://play.google.com/store/apps/details?id=" + appPackageName)));
    }
}

From source file:Main.java

public static Intent getEmailIntent(String toEmailAdr, String subject, String message, File attachmentFile,
        String intentChooserTitle) {
    String uriText = "mailto:" + toEmailAdr + "?subject=" + Uri.encode(subject) + "&body="
            + Uri.encode(message);/*from   w w  w  . ja v  a  2  s .com*/
    Uri uri = Uri.parse(uriText);

    Intent sendIntent = new Intent(Intent.ACTION_SENDTO);
    sendIntent.setData(uri);
    if (attachmentFile != null)
        sendIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(attachmentFile));
    return Intent.createChooser(sendIntent, intentChooserTitle);
}