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:org.wso2.mdm.agent.services.Operation.java

/**
 * Retrieve device application information.
 * @param code - Operation code.// w  ww. j a  va  2  s  .c o  m
 */
public void getApplicationList(String code) throws AndroidAgentException {
    ArrayList<DeviceAppInfo> apps = appList.getInstalledApps();

    JSONArray result = new JSONArray();
    int size = apps.size();

    for (int i = 0; i < size; i++) {
        JSONObject app = new JSONObject();
        try {
            app.put(APP_INFO_TAG_NAME, Uri.encode(apps.get(i).getAppname()));
            app.put(APP_INFO_TAG_PACKAGE, apps.get(i).getPackagename());
            app.put(APP_INFO_TAG_ICON, apps.get(i).getIcon());
            result.put(app);
        } catch (JSONException e) {
            throw new AndroidAgentException("Invalid JSON format.", e);
        }
    }

    resultBuilder.build(code, result);
}

From source file:com.albedinsky.android.support.intent.MapIntent.java

/**
 * Appends {@link #mLabel} to the specified <var>uriBuilder</var>.
 * <p>/*from w  w  w  .  java2s. c  om*/
 * <b>Note</b>, that label will be enclosed in "()" bracekts.
 *
 * @param uriBuilder The builder where to append the label value.
 */
private void appendLabel(StringBuilder uriBuilder) {
    uriBuilder.append("(").append(Uri.encode(mLabel)).append(")");
}

From source file:im.delight.android.baselib.Social.java

/**
 * Whether the given person (represented by phone number) is known on the current device (i.e. in the address book) or not
 *
 * @param context the Context reference to get the ContentResolver from
 * @param phoneNumber the phone number to look up
 * @return whether the phone number is in the contacts list (true) or not (false)
 *//*from   ww w. ja  v  a2 s  . c om*/
public static boolean isPersonKnown(Context context, String phoneNumber) {
    try {
        Uri phoneUri = Uri.withAppendedPath(ContactsContract.PhoneLookup.CONTENT_FILTER_URI,
                Uri.encode(phoneNumber));
        Cursor phoneEntries = context.getContentResolver().query(phoneUri,
                new String[] { android.provider.ContactsContract.PhoneLookup.DISPLAY_NAME }, null, null, null);
        return phoneEntries.getCount() > 0;
    } catch (Exception e) {
        return false;
    }
}

From source file:ml.puredark.hviewer.ui.fragments.SettingFragment.java

@Override
public void onSelectDirectory(@NonNull String path) {
    SharedPreferencesUtil.saveData(getActivity(), KEY_PREF_DOWNLOAD_PATH, Uri.encode(path));
    getPreferenceManager().findPreference(KEY_PREF_DOWNLOAD_PATH).setSummary(Uri.decode(path));
    mDialog.dismiss();/*from   w w  w  .  java2 s .  co  m*/
}

From source file:uk.org.freeflight.wifefinder.MainActivity.java

void showMap() {
    // Display labelled marker at aircraft position
    String uri_str = String.format("geo:%f,%f?z=8&q=%f,%f(%s)", aircraftPosition.latitude,
            aircraftPosition.longitude, aircraftPosition.latitude, aircraftPosition.longitude,
            Uri.encode(db.getAircraftReg((id))));
    Uri gmmIntentUri = Uri.parse(uri_str);

    Intent mapIntent = new Intent(Intent.ACTION_VIEW, gmmIntentUri);
    if (mapIntent.resolveActivity(getPackageManager()) != null) {
        startActivity(mapIntent);// ww  w .j  a va  2 s  .  co m
    }
}

From source file:org.tigase.mobile.chat.ChatHistoryFragment.java

@Override
public Loader<Cursor> onCreateLoader(int arg0, Bundle arg1) {
    return new CursorLoader(getActivity().getApplicationContext(),
            Uri.parse(ChatHistoryProvider.CHAT_URI + "/" + Uri.encode(chat.getJid().getBareJid().toString())),
            null, null, null, null);/*w  ww. j  a v a 2  s.  c om*/
}

From source file:at.flack.receiver.SmsReceiver.java

private Integer fetchThumbnailId(Context context, String address) {

    final Uri uri = Uri.withAppendedPath(ContactsContract.CommonDataKinds.Phone.CONTENT_FILTER_URI,
            Uri.encode(address));
    final Cursor cursor = context.getContentResolver().query(uri, PHOTO_ID_PROJECTION, null, null,
            ContactsContract.Contacts.DISPLAY_NAME + " ASC");

    try {/*from  ww  w.jav  a  2 s.co m*/
        Integer thumbnailId = null;
        if (cursor.moveToFirst()) {
            thumbnailId = cursor.getInt(cursor.getColumnIndex(ContactsContract.Contacts.PHOTO_ID));
        }
        return thumbnailId;
    } finally {
        cursor.close();
    }

}

From source file:com.www.avtovokzal.org.MainActivity.java

private void sendPhoneInformationToServer() {
    String version = null;/* w w  w.j  a  v a 2  s .co m*/
    PackageInfo packageInfo = null;

    try {
        packageInfo = getPackageManager().getPackageInfo(getPackageName(), 0);
    } catch (PackageManager.NameNotFoundException e) {
        e.printStackTrace();
    }

    String manufacturer = Uri.encode(Build.MANUFACTURER);
    String model = Uri.encode(Build.MODEL);
    String device = Uri.encode(Build.DEVICE);
    String board = Uri.encode(Build.BOARD);
    String brand = Uri.encode(Build.BRAND);
    String display = Uri.encode(Build.DISPLAY);
    String id = Uri.encode(Build.ID);
    String product = Uri.encode(Build.PRODUCT);
    String release = Uri.encode(Build.VERSION.RELEASE);

    if (packageInfo != null) {
        version = Uri.encode(packageInfo.versionName);
    }

    if (Constants.LOG_ON) {
        Log.v(TAG, "1: " + manufacturer + " 2: " + model + " 3: " + device + " 4: " + board + " 5: " + brand
                + " 6: " + display + " 7: " + id + " 8: " + product + " 9: " + release + " 10: " + version);
    }

    String url = "http://www.avtovokzal.org/php/app/sendPhoneInformation.php?manufacturer=" + manufacturer
            + "&model=" + model + "&device=" + device + "&board=" + board + "&brand=" + brand + "&display="
            + display + "&build_id=" + id + "&product=" + product + "&release_number=" + release + "&version="
            + version;

    if (isOnline()) {
        StringRequest strReq = new StringRequest(Request.Method.GET, url, new Response.Listener<String>() {
            @Override
            public void onResponse(String response) {
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                if (Constants.LOG_ON)
                    VolleyLog.d(TAG, "Error: " + error.getMessage());
            }
        });
        // ? TimeOut, Retry
        strReq.setRetryPolicy(new DefaultRetryPolicy(DefaultRetryPolicy.DEFAULT_TIMEOUT_MS, 3,
                DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
        // ? ?  
        AppController.getInstance().addToRequestQueue(strReq);
    } else {
        callErrorActivity();
    }
}

From source file:org.droid2droid.ui.contacts.AbstractSMSFragment.java

@Override
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
    Uri baseUri;//from w ww  .j  av a2  s . c o  m
    if (mCurFilter != null) {
        baseUri = Uri.withAppendedPath(Contacts.CONTENT_FILTER_URI, Uri.encode(mCurFilter));
    } else {
        baseUri = Contacts.CONTENT_URI;
    }
    // Now create and return a CursorLoader that will take care of
    // creating a Cursor for the data being displayed.
    String select = "((" + Contacts.DISPLAY_NAME + " NOTNULL) AND (" + Contacts.HAS_PHONE_NUMBER + "=1) AND ("
            + Contacts.DISPLAY_NAME + " != '' ))";
    if (D)
        Log.d(TAG_SMS, PREFIX_LOG + "baseURI=" + baseUri);
    if (D)
        Log.d(TAG_SMS, PREFIX_LOG + "select=" + select);
    return new CursorLoader(getActivity(), baseUri, CONTACTS_PROJECTION, select, null,
            Contacts.DISPLAY_NAME + " COLLATE LOCALIZED ASC");
}

From source file:org.openhab.habdroid.ui.OpenHABWidgetArrayAdapter.java

private void processIconImage(RelativeLayout widgetView, OpenHABWidget openHABWidget) {
    // Process widgets icon image
    Integer iconColor = openHABWidget.getIconColor();
    AutoRefreshImageView widgetImage = (AutoRefreshImageView) widgetView.findViewById(R.id.widgetimage);
    // Some of widgets, for example Frame doesnt' have an icon, so...
    if (widgetImage != null) {
        if (openHABWidget.getIcon() != null) {
            // This is needed to escape possible spaces and everything according to rfc2396
            String iconUrl = openHABBaseUrl + "images/" + Uri.encode(openHABWidget.getIcon() + ".png");
            //                Log.d(TAG, "Will try to load icon from " + iconUrl);
            // Now set image URL
            widgetImage.setImageUrl(iconUrl, R.drawable.blank_icon, openHABUsername, openHABPassword);
            if (iconColor != null)
                widgetImage.setColorFilter(iconColor);
            else/*from   w w w.  j a va  2  s.  c om*/
                widgetImage.clearColorFilter();
        }
    }
}