Java Code Examples for android.net.Uri#encode()
The following examples show how to use
android.net.Uri#encode() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Feedback.java From Personal-Chef with MIT License | 6 votes |
void sendFeedback() { String feedback; String subject = "Feedback"; feedback=fftext.getText().toString(); if(!feedback.trim().isEmpty()) { Log.i("Send email", ""); String TO = "[email protected]"; Intent send = new Intent(Intent.ACTION_SENDTO); String uriText = "mailto:" + Uri.encode(TO) + "?subject=" + Uri.encode(subject) + "&body=" + Uri.encode(feedback); Uri uri = Uri.parse(uriText); send.setData(uri); startActivity(Intent.createChooser(send, "Send mail...")); } else { Toast.makeText(getApplicationContext(), "Please Enter Text in Feedback Details", Toast.LENGTH_SHORT).show(); } }
Example 2
Source File: OkHttpDownloader.java From PkRSS with Apache License 2.0 | 6 votes |
@Override public String toUrl(Request request) { // Copy base url String url = request.url; if (request.individual) { // Handle individual urls differently url += "feed/?withoutcomments=1"; } else { if (request.search != null) url += "?s=" + Uri.encode(request.search); if (request.page > 1) url += (request.search == null ? "?paged=" : "&paged=") + String.valueOf(request.page); } // Return safe url return url; }
Example 3
Source File: USSDController.java From VoIpUSSD with Apache License 2.0 | 6 votes |
private void dialUp(String ussdPhoneNumber, int simSlot) { if (map == null || (!map.containsKey(KEY_ERROR) || !map.containsKey(KEY_LOGIN))) { this.callbackInvoke.over("Bad Mapping structure"); return; } if (ussdPhoneNumber.isEmpty()) { this.callbackInvoke.over("Bad ussd number"); return; } String uri = Uri.encode("#"); if (uri != null) ussdPhoneNumber = ussdPhoneNumber.replace("#", uri); Uri uriPhone = Uri.parse("tel:" + ussdPhoneNumber); if (uriPhone != null) isRunning = true; this.context.startActivity(getActionCallIntent(uriPhone, simSlot)); }
Example 4
Source File: UWXBundleInfo.java From ucar-weex-core with Apache License 2.0 | 5 votes |
public String getUrlParam() { String tempUrl; if (param != null) { if (url.contains("?")) { tempUrl = url + "¶ms=" + Uri.encode(JSON.toJSONString(param)); } else { tempUrl = url + "?params=" + Uri.encode(JSON.toJSONString(param)); } } else { tempUrl = url; } return tempUrl; }
Example 5
Source File: EmailIntentBuilder.java From EmailIntentBuilder with Apache License 2.0 | 5 votes |
@NotNull static String encodeRecipient(String recipient) { int index = recipient.lastIndexOf('@'); String localPart = recipient.substring(0, index); String host = recipient.substring(index + 1); return Uri.encode(localPart) + "@" + Uri.encode(host); }
Example 6
Source File: BackendService.java From NominatimGeocoderBackend with Apache License 2.0 | 5 votes |
@Override protected List<Address> getFromLocationName(String locationName, int maxResults, double lowerLeftLatitude, double lowerLeftLongitude, double upperRightLatitude, double upperRightLongitude, String locale) { String query = Uri.encode(locationName); String url; if (lowerLeftLatitude == 0 && lowerLeftLongitude == 0 && upperRightLatitude == 0 && upperRightLongitude == 0) { url = String.format(Locale.US, SEARCH_GEOCODE_URL, mApiUrl, mAPIKey, locale.split("_")[0], query, maxResults); } else { url = String.format(Locale.US, SEARCH_GEOCODE_WITH_BOX_URL, mApiUrl, mAPIKey, locale.split("_")[0], query, maxResults, lowerLeftLongitude, upperRightLatitude, upperRightLongitude, lowerLeftLatitude); } try { JSONArray result = new JSONArray(new AsyncGetRequest(this, url).asyncStart().retrieveString()); List<Address> addresses = new ArrayList<>(); for (int i = 0; i < result.length(); i++) { Address address = parseResponse(localeFromLocaleString(locale), result.getJSONObject(i)); if (address != null) addresses.add(address); } if (!addresses.isEmpty()) return addresses; } catch (Exception e) { Log.w(TAG, e); } return null; }
Example 7
Source File: BaiduTranslator.java From Akoi-Translator with MIT License | 5 votes |
@Override protected TranslateResult doTranslateBackground(final TranslateRequest request) { String query = Uri.encode(request.mQuery); String fromLan = obtainFromLanguage(request); String toLan = obtainToLanguage(request); String encryptedSign = API_KEY + request.mQuery + SALT + API_SECRET; String sign = AppUtils.getMD5(encryptedSign.getBytes()); String url = REQUEST_URL.replace("%api_key%", API_KEY).replace("%query%", query) .replace("%from%", fromLan).replace("%to%", toLan) .replace("%salt%", SALT).replace("%sign%", sign); String rawResponse = HttpUtils.doGet(url); AppLog.i(LOGTAG, "rawResponse=" + rawResponse + "; url=" + url); return parseTranslateResult(rawResponse); }
Example 8
Source File: MainActivity.java From CSCI4669-Fall15-Android with Apache License 2.0 | 5 votes |
@Override public void onClick(View v) { // get query string and create a URL representing the search String tag = ((TextView) v.findViewById(R.id.textView)).getText().toString(); String urlString = getString(R.string.searchURL) + Uri.encode(savedSearches.getString(tag, ""), "UTF-8"); // create an Intent to launch a web browser Intent webIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(urlString)); startActivity(webIntent); // launches web browser to view results }
Example 9
Source File: MainActivity.java From GotoSleep with GNU General Public License v3.0 | 5 votes |
private String sendFeedback(){ String subject = "Go to Sleep Feedback"; String bodyText = getString(R.string.feedbackBodyText); String mailto = "mailto:[email protected]" + "?subject=" + Uri.encode(subject) + "&body=" + Uri.encode(bodyText); return mailto; }
Example 10
Source File: ImageLoader.java From Contacts with MIT License | 5 votes |
public static void display(ImageView imageView, String uri, boolean fadeIn, int stubImage, ImageLoaderListener listener) { if (uri == null || uri.length() == 0) uri = FAKE_URI; uri = Uri.encode(uri, ALLOWED_URI_CHARS); Picasso picasso = Picasso.with(imageView.getContext()); RequestCreator requestCreator = picasso.load(uri); if (stubImage != 0) { requestCreator.placeholder(stubImage); requestCreator.error(stubImage); } if (!(fadeIn && FADE_ENABLED)) requestCreator.noFade(); LayoutParams params = imageView.getLayoutParams(); if (params.width > 0 && params.height > 0) { requestCreator.resize(params.width, params.height, true); } requestCreator.inSampleSize(true); requestCreator.into(imageView, listener); }
Example 11
Source File: HttpUrlConnectionProxyUtil.java From DoraemonKit with Apache License 2.0 | 4 votes |
public static String encodeUrl(String url) { return Uri.encode(url, "-![.:/,%?&=]"); }
Example 12
Source File: SearchView.java From zen4android with MIT License | 4 votes |
/** * When a particular suggestion has been selected, perform the various lookups required * to use the suggestion. This includes checking the cursor for suggestion-specific data, * and/or falling back to the XML for defaults; It also creates REST style Uri data when * the suggestion includes a data id. * * @param c The suggestions cursor, moved to the row of the user's selection * @param actionKey The key code of the action key that was pressed, * or {@link KeyEvent#KEYCODE_UNKNOWN} if none. * @param actionMsg The message for the action key that was pressed, * or <code>null</code> if none. * @return An intent for the suggestion at the cursor's position. */ private Intent createIntentFromSuggestion(Cursor c, int actionKey, String actionMsg) { try { // use specific action if supplied, or default action if supplied, or fixed default String action = getColumnString(c, SearchManager.SUGGEST_COLUMN_INTENT_ACTION); if (action == null) { action = mSearchable.getSuggestIntentAction(); } if (action == null) { action = Intent.ACTION_SEARCH; } // use specific data if supplied, or default data if supplied String data = getColumnString(c, SearchManager.SUGGEST_COLUMN_INTENT_DATA); if (data == null) { data = mSearchable.getSuggestIntentData(); } // then, if an ID was provided, append it. if (data != null) { String id = getColumnString(c, SearchManager.SUGGEST_COLUMN_INTENT_DATA_ID); if (id != null) { data = data + "/" + Uri.encode(id); } } Uri dataUri = (data == null) ? null : Uri.parse(data); String query = getColumnString(c, SearchManager.SUGGEST_COLUMN_QUERY); String extraData = getColumnString(c, SearchManager.SUGGEST_COLUMN_INTENT_EXTRA_DATA); return createIntent(action, dataUri, extraData, query, actionKey, actionMsg); } catch (RuntimeException e ) { int rowNum; try { // be really paranoid now rowNum = c.getPosition(); } catch (RuntimeException e2 ) { rowNum = -1; } Log.w(LOG_TAG, "Search suggestions cursor at row " + rowNum + " returned exception.", e); return null; } }
Example 13
Source File: MyCache.java From emerald with GNU General Public License v3.0 | 4 votes |
public static File getCustomIconFile(Context c, String component) { return new File(c.getFilesDir(), Uri.encode(component)+".png"); }
Example 14
Source File: GroupsViewFragment.java From HomeGenie-Android with GNU General Public License v3.0 | 4 votes |
public void UpdateCurrentGroupMenu() { StartActivity rootActivity = (StartActivity) getActivity(); if (rootActivity == null) return; Menu menu = rootActivity.getActionMenu(); if (menu != null) { MenuItem automation = menu.findItem(R.id.menu_automation); if (automation != null) { automation.setEnabled(false); Menu submenu = automation.getSubMenu(); if (submenu == null) return; // submenu.removeGroup(Menu.NONE); if (mGroupPrograms.size() > 0) { for (Module program : mGroupPrograms) { MenuItem prg = submenu.add(Menu.NONE, Menu.NONE, Menu.NONE, program.getDisplayName()); prg.setIcon(R.drawable.ic_action_flash_on); MenuCompat.setShowAsAction(prg, SHOW_AS_ACTION_IF_ROOM | SHOW_AS_ACTION_WITH_TEXT); final String address = program.Address; String groupName = ""; try { groupName = Uri.encode(mAdapter.getGroup(mCurrentGroup).Name, "UTF-8"); } catch (Exception e) { } final String group = groupName; prg.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem menuItem) { String apiCall = "HomeAutomation.HomeGenie/Automation/Programs.Run/" + address + "/" + group + "/" + new Date().getTime(); Control.apiRequest(apiCall, null); return true; } }); } automation.setEnabled(true); } } // // MenuItem recordMacro = submenu.add(1, Menu.NONE, Menu.NONE, "Record macro"); // recordMacro.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { // @Override // public boolean onMenuItemClick(MenuItem menuItem) { // StartActivity sa = (StartActivity)getActivity(); // sa.openMacroRecordMenu(); // return true; // } // }); // rootactivity.supportInvalidateOptionsMenu(); } }
Example 15
Source File: Command.java From BotLibre with Eclipse Public License 1.0 | 4 votes |
public void map() { String query = ((String) jsonObject.opt("query")); String dirFrom = (String) jsonObject.opt("directions-from"); String dirTo = (String) jsonObject.opt("directions-to"); String mode = (String) jsonObject.opt("mode"); String avoid = (String) jsonObject.opt("avoid"); Intent mapIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("geo:0,0")); mapIntent.setPackage("com.google.android.apps.maps"); if (query != null) { query = Uri.encode(query); mapIntent.setData(Uri.parse("geo:0,0?q="+query)); } if (dirTo != null && dirFrom == null) { String directions = "google.navigation:q="+Uri.encode(dirTo); StringBuilder sb = new StringBuilder(directions); if (mode != null) { if (mode.contains("driv")) sb.append("&mode=d"); else if (mode.contains("walk")) sb.append("&mode=w"); else if (mode.contains("bic") || mode.contains("bik")) sb.append("&mode=b"); } else if (avoid != null) { sb.append("&avoid="); if (avoid.contains("toll")) sb.append("t"); if (avoid.contains("high")) sb.append("h"); if (avoid.contains("ferr")) sb.append("f"); } directions = sb.toString(); mapIntent.setData(Uri.parse(directions)); } else if (dirTo != null && dirFrom != null) { mapIntent.setData(Uri.parse("http://maps.google.com/maps?saddr="+Uri.encode(dirFrom)+"&daddr="+Uri.encode(dirTo))); } if (mapIntent.resolveActivity(manager) != null) { context.startActivity(mapIntent); } else { MainActivity.showMessage("Google maps not available on your device", (Activity)context); } }
Example 16
Source File: AppDetailsRecyclerViewAdapter.java From fdroidclient with GNU General Public License v3.0 | 4 votes |
@Override public void bindModel() { itemView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { boolean shouldBeVisible = contentView.getVisibility() != View.VISIBLE; contentView.setVisibility(shouldBeVisible ? View.VISIBLE : View.GONE); updateExpandableItem(shouldBeVisible); if (shouldBeVisible && recyclerView != null) { ((LinearLayoutManager) recyclerView.getLayoutManager()).scrollToPositionWithOffset(items.indexOf(VIEWTYPE_LINKS), 0); } } }); headerView.setText(R.string.links); updateExpandableItem(false); contentView.removeAllViews(); // License link if (!TextUtils.isEmpty(app.license)) { String firstLicense = app.license.split(",")[0]; String url = "https://spdx.org/licenses/" + firstLicense + ".html"; if (uriIsSetAndCanBeOpened(url)) { addLinkItemView(contentView, R.string.menu_license, R.drawable.ic_license, url, app.license); } } // Video link if (uriIsSetAndCanBeOpened(app.video)) { addLinkItemView(contentView, R.string.menu_video, R.drawable.ic_video, app.video); } // Source button if (uriIsSetAndCanBeOpened(app.sourceCode)) { addLinkItemView(contentView, R.string.menu_source, R.drawable.ic_source_code, app.sourceCode); } // Issues button if (uriIsSetAndCanBeOpened(app.issueTracker)) { addLinkItemView(contentView, R.string.menu_issues, R.drawable.ic_issues, app.issueTracker); } // Translation button if (uriIsSetAndCanBeOpened(app.translation)) { addLinkItemView(contentView, R.string.menu_translation, R.drawable.ic_translation, app.translation); } // Changelog button if (uriIsSetAndCanBeOpened(app.changelog)) { addLinkItemView(contentView, R.string.menu_changelog, R.drawable.ic_changelog, app.changelog); } // Website button if (uriIsSetAndCanBeOpened(app.webSite)) { addLinkItemView(contentView, R.string.menu_website, R.drawable.ic_website, app.webSite); } // Email button final String subject = Uri.encode(context.getString(R.string.app_details_subject, app.name)); String emailUrl = app.authorEmail == null ? null : ("mailto:" + app.authorEmail + "?subject=" + subject); if (uriIsSetAndCanBeOpened(emailUrl)) { addLinkItemView(contentView, R.string.menu_email, R.drawable.ic_email, emailUrl); } }
Example 17
Source File: PushTests.java From azure-mobile-apps-android-client with Apache License 2.0 | 4 votes |
public void testRegister() throws Throwable { final Container container = new Container(); MobileServiceClient client = null; final String handle = "handle"; String installationId = MobileServiceApplication.getInstallationId(getInstrumentation().getTargetContext()); final String expectedUrl = appUrl + pnsApiUrl + "/installations/" + Uri.encode(installationId); final String expectedContent = "{\"pushChannel\":\"handle\",\"platform\":\""+pnsApiPlatform+"\"}"; try { client = new MobileServiceClient(appUrl, getInstrumentation().getTargetContext()); client = client.withFilter(new ServiceFilter() { @Override public ListenableFuture<ServiceFilterResponse> handleRequest(ServiceFilterRequest request, NextServiceFilterCallback nextServiceFilterCallback) { container.requestUrl = request.getUrl(); container.requestContent = request.getContent(); container.requestMethod = request.getMethod(); ServiceFilterResponseMock mockResponse = new ServiceFilterResponseMock(); mockResponse.setStatus(new StatusLine(Protocol.HTTP_2, 204, "")); ServiceFilterRequestMock mockRequest = new ServiceFilterRequestMock(mockResponse); return nextServiceFilterCallback.onNext(mockRequest); } }); final MobileServicePush push = client.getPush(); push.register(handle).get(); } catch (Exception exception) { if (exception instanceof ExecutionException) { container.exception = (Exception) exception.getCause(); } else { container.exception = exception; } fail(container.exception.getMessage()); } // Asserts Assert.assertEquals(expectedUrl, container.requestUrl); Assert.assertEquals(expectedContent, container.requestContent); Assert.assertEquals(HttpConstants.PutMethod, container.requestMethod); }
Example 18
Source File: Command.java From BotLibre with Eclipse Public License 1.0 | 4 votes |
public void map() { String query = ((String) jsonObject.opt("query")); String dirFrom = (String) jsonObject.opt("directions-from"); String dirTo = (String) jsonObject.opt("directions-to"); String mode = (String) jsonObject.opt("mode"); String avoid = (String) jsonObject.opt("avoid"); Intent mapIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("geo:0,0")); mapIntent.setPackage("com.google.android.apps.maps"); if (query != null) { query = Uri.encode(query); mapIntent.setData(Uri.parse("geo:0,0?q="+query)); } if (dirTo != null && dirFrom == null) { String directions = "google.navigation:q="+Uri.encode(dirTo); StringBuilder sb = new StringBuilder(directions); if (mode != null) { if (mode.contains("driv")) sb.append("&mode=d"); else if (mode.contains("walk")) sb.append("&mode=w"); else if (mode.contains("bic") || mode.contains("bik")) sb.append("&mode=b"); } else if (avoid != null) { sb.append("&avoid="); if (avoid.contains("toll")) sb.append("t"); if (avoid.contains("high")) sb.append("h"); if (avoid.contains("ferr")) sb.append("f"); } directions = sb.toString(); mapIntent.setData(Uri.parse(directions)); } else if (dirTo != null && dirFrom != null) { mapIntent.setData(Uri.parse("http://maps.google.com/maps?saddr="+Uri.encode(dirFrom)+"&daddr="+Uri.encode(dirTo))); } if (mapIntent.resolveActivity(manager) != null) { context.startActivity(mapIntent); } else { MainActivity.showMessage("Google maps not available on your device", (Activity)context); } }
Example 19
Source File: BaseImageDownloader.java From android-project-wo2b with Apache License 2.0 | 3 votes |
/** * Create {@linkplain HttpURLConnection HTTP connection} for incoming URL * * @param url URL to connect to * @param extra Auxiliary object which was passed to {@link DisplayImageOptions.Builder#extraForDownloader(Object) * DisplayImageOptions.extraForDownloader(Object)}; can be null * @return {@linkplain HttpURLConnection Connection} for incoming URL. Connection isn't established so it still configurable. * @throws IOException if some I/O error occurs during network request or if no InputStream could be created for * URL. */ protected HttpURLConnection createConnection(String url, Object extra) throws IOException { String encodedUrl = Uri.encode(url, ALLOWED_URI_CHARS); HttpURLConnection conn = (HttpURLConnection) new URL(encodedUrl).openConnection(); conn.setConnectTimeout(connectTimeout); conn.setReadTimeout(readTimeout); return conn; }
Example 20
Source File: BaseImageDownloader.java From Roid-Library with Apache License 2.0 | 3 votes |
/** * Create {@linkplain HttpURLConnection HTTP connection} for incoming URL * * @param url URL to connect to * @param extra Auxiliary object which was passed to * {@link DisplayImageOptions.Builder#extraForDownloader(Object) * DisplayImageOptions.extraForDownloader(Object)}; can be null * @return {@linkplain HttpURLConnection Connection} for incoming URL. * Connection isn't established so it still configurable. * @throws IOException if some I/O error occurs during network request or * if no InputStream could be created for URL. */ protected HttpURLConnection createConnection(String url, Object extra) throws IOException { String encodedUrl = Uri.encode(url, ALLOWED_URI_CHARS); HttpURLConnection conn = (HttpURLConnection) new URL(encodedUrl).openConnection(); conn.setConnectTimeout(connectTimeout); conn.setReadTimeout(readTimeout); return conn; }