Java Code Examples for android.net.Uri#getQueryParameterNames()

The following examples show how to use android.net.Uri#getQueryParameterNames() . 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: ImageUtils.java    From Capstone-Project with MIT License 6 votes vote down vote up
public static String getCustomPostThumbnailImageUrl(String imageUrl, int heightPx, int widthPx) {
    if (TextUtils.isEmpty(imageUrl)) {
        return null;
    }

    Uri uri = Uri.parse(imageUrl);
    final Set<String> params = uri.getQueryParameterNames();
    final Uri.Builder newUri = uri.buildUpon().clearQuery();
    for (String param : params) {
        String value;
        if (param.equals("h")) {
            value = String.valueOf(heightPx);
        } else if (param.equals("w")) {
            value = String.valueOf(widthPx);
        } else {
            value = uri.getQueryParameter(param);
        }

        newUri.appendQueryParameter(param, value);
    }

    return newUri.build().toString();
}
 
Example 2
Source File: AbstractContentProviderStub.java    From DroidPlugin with GNU Lesser General Public License v3.0 6 votes vote down vote up
private Uri buildNewUri(Uri uri, String targetAuthority) {
    Uri.Builder b = new Builder();
    b.scheme(uri.getScheme());
    b.authority(targetAuthority);
    b.path(uri.getPath());

    if (VERSION.SDK_INT >= VERSION_CODES.HONEYCOMB) {
        Set<String> names = uri.getQueryParameterNames();
        if (names != null && names.size() > 0) {
            for (String name : names) {
                if (!TextUtils.equals(name, Env.EXTRA_TARGET_AUTHORITY)) {
                    b.appendQueryParameter(name, uri.getQueryParameter(name));
                }
            }
        }
    } else {
        b.query(uri.getQuery());
    }
    b.fragment(uri.getFragment());
    return b.build();
}
 
Example 3
Source File: ImageUtils.java    From Capstone-Project with MIT License 6 votes vote down vote up
public static String getCustomCommentUserImageThumbnailUrl(String imageUrl, int heightPx, int widthPx) {
    if (TextUtils.isEmpty(imageUrl)) {
        return null;
    }

    Uri uri = Uri.parse(imageUrl);
    final Set<String> params = uri.getQueryParameterNames();
    final Uri.Builder newUri = uri.buildUpon().clearQuery();
    for (String param : params) {
        String value;
        if (param.equals("h")) {
            value = String.valueOf(heightPx);
        } else if (param.equals("w")) {
            value = String.valueOf(widthPx);
        } else {
            value = uri.getQueryParameter(param);
        }

        newUri.appendQueryParameter(param, value);
    }

    return newUri.build().toString();
}
 
Example 4
Source File: ImageUtils.java    From Capstone-Project with MIT License 6 votes vote down vote up
public static String getCustomUserThumbnailUrl(String imageUrl, int heightPx, int widthPx) {
    if (TextUtils.isEmpty(imageUrl)) {
        return null;
    }

    Uri uri = Uri.parse(imageUrl);
    final Set<String> params = uri.getQueryParameterNames();
    final Uri.Builder newUri = uri.buildUpon().clearQuery();
    for (String param : params) {
        String value;
        if (param.equals("h")) {
            value = String.valueOf(heightPx);
        } else if (param.equals("w")) {
            value = String.valueOf(widthPx);
        } else {
            value = uri.getQueryParameter(param);
        }

        newUri.appendQueryParameter(param, value);
    }

    return newUri.build().toString();
}
 
Example 5
Source File: EmailLinkParser.java    From FirebaseUI-Android with Apache License 2.0 6 votes vote down vote up
private Map<String, String> parseUri(Uri uri) {
    Map<String, String> map = new HashMap<>();
    try {
        Set<String> queryParameters = uri.getQueryParameterNames();
        for (String param : queryParameters) {
            if (param.equalsIgnoreCase(LINK) || param.equalsIgnoreCase(CONTINUE_URL)) {
                Uri innerUri = Uri.parse(uri.getQueryParameter(param));
                Map<String, String> innerValues = parseUri(innerUri);
                if (innerValues != null) {
                    map.putAll(innerValues);
                }
            } else {
                String value = uri.getQueryParameter(param);
                if (value != null) {
                    map.put(param, value);
                }
            }
        }
    } catch (Exception e) {
        // Do nothing.
    }
    return map;
}
 
Example 6
Source File: SearchActivityBundle.java    From Hentoid with Apache License 2.0 6 votes vote down vote up
public static List<Attribute> parseSearchUri(Uri uri) {
    List<Attribute> result = new ArrayList<>();

    if (uri != null)
        for (String typeStr : uri.getQueryParameterNames()) {
            AttributeType type = AttributeType.searchByName(typeStr);
            if (type != null)
                for (String attrStr : uri.getQueryParameters(typeStr)) {
                    String[] attrParams = attrStr.split(";");
                    if (2 == attrParams.length) {
                        result.add(new Attribute(type, attrParams[1]).setId(Long.parseLong(attrParams[0])));
                    }
                }
        }

    return result;
}
 
Example 7
Source File: FlutterWrapperActivity.java    From hybrid_stack_manager with MIT License 6 votes vote down vote up
public void openUrl(String url) {
    HybridStackManager.sharedInstance().curFlutterActivity = null;
    if(url.contains("flutter=true")){
        Intent intent = new Intent(FlutterWrapperActivity.this, FlutterWrapperActivity.class);
        intent.setAction(Intent.ACTION_RUN);
        intent.setData(Uri.parse(url));
        this.innerStartActivity(intent,true);
    }
    else{
        Uri tmpUri = Uri.parse(url);
        String tmpUrl = String.format("%s://%s",tmpUri.getScheme(),tmpUri.getHost());
        HashMap query = new HashMap();
        for(String key : tmpUri.getQueryParameterNames()){
            query.put(key,tmpUri.getQueryParameter(key));
        }
        XURLRouter.sharedInstance().openUrlWithQueryAndParams(tmpUrl,query,null);
        saveFinishSnapshot(false);
    }
}
 
Example 8
Source File: FlutterWrapperActivity.java    From hybrid_stack_manager with MIT License 6 votes vote down vote up
public void openUrl(String url) {
    HybridStackManager.sharedInstance().curFlutterActivity = null;
    if(url.contains("flutter=true")){
        Intent intent = new Intent(FlutterWrapperActivity.this, FlutterWrapperActivity.class);
        intent.setAction(Intent.ACTION_RUN);
        intent.setData(Uri.parse(url));
        this.innerStartActivity(intent,true);
    }
    else{
        Uri tmpUri = Uri.parse(url);
        String tmpUrl = String.format("%s://%s",tmpUri.getScheme(),tmpUri.getHost());
        HashMap query = new HashMap();
        for(String key : tmpUri.getQueryParameterNames()){
            query.put(key,tmpUri.getQueryParameter(key));
        }
        XURLRouter.sharedInstance().openUrlWithQueryAndParams(tmpUrl,query,null);
        saveFinishSnapshot(false);
    }
}
 
Example 9
Source File: ShowLocationActivity.java    From PocketMaps with MIT License 6 votes vote down vote up
private boolean getLocationFromQueryParameters(Properties prop, Uri uri)
{
  try
  {
    Set<String> keys = uri.getQueryParameterNames();
    for (String key : keys)
    {
      String value = uri.getQueryParameter(key);
      prop.setProperty(key, value);
    }
    return checkLocationParameters(prop);
  }
  catch (UnsupportedOperationException e)
  {
    // Example: "geo:0,0?q=MySearchLocation"
    // Example: "geo:100,100"
    return false;
  }
}
 
Example 10
Source File: CTInAppBaseFragment.java    From clevertap-android-sdk with MIT License 6 votes vote down vote up
void fireUrlThroughIntent(String url, Bundle formData) {
    try {
        Uri uri = Uri.parse(url.replace("\n", "").replace("\r", ""));
        Set<String> queryParamSet = uri.getQueryParameterNames();
        Bundle queryBundle = new Bundle();
        if (queryParamSet != null && !queryParamSet.isEmpty()) {
            for (String queryName : queryParamSet) {
                queryBundle.putString(queryName, uri.getQueryParameter(queryName));
            }
        }
        Intent intent = new Intent(Intent.ACTION_VIEW, uri);
        if (!queryBundle.isEmpty()) {
            intent.putExtras(queryBundle);
        }
        Utils.setPackageNameFromResolveInfoList(getActivity(),intent);
        startActivity(intent);
    } catch (Throwable t) {
        // Ignore
    }
    didDismiss(formData);
}
 
Example 11
Source File: MessageExtractActivity.java    From PretendSharing_Xposed with MIT License 6 votes vote down vote up
private void parseRealIntent(){
    String tempUriStr = realIntent.getDataString();
    if(tempUriStr != null && tempUriStr.startsWith("mqqapi://")) { //qq的参数是base64加密的
        Uri tempUri = realIntent.getData();
        Set<String> tempSet = tempUri.getQueryParameterNames();
        tempUriStr = tempUriStr + "\n" + getString(R.string.string_decoded) + "\n";
        for (String tempStr:tempSet){
            String tempStrGet = tempUri.getQueryParameter(tempStr);
            String tempBase64Decoded = "";
            try{
                tempBase64Decoded = new String(Base64.decode(tempStrGet.replaceAll(" ", "+").getBytes(),Base64.DEFAULT));
            }catch (Exception e){
                tempBase64Decoded = tempStrGet;
            }
            tempUriStr = tempUriStr + tempStr + ":" + tempBase64Decoded + "\n";
        }
    }
    String tempBundle = utils.toString(utils.goThroughBundleAsString(realIntent.getExtras()));
    textView.setText(String.valueOf(tempUriStr)+"\n"+tempBundle);
}
 
Example 12
Source File: AbstractContentProviderStub.java    From letv with Apache License 2.0 6 votes vote down vote up
private Uri buildNewUri(Uri uri, String targetAuthority) {
    Builder b = new Builder();
    b.scheme(uri.getScheme());
    b.authority(targetAuthority);
    b.path(uri.getPath());
    if (VERSION.SDK_INT >= 11) {
        Set<String> names = uri.getQueryParameterNames();
        if (names != null && names.size() > 0) {
            for (String name : names) {
                if (!TextUtils.equals(name, ApkConstant.EXTRA_TARGET_AUTHORITY)) {
                    b.appendQueryParameter(name, uri.getQueryParameter(name));
                }
            }
        }
    } else {
        b.query(uri.getQuery());
    }
    b.fragment(uri.getFragment());
    return b.build();
}
 
Example 13
Source File: UriUtil.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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 14
Source File: Gateway3DSecureActivity.java    From gateway-android-sdk with Apache License 2.0 5 votes vote down vote up
String getACSResultFromUri(Uri uri) {
    String result = null;

    Set<String> params = uri.getQueryParameterNames();
    for (String param : params) {
        if ("acsResult".equalsIgnoreCase(param)) {
            result = uri.getQueryParameter(param);
        }
    }

    return result;
}
 
Example 15
Source File: AdditionalParamsProcessor.java    From AppAuth-Android with Apache License 2.0 5 votes vote down vote up
static Map<String, String> extractAdditionalParams(
        Uri uri,
        Set<String> builtInParams) {
    Map<String, String> additionalParams = new LinkedHashMap<>();
    for (String param : uri.getQueryParameterNames()) {
        if (!builtInParams.contains(param)) {
            additionalParams.put(param, uri.getQueryParameter(param));
        }
    }
    return additionalParams;
}
 
Example 16
Source File: ModernHttpRequesterMock.java    From commcare-android with Apache License 2.0 5 votes vote down vote up
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
private static void assertUrlsEqual(String expected, String request) {
    Uri requestUrl = Uri.parse(request);
    Uri expectedUrl = Uri.parse(expected);
    assertEquals(expectedUrl.getPath(), requestUrl.getPath());
    for (String queryParam : expectedUrl.getQueryParameterNames()) {
        assertEquals(requestUrl.getQueryParameter(queryParam), expectedUrl.getQueryParameter(queryParam));
    }
}
 
Example 17
Source File: UriUtil.java    From MediaSDK with Apache License 2.0 5 votes vote down vote up
/**
 * 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 18
Source File: Payments.java    From Watch-Me-Build-a-Finance-Startup with MIT License 5 votes vote down vote up
public HashMap<String,String> parseLinkUriData(Uri linkUri) {
    HashMap<String,String> linkData = new HashMap<String,String>();
    for(String key : linkUri.getQueryParameterNames()) {
        linkData.put(key, linkUri.getQueryParameter(key));
    }
    return linkData;
}
 
Example 19
Source File: FlowContentObserver.java    From Meteorite with Apache License 2.0 4 votes vote down vote up
@TargetApi(VERSION_CODES.JELLY_BEAN)
private void onChange(boolean selfChanges, Uri uri, boolean calledInternally) {
    String fragment = uri.getFragment();
    String tableName = uri.getAuthority();

    String columnName;
    String param;

    Set<String> queryNames = uri.getQueryParameterNames();
    SQLOperator[] columnsChanged = new SQLOperator[queryNames.size()];
    if (!queryNames.isEmpty()) {
        int index = 0;
        for (String key : queryNames) {
            param = Uri.decode(uri.getQueryParameter(key));
            columnName = Uri.decode(key);
            columnsChanged[index] = Operator.op(new NameAlias.Builder(columnName).build())
                .eq(param);
            index++;
        }
    }

    Class<?> table = registeredTables.get(tableName);
    Action action = Action.valueOf(fragment);
    if (!isInTransaction) {

        for (OnModelStateChangedListener modelChangeListener : modelChangeListeners) {
            modelChangeListener.onModelStateChanged(table, action, columnsChanged);
        }

        if (!calledInternally) {
            for (OnTableChangedListener onTableChangeListener : onTableChangedListeners) {
                onTableChangeListener.onTableChanged(table, action);
            }
        }
    } else {
        // convert this uri to a CHANGE op if we don't care about individual changes.
        if (!notifyAllUris) {
            action = Action.CHANGE;
            uri = SqlUtils.getNotificationUri(table, action);
        }
        synchronized (notificationUris) {
            // add and keep track of unique notification uris for when transaction completes.
            notificationUris.add(uri);
        }

        synchronized (tableUris) {
            tableUris.add(SqlUtils.getNotificationUri(table, action));
        }
    }
}
 
Example 20
Source File: ImageGalleryUtils.java    From droidddle with Apache License 2.0 4 votes vote down vote up
public static String getFormattedImageUrl(@Nullable String url, int width, int height) {
    if (!TextUtils.isEmpty(url)) {

        Uri uri = Uri.parse(url);
        String scheme = uri.getScheme();
        String authority = uri.getAuthority();
        String path = uri.getEncodedPath();

        Set<String> queryParameterNames = uri.getQueryParameterNames();

        Uri.Builder builder = new Uri.Builder();
        builder.scheme(scheme)
                .authority(authority)
                .appendPath(path.substring(1));

        boolean isWidthSet = false;
        boolean isHeightSet = false;

        if (width > 2048) {
            width = 2048;
        }

        if (height > 2048) {
            height = 2048;
        }

        for (String key : queryParameterNames) {
            if (key.equals("w")) {
                builder.appendQueryParameter(key, String.valueOf(width));
                isWidthSet = true;
            } else if (key.equals("h")) {
                builder.appendQueryParameter(key, String.valueOf(height));
                isHeightSet = true;
            } else {
                builder.appendQueryParameter(key, uri.getQueryParameter(key));
            }
        }

        if (!isWidthSet) {
            builder.appendQueryParameter("w", String.valueOf(width));
        }

        if (!isHeightSet) {
            builder.appendQueryParameter("h", String.valueOf(height));
        }

        String formattedUrl = String.format("http://xi.mg/%s", builder.build().toString());
        formattedUrl = formattedUrl.replace(" ", "%20");
        formattedUrl = formattedUrl.replace("%2520", "%20");

        return formattedUrl;
    }

    return "";
}