Example usage for android.net Uri getQueryParameter

List of usage examples for android.net Uri getQueryParameter

Introduction

In this page you can find the example usage for android.net Uri getQueryParameter.

Prototype

@Nullable
public String getQueryParameter(String key) 

Source Link

Document

Searches the query string for the first value with the given key.

Usage

From source file:Main.java

/**
 * Retrieve the account UUID, or null if the UUID param is not found.
 *//*from  ww  w .  jav  a  2 s.  com*/
public static String getAccountUuidFromIntent(Intent intent) {
    final Uri uri = intent.getData();
    if (uri == null) {
        return null;
    }
    String uuid = uri.getQueryParameter(ACCOUNT_UUID_PARAM);
    return TextUtils.isEmpty(uuid) ? null : uuid;
}

From source file:Main.java

/**
 *
 * @param baseURL// w w w. j av a2s .  co  m
 * @param key
 * @return the soundcloud track id
 */
public static String parseSoundCloud(String baseURL) {

    Uri parsed = Uri.parse(baseURL);
    String authority = parsed.getAuthority();
    String trackURL = null;
    if (TextUtils.isEmpty(authority)) {
        return null;
    }
    if (authority.indexOf("api.soundcloud") >= 0) {
        trackURL = baseURL;
    } else if (authority.indexOf("soundcloud") >= 0) {
        Uri parsedURI = Uri.parse(baseURL);
        try {
            trackURL = parsedURI.getQueryParameter("url");
        } catch (Exception exc) {

        }
    }

    if (TextUtils.isEmpty(trackURL) == true) {
        return null;
    }

    Uri base = Uri.parse(trackURL);

    List<String> segments = base.getPathSegments();
    for (String segment : segments) {
        if (TextUtils.isDigitsOnly(segment) == true) {
            return segment;// String.format("https://api.soundcloud.com/tracks/%1$s/stream?consumer_key=%2$s",segment,key);
        }
    }

    return "";
}

From source file:Main.java

public static String getParam(Uri uri, String key, String defaultValue) {
    if (uri == null) {
        return defaultValue;
    }//from   w  ww .j a  va2s .co  m
    String value = null;
    try {
        value = uri.getQueryParameter(key);
    } catch (Exception e) {

    }

    if (TextUtils.isEmpty(value)) {
        value = defaultValue;
    }
    return value;
}

From source file:net.openid.appauth.internal.UriUtil.java

public static Long getLongQueryParameter(@NonNull Uri uri, @NonNull String param) {
    String valueStr = uri.getQueryParameter(param);
    if (valueStr != null) {
        return Long.parseLong(valueStr);
    }//from  w ww . java 2s  .c o m
    return null;
}

From source file:edu.stanford.mobisocial.dungbeetle.social.FriendRequest.java

public static long acceptFriendRequest(Context c, Uri friendRequest, boolean requireCapability) {
    String email = friendRequest.getQueryParameter("email");
    String name = friendRequest.getQueryParameter("name");
    if (name == null) {
        name = email;/*from  ww  w .ja va  2s.  co  m*/
    }

    String pubKeyStr = friendRequest.getQueryParameter("publicKey");
    RSACrypto.publicKeyFromString(pubKeyStr); // may throw exception
    String cap = friendRequest.getQueryParameter("cap");
    if (requireCapability) {
        if (cap == null) {
            Log.w(TAG, "Unapproved friend request");
            return -1;
        }
        SharedPreferences p = c.getSharedPreferences("main", 0);
        String myCap = p.getString(PREF_FRIEND_CAPABILITY, null);
        if (myCap == null) {
            Log.w(TAG, "No capability available");
            return -1;
        }
        if (!cap.equals(myCap)) {
            Log.w(TAG, "Capability mismatch");
            return -1;
        }
    }

    Uri uri = Helpers.insertContact(c, pubKeyStr, name, email);
    long contactId = Long.valueOf(uri.getLastPathSegment());
    Helpers.insertSubscriber(c, contactId, "friend");
    return contactId;
}

From source file:com.appnexus.opensdk.ANJAMImplementation.java

private static void callDispatchAppEvent(AdWebView webView, Uri uri) {
    String event = uri.getQueryParameter("event");
    String data = uri.getQueryParameter("data");

    webView.adView.getAdDispatcher().onAppEvent(event, data);
}

From source file:edu.stanford.mobisocial.dungbeetle.social.FriendRequest.java

/**
 * Returns the contact id for the contact associated with the given uri,
 * or -1 if no such contact exists./*from w ww.  j a v  a2s  .  c om*/
 */
public static long getExistingContactId(Context context, Uri friendRequest) {
    String personId = null;
    try {
        String pubKeyStr = friendRequest.getQueryParameter("publicKey");
        PublicKey key = RSACrypto.publicKeyFromString(pubKeyStr);
        personId = Util.makePersonIdForPublicKey(key);
    } catch (Exception e) {
        return -1;
    }
    Uri uri = Uri.parse(DungBeetleContentProvider.CONTENT_URI + "/contacts");
    String[] projection = new String[] { Contact._ID };
    String selection = Contact.PERSON_ID + " = ?";
    String[] selectionArgs = new String[] { personId };
    String sortOrder = null;
    Cursor c = context.getContentResolver().query(uri, projection, selection, selectionArgs, sortOrder);
    if (!c.moveToFirst()) {
        return -1;
    }
    return c.getLong(0);
}

From source file:com.appnexus.opensdk.ANJAMImplementation.java

private static void callDeepLink(WebView webView, Uri uri) {
    String cb = uri.getQueryParameter("cb");
    String urlParam = uri.getQueryParameter("url");

    LinkedList<BasicNameValuePair> list = new LinkedList<BasicNameValuePair>();
    list.add(new BasicNameValuePair(KEY_CALLER, CALL_DEEPLINK));

    if ((webView.getContext() == null) || (urlParam == null)) {
        loadResult(webView, cb, list);/*  ww  w  . ja v a2  s. c o  m*/
        return;
    }
    try {
        Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(Uri.decode(urlParam)));
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        webView.getContext().startActivity(intent);
    } catch (ActivityNotFoundException e) {
        loadResult(webView, cb, list);
    }
}

From source file:com.appnexus.opensdk.ANJAMImplementation.java

private static void callExternalBrowser(WebView webView, Uri uri) {
    String urlParam = uri.getQueryParameter("url");

    if ((webView.getContext() == null) || (urlParam == null) || (!urlParam.startsWith("http"))) {
        return;//from  ww  w  .  j a  va2s . c  o  m
    }
    try {
        Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(Uri.decode(urlParam)));
        webView.getContext().startActivity(intent);
    } catch (ActivityNotFoundException e) {
        Toast.makeText(webView.getContext(), R.string.action_cant_be_completed, Toast.LENGTH_SHORT).show();
    }
}

From source file:com.appnexus.opensdk.ANJAMImplementation.java

private static void callGetDeviceID(WebView webView, Uri uri) {
    String cb = uri.getQueryParameter("cb");
    String idValue;//  w  ww.  jav  a2s  .  c  o m
    String idNameValue;

    if (!StringUtil.isEmpty(Settings.getSettings().aaid)) {
        idValue = Settings.getSettings().aaid;
        idNameValue = "aaid";
    } else {
        idValue = Settings.getSettings().hidsha1;
        idNameValue = "sha1udid";
    }

    LinkedList<BasicNameValuePair> list = new LinkedList<BasicNameValuePair>();
    list.add(new BasicNameValuePair(KEY_CALLER, CALL_GETDEVICEID));
    list.add(new BasicNameValuePair("idname", idNameValue));
    list.add(new BasicNameValuePair("id", idValue));
    loadResult(webView, cb, list);
}