List of usage examples for android.net Uri encode
public static String encode(String s)
From source file:com.appnexus.opensdk.AdRequest.java
String getRequestUrl() { StringBuilder sb;//w ww.j a va2s . co m sb = new StringBuilder(Settings.getSettings().BASE_URL); sb.append("id="); if (placementId != null) { sb.append(Uri.encode(placementId)); } else { sb.append("NO-PLACEMENT-ID"); } if (!isEmpty(hidmd5)) sb.append("&md5udid=").append(Uri.encode(hidmd5)); if (!isEmpty(hidsha1)) sb.append("&sha1udid=").append(Uri.encode(hidsha1)); if (!isEmpty(devMake)) sb.append("&devmake=").append(Uri.encode(devMake)); if (!isEmpty(devModel)) sb.append("&devmodel=").append(Uri.encode(devModel)); if (!isEmpty(carrier)) sb.append("&carrier=").append(Uri.encode(carrier)); sb.append("&appid="); if (!isEmpty(Settings.getSettings().app_id)) { sb.append(Uri.encode(Settings.getSettings().app_id)); } else { sb.append("NO-APP-ID"); } if (firstlaunch) sb.append("&firstlaunch=true"); if (!isEmpty(lat) && !isEmpty(lon)) sb.append("&loc=").append(lat).append(",").append(lon); if (!isEmpty(locDataAge)) sb.append("&loc_age=").append(locDataAge); if (!isEmpty(locDataPrecision)) sb.append("&loc_prec=").append(locDataPrecision); if (Settings.getSettings().test_mode) sb.append("&istest=true"); if (!isEmpty(ua)) sb.append("&ua=").append(Uri.encode(ua)); if (!isEmpty(orientation)) sb.append("&orientation=").append(orientation); if (width > 0 && height > 0) sb.append("&size=").append(width).append("x").append(height); // complicated, don't change if (owner != null) { if (maxHeight > 0 && maxWidth > 0) { if (!(owner instanceof InterstitialAdView) && (width < 0 || height < 0)) { sb.append("&max_size=").append(maxWidth).append("x").append(maxHeight); } else if (owner instanceof InterstitialAdView) { sb.append("&size=").append(maxWidth).append("x").append(maxHeight); } } } if (!isEmpty(allowedSizes)) sb.append("&promo_sizes=").append(allowedSizes); if (!isEmpty(mcc)) sb.append("&mcc=").append(Uri.encode(mcc)); if (!isEmpty(mnc)) sb.append("&mnc=").append(Uri.encode(mnc)); if (!isEmpty(language)) sb.append("&language=").append(Uri.encode(language)); if (!isEmpty(dev_timezone)) sb.append("&devtz=").append(Uri.encode(dev_timezone)); if (!isEmpty(dev_time)) sb.append("&devtime=").append(Uri.encode(dev_time)); if (!isEmpty(connection_type)) sb.append("&connection_type=").append(Uri.encode(connection_type)); if (!isEmpty(nativeBrowser)) sb.append("&native_browser=").append(nativeBrowser); if (!isEmpty(psa)) sb.append("&psa=").append(psa); if (reserve > 0) sb.append("&reserve=").append(reserve); if (!isEmpty(age)) sb.append("&age=").append(Uri.encode(age)); if (!isEmpty(gender)) sb.append("&gender=").append(Uri.encode(gender)); sb.append("&format=json"); sb.append("&st=mobile_app"); sb.append("&sdkver=").append(Uri.encode(Settings.getSettings().sdkVersion)); // add custom parameters if there are any if (customKeywords != null) { for (Pair<String, String> pair : customKeywords) { if (!isEmpty(pair.first) && (pair.second != null)) { sb.append("&").append(pair.first).append("=").append(Uri.encode(pair.second)); } } } return sb.toString(); }
From source file:com.appsimobile.appsihomeplugins.dashclock.phone.SmsExtension.java
private Cursor tryOpenContactsCursorByAddress(String phoneNumber) { try {/*from w ww . ja v a2 s . co m*/ return getContentResolver().query(ContactsContract.PhoneLookup.CONTENT_FILTER_URI.buildUpon() .appendPath(Uri.encode(phoneNumber)).build(), ContactsQuery.PROJECTION, null, null, null); } catch (Exception e) { // Can be called by the content provider (from Google Play crash/ANR console) // java.lang.IllegalArgumentException: URI: content://com.android.contacts/phone_lookup/ LOGW(TAG, "Error looking up contact name", e); return null; } }
From source file:io.github.sdsstudios.ScoreKeeper.Home.java
@Override public boolean onNavigationItemSelected(MenuItem item) { // Handle navigation view item clicks here. int id = item.getItemId(); switch (id) { case R.id.nav_history: if (gameDBAdapter.open().numRows() > 0) { startActivity(historyIntent); } else {/* w w w .j ava 2 s. c o m*/ Toast.makeText(this, R.string.no_games, Toast.LENGTH_SHORT).show(); } break; case R.id.nav_players: Toast.makeText(this, R.string.graph_coming_soon, Toast.LENGTH_SHORT).show(); break; case R.id.nav_settings: startActivity(settingsIntent); break; case R.id.nav_about: startActivity(aboutIntent); break; case R.id.nav_rate_review: Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=io.github.sdsstudios.ScoreKeeper")); startActivity(browserIntent); break; case R.id.nav_email_dev: Intent send = new Intent(Intent.ACTION_SENDTO); String uriText = "mailto:" + Uri.encode("seth.d.schroeder@gmail.com") + "?subject=" + Uri.encode("Feedback for Score Keeper app") + "&body=" + Uri.encode(""); Uri uri = Uri.parse(uriText); send.setData(uri); startActivity(Intent.createChooser(send, "Send mail...")); startActivity(send); break; } DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); drawer.closeDrawer(GravityCompat.START); return true; }
From source file:com.oscarsalguero.dialer.MainActivity.java
/** * Dials a phone number using the ACTION_CALL intent (requires CALL_PHONE permission). *//* ww w .j ava 2s . c om*/ private void callPhone() { try { String phoneNumber = textViewDisplay.getText().toString(); Intent callIntent = new Intent(Intent.ACTION_CALL); callIntent.setData(Uri.parse(URI_PREFIX_TEL + Uri.encode(phoneNumber))); startActivity(callIntent); logPhoneNumber(phoneNumber); } catch (SecurityException e) { Log.e(LOG_TAG, "An exception occurred trying to execute the CALL intent.", e); } }
From source file:at.flack.MainActivity.java
public static String getContactName(Context context, String phoneNumber) { if (phoneNumber == null || phoneNumber.length() == 0) return phoneNumber; ContentResolver cr = context.getContentResolver(); Uri uri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, Uri.encode(phoneNumber)); Cursor cursor = cr.query(uri, new String[] { PhoneLookup.DISPLAY_NAME }, null, null, null); if (cursor == null) { return null; }/*from ww w . ja v a2s . c o m*/ String contactName = null; if (cursor.moveToFirst()) { contactName = cursor.getString(cursor.getColumnIndex(PhoneLookup.DISPLAY_NAME)); } if (cursor != null && !cursor.isClosed()) { cursor.close(); } return contactName; }
From source file:de.unwesen.packrat.api.FeedReader.java
/** * Disabled in production builds./*from www .j av a2 s. c om*/ **/ // private void testPatterns() // { // try { // InputStream is = mContext.getResources().openRawResource(R.raw.patterns); // java.io.BufferedReader br = new java.io.BufferedReader( // new java.io.InputStreamReader(is)); // // int[] types = mContext.getResources().getIntArray(R.array.media_types); // String[] names = mContext.getResources().getStringArray(R.array.media_type_names); // // String strLine = null; // while (null != (strLine = br.readLine())) { // Integer type = sMediaTypes.get(strLine); // if (null == type) { // // This word is a media type keyword, so we'll ignore it. // Log.w(LTAG, String.format("Unrecognized: %s", strLine)); // continue; // } // // String tn = null; // for (int i = 0 ; i < types.length ; ++i) { // if (type == types[i]) { // tn = names[i]; // break; // } // } // // Log.d(LTAG, String.format("%s\t\t\t%s (%d)", strLine, tn, type)); // } // } catch (Exception ex) { // Log.w(LTAG, "Error: " + ex); // } // } public void findBy(int searchType, String searchTerm, Handler handler) { if (null == searchTerm || 0 == searchTerm.length()) { Log.e(LTAG, "Empty search term!"); } if (SEARCH_TYPE_WEB == searchType) { webSearch(searchTerm, handler); return; } // TODO use APIBase's Requester/requestUri, etc. Uri uri = Uri.parse(PRODUCT_BASE_URI + Uri.encode(String.format(SEARCH_MASKS[searchType], searchTerm))); //Log.d(LTAG, "Search URI: " + uri); if (null != mFetcher) { mFetcher.keepRunning = false; mFetcher.interrupt(); } mFetcher = new Fetcher(uri, handler); mFetcher.start(); }
From source file:com.magicmod.mmweather.engine.YahooWeatherProvider.java
@Override public void refreshData(Location location, boolean metricUnits) { mLocation = location;// w w w.ja v a2 s . c o m mMetricUnits = metricUnits; String language = getLanguage(); String params = String.format(Locale.US, "\"%f %f\" and locale=\"%s\"", location.getLatitude(), location.getLongitude(), language); String url = URL_PLACEFINDER + Uri.encode(params); JSONObject results = fetchResults(url); if (results == null) { mWeatherInfo = null; return; } try { JSONObject result = results.getJSONObject("Result"); String woeid = result.getString("woeid"); String city = result.getString("city"); if (city == null) { city = result.getString("neighborhood"); } // The city name in the placefinder result is HTML encoded :-( if (city != null) { city = Html.fromHtml(city).toString(); } Log.d(TAG, "Resolved location " + location + " to " + city + " (" + woeid + ")"); mWeatherInfo = getWeatherInfo(woeid, city, metricUnits); } catch (JSONException e) { Log.e(TAG, "Received malformed placefinder data (location=" + location + ", lang=" + language + ")", e); mWeatherInfo = null; } if (mWeatherDataChangedListener != null) mWeatherDataChangedListener.onDataChanged(); }
From source file:net.exclaimindustries.geohashdroid.services.WikiService.java
@Override protected void serializeToDisk(Intent i, OutputStream os) { // We'll encode one line per object, with the last lines reserved for // the entire message (the only thing of these that can have multiple // lines).//from w w w . j av a 2 s .co m OutputStreamWriter osw = new OutputStreamWriter(os); StringBuilder builder = new StringBuilder(); // Always write out the \n, even if it's null. An empty line will be // deserialized as a null. Yes, even if that'll cause an error later. // The date can come in as a long. Calendar c = (Calendar) i.getParcelableExtra(EXTRA_TIMESTAMP); if (c != null) builder.append(c.getTimeInMillis()); builder.append('\n'); // The location is just two doubles. Split 'em with a colon. Location loc = (Location) i.getParcelableExtra(EXTRA_LOCATION); if (loc != null) builder.append(Double.toString(loc.getLatitude())).append(':') .append(Double.toString(loc.getLongitude())); builder.append('\n'); // The image is just a URI. Easy so far. Uri uri = (Uri) i.getParcelableExtra(EXTRA_IMAGE); if (uri != null) builder.append(uri.toString()); builder.append('\n'); // And now comes Info. It encompasses two doubles (the destination), // a Date (the date of the expedition), and a Graticule (two ints // and two booleans). The Graticule part can be null if this is a // globalhash. Info info = (Info) i.getParcelableExtra(EXTRA_INFO); if (info != null) { builder.append(Double.toString(info.getLatitude())).append(':') .append(Double.toString(info.getLongitude())).append(':') .append(Long.toString(info.getDate().getTime())).append(':'); if (!info.isGlobalHash()) { Graticule g = info.getGraticule(); builder.append(Integer.toString(g.getLatitude())).append(':').append(g.isSouth() ? '1' : '0') .append(':').append(Integer.toString(g.getLongitude())).append(':') .append((g.isWest() ? '1' : '0')); } } builder.append('\n'); // The rest of it is the message. We'll URI-encode it so it comes out // as a single string without line breaks. String message = i.getStringExtra(EXTRA_MESSAGE); if (message != null) builder.append(Uri.encode(message)); // Right... let's write it out. try { osw.write(builder.toString()); } catch (IOException e) { // If we got an exception, we're in deep trouble. Log.e(DEBUG_TAG, "Exception when serializing an Intent!", e); } }
From source file:de.unwesen.packrat.api.FeedReader.java
private void webSearch(String term, final Handler handler) { Uri uri = Uri.parse(String.format(WEB_BASE_URI, WEB_SEARCH_API_KEY, Uri.encode(term))); //Log.d(LTAG, "Search URI: " + uri); requestUri(uri, new Handler(new Handler.Callback() { public boolean handleMessage(Message msg) { if (ERR_SUCCESS == msg.what) { String data = (String) msg.obj; handleWebSearchResults(data, handler); } else { handler.obtainMessage(msg.what).sendToTarget(); }//from w ww .j a v a2s . co m return true; } })); }
From source file:org.fdroid.enigtext.contacts.ContactAccessor.java
/*** * If the code below looks shitty to you, that's because it was taken * directly from the Android source, where shitty code is all you get. *//*from www . ja va 2 s . com*/ public Cursor getCursorForRecipientFilter(CharSequence constraint, ContentResolver mContentResolver) { final String SORT_ORDER = Contacts.TIMES_CONTACTED + " DESC," + Contacts.DISPLAY_NAME + "," + Phone.TYPE; final String[] PROJECTION_PHONE = { Phone._ID, // 0 Phone.CONTACT_ID, // 1 Phone.TYPE, // 2 Phone.NUMBER, // 3 Phone.LABEL, // 4 Phone.DISPLAY_NAME, // 5 }; String phone = ""; String cons = null; if (constraint != null) { cons = constraint.toString(); if (RecipientsAdapter.usefulAsDigits(cons)) { phone = PhoneNumberUtils.convertKeypadLettersToDigits(cons); if (phone.equals(cons)) { phone = ""; } else { phone = phone.trim(); } } } Uri uri = Uri.withAppendedPath(Phone.CONTENT_FILTER_URI, Uri.encode(cons)); String selection = String.format("%s=%s OR %s=%s OR %s=%s", Phone.TYPE, Phone.TYPE_MOBILE, Phone.TYPE, Phone.TYPE_WORK_MOBILE, Phone.TYPE, Phone.TYPE_MMS); Cursor phoneCursor = mContentResolver.query(uri, PROJECTION_PHONE, null, null, SORT_ORDER); if (phone.length() > 0) { ArrayList result = new ArrayList(); result.add(Integer.valueOf(-1)); // ID result.add(Long.valueOf(-1)); // CONTACT_ID result.add(Integer.valueOf(Phone.TYPE_CUSTOM)); // TYPE result.add(phone); // NUMBER /* * The "\u00A0" keeps Phone.getDisplayLabel() from deciding * to display the default label ("Home") next to the transformation * of the letters into numbers. */ result.add("\u00A0"); // LABEL result.add(cons); // NAME ArrayList<ArrayList> wrap = new ArrayList<ArrayList>(); wrap.add(result); ArrayListCursor translated = new ArrayListCursor(PROJECTION_PHONE, wrap); return new MergeCursor(new Cursor[] { translated, phoneCursor }); } else { return phoneCursor; } }