List of usage examples for android.net Uri encode
public static String encode(String s)
From source file:com.windigo.RestApiMethodMetadata.java
/** * Replace placeholders with actual parameter values * * @param path/*from ww w. j a va 2s . co m*/ * @param pathParams * @param args * @return {@link String} */ public String parsePlaceholderParams(String path, Map<Integer, String> pathParams, Object[] args) throws IllegalArgumentException { for (Map.Entry<Integer, String> placeholder : placeholderParms.entrySet()) { Object paramVal = args[placeholder.getKey()]; if (paramVal == null) { throw new IllegalArgumentException( String.format("Null parameters are not allowed for : [%s]", placeholder.getValue())); } String value = Uri.encode(paramVal.toString()); path = path.replaceAll("\\{(" + placeholder.getValue() + ")\\}", value); } return path; }
From source file:com.gsma.rcs.ri.utils.RcsContactUtil.java
/** * Gets the photo of a contact, or null if no photo is present * /* ww w .j a v a 2 s . co m*/ * @param contact the contact ID * @return an Bitmap of the photo, or null if no photo is present */ public Bitmap getPhotoFromContactId(ContactId contact) { /* First try to get it from cache */ Bitmap photo = mPhotoContactCache.get(contact); if (photo != null) { return photo; } Uri contactUri = Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_FILTER_URI, Uri.encode(contact.toString())); Cursor cursor = null; try { cursor = mResolver.query(contactUri, PROJ_CONTACT_ID, null, null, null); if (cursor == null) { throw new SQLException("Cannot query photo for contact=" + contact); } if (!cursor.moveToFirst()) { return null; } long contactId = cursor.getLong(cursor.getColumnIndexOrThrow(ContactsContract.PhoneLookup._ID)); InputStream photoInputStream = ContactsContract.Contacts.openContactPhotoInputStream(mResolver, ContentUris.withAppendedId(ContactsContract.Contacts.CONTENT_URI, contactId)); if (photoInputStream != null) { photo = BitmapFactory.decodeStream(photoInputStream); /* Insert in cache */ mPhotoContactCache.put(contact, photo); return photo; } return null; } finally { if (cursor != null) { cursor.close(); } } }
From source file:com.visva.voicerecorder.utils.Utils.java
public static Uri getPhotoUriFromPhoneNumber(ContentResolver resolver, String phoneNo) { Uri result = null;//from w ww . j a va 2 s . c o m if (phoneNo == "" || "null".equals(phoneNo)) { phoneNo = "111111111"; } String[] projection = null; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { projection = new String[] { ContactsContract.Contacts._ID, ContactsContract.PhoneLookup.DISPLAY_NAME, ContactsContract.PhoneLookup.NUMBER, ContactsContract.Contacts.PHOTO_THUMBNAIL_URI, ContactsContract.PhoneLookup.PHOTO_URI, ContactsContract.PhoneLookup.LOOKUP_KEY }; } else { projection = new String[] { ContactsContract.Contacts._ID, ContactsContract.PhoneLookup.DISPLAY_NAME, ContactsContract.PhoneLookup.NUMBER, ContactsContract.PhoneLookup.PHOTO_URI, ContactsContract.PhoneLookup.LOOKUP_KEY }; } Uri lookupUri = Uri.withAppendedPath(ContactsContract.PhoneLookup.CONTENT_FILTER_URI, Uri.encode(phoneNo)); Cursor cursor = resolver.query(lookupUri, projection, null, null, null); if (cursor == null) return null; if (cursor.moveToFirst()) { if (cursor.getString(3) != null) result = Uri.parse(cursor.getString(3)); else if (cursor.getString(4) != null) result = Uri.parse(cursor.getString(4)); } if (cursor != null) { cursor.close(); cursor = null; } return result; }
From source file:com.epic.framework.implementation.tapjoy.TapjoyURLConnection.java
/** * Performs a network request call using HTTP POST to the specified URL and parameters. * /* w ww . j av a 2 s . c om*/ * @param url The URL to connect to. * @param params POST parameters in key/value format. * @param paramsData Any additional POST parameters in key/value format. * @return Response from the server. */ public String connectToURLwithPOST(String url, Hashtable<String, String> params, Hashtable<String, String> paramsData) { String httpResponse = null; try { String requestURL = url; // Replaces all spaces. requestURL = requestURL.replaceAll(" ", "%20"); TapjoyLog.i(TAPJOY_URL_CONNECTION, "baseURL: " + url); TapjoyLog.i(TAPJOY_URL_CONNECTION, "requestURL: " + requestURL); HttpPost httpPost = new HttpPost(requestURL); List<NameValuePair> pairs = new ArrayList<NameValuePair>(); Set<Entry<String, String>> entries = params.entrySet(); Iterator<Entry<String, String>> iterator = entries.iterator(); while (iterator.hasNext()) { Entry<String, String> item = iterator.next(); pairs.add(new BasicNameValuePair(item.getKey(), item.getValue())); TapjoyLog.i(TAPJOY_URL_CONNECTION, "key: " + item.getKey() + ", value: " + Uri.encode(item.getValue())); } if (paramsData != null && paramsData.size() > 0) { entries = paramsData.entrySet(); iterator = entries.iterator(); while (iterator.hasNext()) { Entry<String, String> item = iterator.next(); pairs.add(new BasicNameValuePair("data[" + item.getKey() + "]", item.getValue())); TapjoyLog.i(TAPJOY_URL_CONNECTION, "key: " + item.getKey() + ", value: " + Uri.encode(item.getValue())); } } httpPost.setEntity(new UrlEncodedFormEntity(pairs)); TapjoyLog.i(TAPJOY_URL_CONNECTION, "HTTP POST: " + httpPost.toString()); // Create a HttpParams object so we can set our timeout times. HttpParams httpParameters = new BasicHttpParams(); // Time to wait to establish initial connection. HttpConnectionParams.setConnectionTimeout(httpParameters, 15000); // Time to wait for incoming data. HttpConnectionParams.setSoTimeout(httpParameters, 30000); // Create a http client with out timeout settings. HttpClient client = new DefaultHttpClient(httpParameters); HttpResponse response = client.execute(httpPost); HttpEntity entity = response.getEntity(); httpResponse = EntityUtils.toString(entity); TapjoyLog.i(TAPJOY_URL_CONNECTION, "--------------------"); TapjoyLog.i(TAPJOY_URL_CONNECTION, "response status: " + response.getStatusLine().getStatusCode()); TapjoyLog.i(TAPJOY_URL_CONNECTION, "response size: " + httpResponse.length()); TapjoyLog.i(TAPJOY_URL_CONNECTION, "response: "); TapjoyLog.i(TAPJOY_URL_CONNECTION, "" + httpResponse); TapjoyLog.i(TAPJOY_URL_CONNECTION, "--------------------"); } catch (Exception e) { TapjoyLog.e(TAPJOY_URL_CONNECTION, "Exception: " + e.toString()); } return httpResponse; }
From source file:org.easyaccess.phonedialer.CallStateService.java
/** * Plays the ringtone associated with the number passed as a parameter. * //from w w w . j a va2 s. c o m * @param number * The number associated with the incoming call. */ void playRingtone(String number) { Uri queryUri = Uri.withAppendedPath(ContactsContract.PhoneLookup.CONTENT_FILTER_URI, Uri.encode(number)); String[] columns = new String[] { ContactsContract.Contacts.CUSTOM_RINGTONE }; Cursor contactsCursor = getContentResolver().query(queryUri, columns, null, null, null); if (contactsCursor.moveToFirst()) { if (contactsCursor .getString(contactsCursor.getColumnIndex(ContactsContract.Contacts.CUSTOM_RINGTONE)) == null) { // no custom ringtone has been set Utils.ringtone = RingtoneManager.getRingtone(getBaseContext(), Settings.System.DEFAULT_RINGTONE_URI); Utils.ringtone.play(); } else { Utils.ringtone = RingtoneManager.getRingtone(getBaseContext(), Uri.parse(contactsCursor .getString(contactsCursor.getColumnIndex(ContactsContract.Contacts.CUSTOM_RINGTONE)))); Utils.ringtone.play(); } } }
From source file:org.tigase.mobile.chat.ChatHistoryFragment.java
private Cursor getChatEntry(long id) { Cursor cursor = getActivity().getApplicationContext().getContentResolver().query(Uri.parse( ChatHistoryProvider.CHAT_URI + "/" + Uri.encode(chat.getJid().getBareJid().toString()) + "/" + id), null, null, null, null);// ww w .j a va 2 s . co m cursor.moveToNext(); return cursor; }
From source file:com.timtory.wmgallery.picasa.PicasaApi.java
public int getAlbums(AccountManager accountManager, SyncResult syncResult, UserEntry user, GDataParser.EntryHandler handler) { // Construct the query URL for user albums. String baseUrl = Settings.Secure.getString(mContentResolver, SETTINGS_PICASA_GDATA_BASE_URL_KEY); StringBuilder builder = new StringBuilder(baseUrl != null ? baseUrl : DEFAULT_BASE_URL); builder.append("user/"); builder.append(Uri.encode(mAuth.user)); builder.append(BASE_QUERY_STRING);/*w ww .ja v a 2s .c o m*/ builder.append("&kind=album"); try { // Send the request. synchronized (mOperation) { GDataClient.Operation operation = mOperation; operation.inOutEtag = user.albumsEtag; boolean retry = false; int numRetries = 1; do { retry = false; synchronized (mClient) { mClient.get(builder.toString(), operation); } switch (operation.outStatus) { case HttpStatus.SC_OK: break; case HttpStatus.SC_NOT_MODIFIED: return RESULT_NOT_MODIFIED; case HttpStatus.SC_FORBIDDEN: case HttpStatus.SC_UNAUTHORIZED: if (!retry) { accountManager.invalidateAuthToken(PicasaService.ACCOUNT_TYPE, mAuth.authToken); retry = true; } if (numRetries == 0) { ++syncResult.stats.numAuthExceptions; } default: Log.i(TAG, "getAlbums uri " + builder.toString()); Log.e(TAG, "getAlbums: unexpected status code " + operation.outStatus + " data: " + operation.outBody.toString()); ++syncResult.stats.numIoExceptions; return RESULT_ERROR; } --numRetries; } while (retry && numRetries >= 0); // Store the new ETag for the user/albums feed. user.albumsEtag = operation.inOutEtag; // Parse the response. synchronized (mParser) { GDataParser parser = mParser; parser.setEntry(mAlbumInstance); parser.setHandler(handler); try { Xml.parse(operation.outBody, Xml.Encoding.UTF_8, parser); } catch (SocketException e) { Log.e(TAG, "getAlbumPhotos: " + e); ++syncResult.stats.numIoExceptions; e.printStackTrace(); return RESULT_ERROR; } } } return RESULT_OK; } catch (IOException e) { Log.e(TAG, "getAlbums: " + e); ++syncResult.stats.numIoExceptions; } catch (SAXException e) { Log.e(TAG, "getAlbums: " + e); ++syncResult.stats.numParseExceptions; } return RESULT_ERROR; }
From source file:com.tapjoy.TapjoyConnectCore.java
/** * Constructs the generic URL parameters. * Does NOT include://from www. ja va 2s . c o m * publisher_user_id (publisher user ID) * referrer (for referral tracking) * verifier/timestamp * @return Generic URL parameters used in the connect call. */ public static String getGenericURLParams() { String urlParams = ""; urlParams += TapjoyConstants.TJC_APP_ID_NAME + "=" + Uri.encode(appID) + "&"; urlParams += getParamsWithoutAppID(); return urlParams; }
From source file:group.pals.android.lib.ui.filechooser.utils.ui.history.HistoryFragment.java
@Override public Loader<Cursor> onCreateLoader(int id, Bundle args) { if (BuildConfig.DEBUG) Log.d(_ClassName, "onCreateLoader()"); enableControls(false);//from w w w. j a va 2 s . c om String selection = null; if (!TextUtils.isEmpty(mHistoryCursorAdapter.getSearchText())) { selection = DbUtils.rawSqlEscapeString(Uri.encode(mHistoryCursorAdapter.getSearchText().toString())); selection = String.format("%s LIKE '%%://%%%s%%'", History._ColumnUri, selection); } if (id == mLoaderIdHistoryData) { mHandler.removeCallbacksAndMessages(null); mHandler.postDelayed(mViewLoadingShower, DisplayPrefs._DelayTimeForSimpleAnimation); mHistoryCursorAdapter.changeCursor(null); /* * Offset. */ if (mCurrentPage >= mPageCount) mCurrentPage = mPageCount - 1; if (mCurrentPage < 0) mCurrentPage = 0; int offset = mCurrentPage * mMaxItemsPerPage; return new CursorLoader(getActivity(), History._ContentUri, null, selection, null, String.format( "%s DESC LIMIT %s OFFSET %s", History._ColumnModificationTime, mMaxItemsPerPage, offset)); } // mLoaderIdHistoryData else if (id == mLoaderIdHistoryCounter) { mPageCount = 1; mCurrentPage = 0; if (mCursorCounter != null) { mCursorCounter.close(); mCursorCounter = null; } return new CursorLoader(getActivity(), History._ContentUri, new String[] { History._COUNT }, selection, null, null); } // mLoaderIdHistoryCounter return null; }
From source file:com.lottodroid.widgets.wikiarticle.WikiarticleHelper.java
/** * Read and return the content for a specific Wiktionary page. This makes a * lightweight API call, and trims out just the page content returned. * Because this call blocks until results are available, it should not be * run from a UI thread./*from w w w . ja va 2 s .c om*/ * * @param title The exact title of the Wiktionary page requested. * @param expandTemplates If true, expand any wiki templates found. * @return Exact content of page. * @throws ApiException If any connection or server error occurs. * @throws ParseException If there are problems parsing the response. */ public static String getPageContent(String title, boolean expandTemplates) throws ApiException, ParseException { // Encode page title and expand templates if requested String encodedTitle = Uri.encode(title); String expandClause = expandTemplates ? WIKIARTICLE_EXPAND_TEMPLATES : ""; // Query the API for content String content = getUrlContent(String.format(WIKIARTICLE_PAGE, encodedTitle, expandClause)); try { // Drill into the JSON response to find the content body JSONObject response = new JSONObject(content); JSONObject query = response.getJSONObject("query"); JSONObject pages = query.getJSONObject("pages"); JSONObject page = pages.getJSONObject((String) pages.keys().next()); JSONArray revisions = page.getJSONArray("revisions"); JSONObject revision = revisions.getJSONObject(0); return revision.getString("*"); } catch (JSONException e) { throw new ParseException("Problem parsing API response", e); } }