Java Code Examples for android.net.Uri#buildUpon()
The following examples show how to use
android.net.Uri#buildUpon() .
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: Action.java From Rabbits with Apache License 2.0 | 6 votes |
/** * Create uri from url and param. This will parse all param to String and append * them to the uri. * * @return Uri */ public Uri createUri() { Uri uri = Uri.parse(getOriginUrl()); Uri.Builder builder = uri.buildUpon(); Bundle extras = getExtras(); if (extras != null) { Set<String> keys = extras.keySet(); for (String key : keys) { if (TextUtils.equals(key, Rabbit.KEY_ORIGIN_URL) || TextUtils.equals(key, Rabbit.KEY_PATTERN)) { continue; } Object value = extras.get(key); if (value == null) { continue; } builder.appendQueryParameter(key, URLEncodeUtils.encode(value.toString())); } } uri = builder.build(); return uri; }
Example 2
Source File: HybridStackManager.java From hybrid_stack_manager with MIT License | 6 votes |
public static String concatUrl(String url, HashMap query, HashMap params) { // assert(params==null||params.size()==0); Uri uri = Uri.parse(url); Uri.Builder builder = uri.buildUpon(); if (query != null) { for (Object key : query.keySet()) { Object value = query.get(key); if (value != null) { final String str; str = value.toString(); builder.appendQueryParameter(String.valueOf(key),str); } } } return builder.build().toString(); }
Example 3
Source File: RouterUtils.java From WMRouter with Apache License 2.0 | 6 votes |
/** * 在Uri中添加参数 * * @param uri 原始uri * @param params 要添加的参数 * @return uri 新的uri */ public static Uri appendParams(Uri uri, Map<String, String> params) { if (uri != null && params != null && !params.isEmpty()) { Uri.Builder builder = uri.buildUpon(); try { for (String key : params.keySet()) { if (TextUtils.isEmpty(key)) continue; final String val = uri.getQueryParameter(key); if (val == null) { // 当前没有此参数时,才会添加 final String value = params.get(key); builder.appendQueryParameter(key, value); } } return builder.build(); } catch (Exception e) { Debugger.fatal(e); } } return uri; }
Example 4
Source File: ForceHttpsActivity.java From LocationPrivacy with GNU General Public License v3.0 | 6 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Intent intent = getIntent(); if (intent == null) { finish(); return; } Uri uri = intent.getData(); if (uri != null) { Uri.Builder builder = uri.buildUpon(); builder.scheme("https"); intent.setData(builder.build()); } App.startActivityWithBlockedOrChooser(this, intent); finish(); }
Example 5
Source File: TranslationActivity.java From TranslateApp with GNU General Public License v3.0 | 5 votes |
@Override protected String doInBackground(String... input) { Uri baseUri = Uri.parse(BASE_REQ_URL); Uri.Builder uriBuilder = baseUri.buildUpon(); uriBuilder.appendPath("translate") .appendQueryParameter("key",getString(R.string.API_KEY)) .appendQueryParameter("lang",mLanguageCodeFrom+"-"+mLanguageCodeTo) .appendQueryParameter("text",input[0]); Log.e("String Url ---->",uriBuilder.toString()); return QueryUtils.fetchTranslation(uriBuilder.toString()); }
Example 6
Source File: AuthenticatorActivity.java From Cirrus_depricated with GNU General Public License v2.0 | 5 votes |
/** * Starts the OAuth 'grant type' flow to get an access token, with * a GET AUTHORIZATION request to the BUILT-IN authorization server. */ private void startOauthorization() { // be gentle with the user mAuthStatusIcon = R.drawable.progress_small; mAuthStatusText = R.string.oauth_login_connection; showAuthStatus(); // GET AUTHORIZATION request Uri uri = Uri.parse(mOAuthAuthEndpointText.getText().toString().trim()); Uri.Builder uriBuilder = uri.buildUpon(); uriBuilder.appendQueryParameter( OAuth2Constants.KEY_RESPONSE_TYPE, getString(R.string.oauth2_response_type) ); uriBuilder.appendQueryParameter( OAuth2Constants.KEY_REDIRECT_URI, getString(R.string.oauth2_redirect_uri) ); uriBuilder.appendQueryParameter( OAuth2Constants.KEY_CLIENT_ID, getString(R.string.oauth2_client_id) ); uriBuilder.appendQueryParameter( OAuth2Constants.KEY_SCOPE, getString(R.string.oauth2_scope) ); uri = uriBuilder.build(); Log_OC.d(TAG, "Starting browser to view " + uri.toString()); Intent i = new Intent(Intent.ACTION_VIEW, uri); startActivity(i); }
Example 7
Source File: Imps.java From Zom-Android-XMPP with GNU General Public License v3.0 | 5 votes |
public static boolean isUnlocked(Context context) { try { Cursor cursor = null; Uri uri = Imps.Provider.CONTENT_URI_WITH_ACCOUNT; Builder builder = uri.buildUpon(); builder = builder.appendQueryParameter(ImApp.NO_CREATE_KEY, "1"); uri = builder.build(); cursor = context.getContentResolver().query( uri, null, null, null, null); if (cursor != null) { cursor.close(); return true; } else { return false; } } catch (Exception e) { // Only complain if we thought this password should succeed Log.e(ImApp.LOG_TAG, e.getMessage(), e); // needs to be unlocked return false; } }
Example 8
Source File: ConversationActivity.java From TranslateApp with GNU General Public License v3.0 | 5 votes |
@Override protected ArrayList<String> doInBackground(Void... params) { Uri baseUri = Uri.parse(BASE_REQ_URL); Uri.Builder uriBuilder = baseUri.buildUpon(); uriBuilder.appendPath("getLangs") .appendQueryParameter("key",getString(R.string.API_KEY)) .appendQueryParameter("ui","en"); Log.e("String Url ---->",uriBuilder.toString()); return QueryUtils.fetchLanguages(uriBuilder.toString()); }
Example 9
Source File: TrayUri.java From tray with Apache License 2.0 | 5 votes |
public Uri build() { final Uri uri = mInternal ? mContentUriInternal : mContentUri; final Uri.Builder builder = uri.buildUpon(); if (mModule != null) { builder.appendPath(mModule); } if (mKey != null) { builder.appendPath(mKey); } if (mType != TrayStorage.Type.UNDEFINED) { builder.appendQueryParameter("backup", TrayStorage.Type.USER.equals(mType) ? "true" : "false"); } return builder.build(); }
Example 10
Source File: TranslationActivity.java From TranslateApp with GNU General Public License v3.0 | 5 votes |
@Override protected ArrayList<String> doInBackground(Void... params) { Uri baseUri = Uri.parse(BASE_REQ_URL); Uri.Builder uriBuilder = baseUri.buildUpon(); uriBuilder.appendPath("getLangs") .appendQueryParameter("key",getString(R.string.API_KEY)) .appendQueryParameter("ui","en"); Log.e("String Url ---->",uriBuilder.toString()); return QueryUtils.fetchLanguages(uriBuilder.toString()); }
Example 11
Source File: Utils.java From fdroidclient with GNU General Public License v3.0 | 5 votes |
@NonNull public static Uri getLocalRepoUri(Repo repo) { if (TextUtils.isEmpty(repo.address)) { return Uri.parse("http://wifi-not-enabled"); } Uri uri = Uri.parse(repo.address); Uri.Builder b = uri.buildUpon(); if (!TextUtils.isEmpty(repo.fingerprint)) { b.appendQueryParameter("fingerprint", repo.fingerprint); } String scheme = Preferences.get().isLocalRepoHttpsEnabled() ? "https" : "http"; b.scheme(scheme); return b.build(); }
Example 12
Source File: UriUtil.java From TelePlus-Android with GNU General Public License v2.0 | 5 votes |
/** * Removes query parameter from an Uri, if present. * * @param uri The uri. * @param queryParameterName The name of the query parameter. * @return The uri without the query parameter. */ public static Uri removeQueryParameter(Uri uri, String queryParameterName) { Uri.Builder builder = uri.buildUpon(); builder.clearQuery(); for (String key : uri.getQueryParameterNames()) { if (!key.equals(queryParameterName)) { for (String value : uri.getQueryParameters(key)) { builder.appendQueryParameter(key, value); } } } return builder.build(); }
Example 13
Source File: ShortcutHelper.java From AndroidChromium with Apache License 2.0 | 5 votes |
/** * Generates a scope URL based on the passed in URL. It should be used if the Web Manifest * does not specify a scope URL. * @param url The url to convert to a scope. * @return The scope. */ @CalledByNative public static String getScopeFromUrl(String url) { // Scope URL is generated by: // - Removing last component of the URL. // - Clearing the URL's query and fragment. Uri uri = Uri.parse(url); List<String> path = uri.getPathSegments(); int endIndex = path.size(); // If there is at least one path element, remove the last one. if (endIndex > 0) { endIndex -= 1; } // Make sure the path starts and ends with a slash (or is only a slash if there is no path). Uri.Builder builder = uri.buildUpon(); String scope_path = "/" + TextUtils.join("/", path.subList(0, endIndex)); if (scope_path.length() > 1) { scope_path += "/"; } builder.path(scope_path); builder.fragment(""); builder.query(""); return builder.build().toString(); }
Example 14
Source File: GalleryListFragment.java From zom-android-matrix with Apache License 2.0 | 5 votes |
private void setupRecyclerView(RecyclerView recyclerView) { recyclerView.setLayoutManager(new LinearLayoutManager(recyclerView.getContext())); Uri baseUri = Imps.Messages.CONTENT_URI; if (mByContactId != -1) baseUri = Imps.Messages.getContentUriByThreadId(mByContactId); Uri.Builder builder = baseUri.buildUpon(); mUri = builder.build(); mLoaderManager = getLoaderManager(); mLoaderCallbacks = new MyLoaderCallbacks(); mLoaderManager.initLoader(mLoaderId, null, mLoaderCallbacks); Cursor cursor = null; mAdapter = new MessageListRecyclerViewAdapter(getActivity(),cursor); if (mAdapter.getItemCount() == 0) { mRecView.setVisibility(View.GONE); if (mByContactId == -1) { mEmptyView.setVisibility(View.VISIBLE); mEmptyViewImage.setVisibility(View.VISIBLE); } else { mEmptyView.setVisibility(View.GONE); mEmptyViewImage.setVisibility(View.GONE); } } else { mRecView.setVisibility(View.VISIBLE); mEmptyView.setVisibility(View.GONE); mEmptyViewImage.setVisibility(View.GONE); } }
Example 15
Source File: DefaultUriAdapter.java From weex-uikit with MIT License | 5 votes |
@NonNull @Override public Uri rewrite(WXSDKInstance instance, String type, Uri uri) { Uri base = Uri.parse(instance.getBundleUrl()); Uri.Builder resultBuilder = uri.buildUpon(); if (uri.isRelative()) { resultBuilder = buildRelativeURI(resultBuilder, base, uri); return resultBuilder.build(); } return uri; }
Example 16
Source File: ContextualSearchRequest.java From AndroidChromium with Apache License 2.0 | 5 votes |
/** * Makes the given {@code Uri} into a similar Uri that triggers a Translate one-box. * @param baseUri The base Uri to build off of. * @param sourceLanguage The language of the original search term, or an empty string to * auto-detect the source language. * @param targetLanguage The language that the user prefers, or an empty string to * use server-side heuristics for the target language. * @return A {@link Uri} that has additional parameters for Translate appropriately set. */ private Uri makeTranslateUri(Uri baseUri, String sourceLanguage, String targetLanguage) { Uri.Builder builder = baseUri.buildUpon(); builder.appendQueryParameter(CTXSL_TRANS_PARAM, CTXSL_TRANS_PARAM_VALUE); if (!sourceLanguage.isEmpty()) { builder.appendQueryParameter(TLITE_SOURCE_LANGUAGE_PARAM, sourceLanguage); } if (!targetLanguage.isEmpty()) { builder.appendQueryParameter(TLITE_TARGET_LANGUAGE_PARAM, targetLanguage); } builder.appendQueryParameter(TLITE_QUERY_PARAM, baseUri.getQueryParameter(GWS_QUERY_PARAM)); return builder.build(); }
Example 17
Source File: UWXNavigatorModule2.java From ucar-weex-core with Apache License 2.0 | 4 votes |
@JSMethod(uiThread = true) public void push(String param, JSCallback callback) { if (!TextUtils.isEmpty(param)) { if (WXSDKEngine.getActivityNavBarSetter() != null) { if (WXSDKEngine.getActivityNavBarSetter().push(param)) { if (callback != null) { callback.invoke(MSG_SUCCESS); } return; } } try { JSONObject jsonObject = JSON.parseObject(param); String url = jsonObject.getString(URL); if (!TextUtils.isEmpty(url)) { Uri rawUri = Uri.parse(url); String scheme = rawUri.getScheme(); Uri.Builder builder = rawUri.buildUpon(); if (TextUtils.isEmpty(scheme)) { builder.scheme(Constants.Scheme.HTTP); } Intent intent = new Intent(Intent.ACTION_VIEW, builder.build()); intent.addCategory(WEEX); intent.putExtra(INSTANCE_ID, mWXSDKInstance.getInstanceId()); mWXSDKInstance.getContext().startActivity(intent); if (callback != null) { callback.invoke(MSG_SUCCESS); } } } catch (Exception e) { WXLogUtils.eTag(TAG, e); if (callback != null) { callback.invoke(MSG_FAILED); } } } else if (callback != null) { callback.invoke(MSG_FAILED); } }
Example 18
Source File: ImageProvider.java From sana.mobile with BSD 3-Clause "New" or "Revised" License | 4 votes |
/** * Return a thumbnail Uri for a given ImageProvider item Uri. The returned * Uri will still be compatible with all ContentProvider methods and refers * to the same item that imageUri refers to. */ public static Uri getThumbUri(Uri imageUri) { Uri.Builder thumbBuilder = imageUri.buildUpon(); thumbBuilder.appendQueryParameter(VIEW_PARAMETER, THUMBNAIL_VIEW); return thumbBuilder.build(); }
Example 19
Source File: DatabaseUtils.java From Zom-Android-XMPP with GNU General Public License v3.0 | 4 votes |
public static Uri getAvatarUri(Uri baseUri, long providerId, long accountId) { Uri.Builder builder = baseUri.buildUpon(); ContentUris.appendId(builder, providerId); ContentUris.appendId(builder, accountId); return builder.build(); }
Example 20
Source File: RouterActivity.java From Zom-Android-XMPP with GNU General Public License v3.0 | 4 votes |
@SuppressWarnings("deprecation") private boolean cursorUnlocked() { try { Uri uri = Imps.Provider.CONTENT_URI_WITH_ACCOUNT; Builder builder = uri.buildUpon(); /** if (pKey != null) builder.appendQueryParameter(ImApp.CACHEWORD_PASSWORD_KEY, pKey); if (!allowCreate) builder = builder.appendQueryParameter(ImApp.NO_CREATE_KEY, "1"); */ uri = builder.build(); mProviderCursor = managedQuery(uri, PROVIDER_PROJECTION, Imps.Provider.CATEGORY + "=?" /* selection */, new String[] { ImApp.IMPS_CATEGORY } /* selection args */, Imps.Provider.DEFAULT_SORT_ORDER); if (mProviderCursor != null) { ImPluginHelper.getInstance(this).loadAvailablePlugins(); mProviderCursor.moveToFirst(); return true; } else { return false; } } catch (Exception e) { // Only complain if we thought this password should succeed Log.e(ImApp.LOG_TAG, e.getMessage(), e); Toast.makeText(this, getString(R.string.error_welcome_database), Toast.LENGTH_LONG).show(); finish(); // needs to be unlocked return false; } }