Example usage for android.net Uri encode

List of usage examples for android.net Uri encode

Introduction

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

Prototype

public static String encode(String s) 

Source Link

Document

Encodes characters in the given string as '%'-escaped octets using the UTF-8 scheme.

Usage

From source file:Main.java

public static String encode(String paramString) {
    if (paramString == null)
        return "";
    return Uri.encode(paramString);
}

From source file:Main.java

/**
 * Dial a ussd code//from w w  w  .  j  a v a  2s  .  com
 */
public static void dailNumber(Context context, String telNo) {
    String ussdCode = telNo + Uri.encode("#");
    context.startActivity(new Intent("android.intent.action.CALL", Uri.parse("tel:" + ussdCode)));
}

From source file:Main.java

public static Intent newSendToIntent(String emailAddress, String subject, String contentBody) {
    return new Intent(Intent.ACTION_SENDTO).setData(Uri.parse("mailto:" + Uri.encode(emailAddress) + "?subject="
            + Uri.encode(subject) + "&body=" + Uri.encode(contentBody)));
}

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)));
        }/*from  w ww .j a v  a2 s . c  o m*/
    }
    String uri = builder.toString();
    Intent intent = new Intent(Intent.ACTION_SENDTO, Uri.parse(uri));
    context.startActivity(intent);
}

From source file:Main.java

public static Intent newEmailIntent(String toAddress, String subject, String body, String cc) {
    Intent intent = new Intent(Intent.ACTION_SENDTO);
    intent.setData(Uri.parse("mailto:" + Uri.encode(toAddress) + "?subject=" + Uri.encode(subject) + "&body="
            + Uri.encode(body) + "&cc=" + Uri.encode(cc)));
    return intent;
}

From source file:Main.java

public static int getContactIdFromPhoneNumber(final Context context, final String number) {
    final Uri uri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, Uri.encode(number));
    final String[] projection = { PhoneLookup._ID };
    final Cursor c = context.getContentResolver().query(uri, projection, null, null, null);
    if (c.getCount() > 0) {
        c.moveToFirst();//from w  ww  .  j  a  va 2  s.  co m
        return c.getInt(0);
    } else {
        return -1;
    }
}

From source file:Main.java

/**
 * @param artistName/*from  w  w  w .j  a v  a  2 s .c  om*/
 */
public static void shopFor(Context mContext, String artistName) {
    String str = "https://market.android.com/search?q=%s&c=music&featured=MUSIC_STORE_SEARCH";
    Intent shopIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(String.format(str, Uri.encode(artistName))));
    shopIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    shopIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
    mContext.startActivity(shopIntent);
}

From source file:Main.java

/** -----------------------------------------------------------------------  Google Maps -- */

public static Intent newOpenMapsAtLatLongAndName(String latitude, String longitude, String name) {
    Intent intent = new Intent(Intent.ACTION_VIEW,
            Uri.parse(String.format(Locale.ENGLISH, "geo:%s,%s", latitude, longitude) + "?q="
                    + Uri.encode(latitude + "," + longitude + "(" + name + ")") + "&z=16"));
    intent.setClassName("com.google.android.apps.maps", "com.google.android.maps.MapsActivity");
    return intent;
}

From source file:Main.java

/**
 * Propose user to send an email with pre-filled fields.
 *//*from w  w w. ja va  2  s .c  o m*/
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 Intent getEmailIntent(String toEmailAdr, String subject, String message, File attachmentFile,
        String intentChooserTitle) {
    String uriText = "mailto:" + toEmailAdr + "?subject=" + Uri.encode(subject) + "&body="
            + Uri.encode(message);/*www . ja  v  a  2s.  c om*/
    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);
}