List of usage examples for android.net Uri getQueryParameterNames
public Set<String> getQueryParameterNames()
From source file:com.takondi.tartt.ARActivity.java
@Override public boolean urlWasInvoked(String url) { Log.d(TAG, "urlWasInvoked " + url); if (url != null) { Uri uri = Uri.parse(url); if (URL_ARCHITECTSDK_SCHEME.equals(uri.getScheme())) { JSONObject paramJson = new JSONObject(); if (!uri.getQueryParameterNames().isEmpty()) { for (String param : uri.getQueryParameterNames()) { try { paramJson.put(param, uri.getQueryParameter(param)); } catch (JSONException e) { e.printStackTrace(); }/*from w ww . ja va 2s.c o m*/ } } handleEvent(uri.getHost(), paramJson); } } return false; }
From source file:im.vector.receiver.VectorUniversalLinkReceiver.java
/*** * Tries to parse an universal link.//w ww . j a v a 2s. c om * * @param uri the uri to parse * @return the universal link items, null if the universal link is invalid */ public static HashMap<String, String> parseUniversalLink(Uri uri) { HashMap<String, String> map = null; try { // sanity check if ((null == uri) || TextUtils.isEmpty(uri.getPath())) { Log.e(LOG_TAG, "## parseUniversalLink : null"); return null; } if (!TextUtils.equals(uri.getHost(), "vector.im") && !TextUtils.equals(uri.getHost(), "riot.im") && !TextUtils.equals(uri.getHost(), "matrix.to")) { Log.e(LOG_TAG, "## parseUniversalLink : unsupported host " + uri.getHost()); return null; } boolean isSupportedHost = TextUtils.equals(uri.getHost(), "vector.im") || TextUtils.equals(uri.getHost(), "riot.im"); // when the uri host is vector.im, it is followed by a dedicated path if (isSupportedHost && !mSupportedVectorLinkPaths.contains(uri.getPath())) { Log.e(LOG_TAG, "## parseUniversalLink : not supported"); return null; } // remove the server part String uriFragment; if (null != (uriFragment = uri.getFragment())) { uriFragment = uriFragment.substring(1); // get rid of first "/" } else { Log.e(LOG_TAG, "## parseUniversalLink : cannot extract path"); return null; } String temp[] = uriFragment.split("/", 3); // limit to 3 for security concerns (stack overflow injection) if (!isSupportedHost) { ArrayList<String> compliantList = new ArrayList<>(Arrays.asList(temp)); compliantList.add(0, "room"); temp = compliantList.toArray(new String[compliantList.size()]); } if (temp.length < 2) { Log.e(LOG_TAG, "## parseUniversalLink : too short"); return null; } if (!TextUtils.equals(temp[0], "room") && !TextUtils.equals(temp[0], "user")) { Log.e(LOG_TAG, "## parseUniversalLink : not supported " + temp[0]); return null; } map = new HashMap<>(); String firstParam = temp[1]; if (MXSession.isUserId(firstParam)) { if (temp.length > 2) { Log.e(LOG_TAG, "## parseUniversalLink : universal link to member id is too long"); return null; } map.put(ULINK_MATRIX_USER_ID_KEY, firstParam); } else if (MXSession.isRoomAlias(firstParam) || MXSession.isRoomId(firstParam)) { map.put(ULINK_ROOM_ID_OR_ALIAS_KEY, firstParam); } else if (MXSession.isGroupId(firstParam)) { map.put(ULINK_GROUP_ID_KEY, firstParam); } // room id only ? if (temp.length > 2) { String eventId = temp[2]; if (MXSession.isMessageId(eventId)) { map.put(ULINK_EVENT_ID_KEY, temp[2]); } else { uri = Uri.parse(uri.toString().replace("#/room/", "room/")); map.put(ULINK_ROOM_ID_OR_ALIAS_KEY, uri.getLastPathSegment()); Set<String> names = uri.getQueryParameterNames(); for (String name : names) { String value = uri.getQueryParameter(name); try { value = URLDecoder.decode(value, "UTF-8"); } catch (Exception e) { Log.e(LOG_TAG, "## parseUniversalLink : URLDecoder.decode " + e.getMessage()); return null; } map.put(name, value); } } } } catch (Exception e) { Log.e(LOG_TAG, "## parseUniversalLink : crashes " + e.getLocalizedMessage()); } // check if the parsing succeeds if ((null != map) && (map.size() < 1)) { Log.e(LOG_TAG, "## parseUniversalLink : empty dictionary"); return null; } return map; }