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:com.androidquery.simplefeed.activity.ImageActivity.java

private String extractAlbum(FeedItem item) {

    String link = item.getLink();
    if (link == null)
        return null;

    String result = null;//from www  .  j a va2 s .c o  m

    try {

        Uri uri = Uri.parse(link);

        String set = uri.getQueryParameter("set");

        if (set != null) {
            String[] splits = set.split("\\.");
            return splits[1];
        }

    } catch (Exception e) {
        AQUtility.report(e);
    }

    return result;

}

From source file:de.persoapp.android.activity.AuthenticateActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.frame_layout); // we need this empty frame, otherwise Crouton may render its croutons wrong

    // default value
    setResult(RESULT_CANCELED);/*from w w  w .  j a  va2  s .c  om*/

    Uri uri = getIntent().getData();
    mTcUrl = uri != null ? uri.getQueryParameter(TC_TOKEN_PARAMETER) : null;

    if (mTcUrl == null) {
        // skip whole life cycle
        Toast.makeText(this, R.string.invalid_request, Toast.LENGTH_LONG).show();
        finish();
        return;
    }

    if (savedInstanceState == null) {

        if (!mDeviceStateTester.needsToShowOtherContent(R.id.frameLayout)) {
            startAuthentication();
        }

    } else {
        mPin = savedInstanceState.getByteArray(PIN_KEY);
        mResultChat = savedInstanceState.getLong(RESULT_CHAT_KEY);
    }
}

From source file:com.odesk.example_odeskapi.MyActivity.java

/**
 * Callback once we are done with the authorization of this app
 * @param intent/*ww w  .  ja v a  2  s. c om*/
 */
@Override
public void onNewIntent(Intent intent) {
    super.onNewIntent(intent);

    // Verify OAuth callback
    Uri uri = intent.getData();
    if (uri != null && uri.getScheme().equals(OAUTH_CALLBACK_SCHEME)) {
        String verifier = uri.getQueryParameter(OAuth.OAUTH_VERIFIER);

        new ODeskRetrieveAccessTokenTask().execute(verifier);
    }
}

From source file:com.upwork.example_upworkapi.MyActivity.java

/**
 * Callback once we are done with the authorization of this app
 * @param intent//from  w w  w .jav a 2s  .  c om
 */
@Override
public void onNewIntent(Intent intent) {
    super.onNewIntent(intent);

    // Verify OAuth callback
    Uri uri = intent.getData();
    if (uri != null && uri.getScheme().equals(OAUTH_CALLBACK_SCHEME)) {
        String verifier = uri.getQueryParameter(OAuth.OAUTH_VERIFIER);

        new UpworkRetrieveAccessTokenTask().execute(verifier);
    }
}

From source file:de.vanita5.twittnuker.activity.support.MapViewerActivity.java

@Override
protected void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getActionBar().setDisplayHomeAsUpEnabled(true);
    final Uri uri = getIntent().getData();
    if (uri == null || !AUTHORITY_MAP.equals(uri.getAuthority())) {
        finish();// w  w w .ja  v a  2  s  . co m
        return;
    }
    final Bundle bundle = new Bundle();
    final String param_lat = uri.getQueryParameter(QUERY_PARAM_LAT);
    final String param_lng = uri.getQueryParameter(QUERY_PARAM_LNG);
    if (param_lat == null || param_lng == null) {
        finish();
        return;
    }
    try {
        bundle.putDouble(EXTRA_LATITUDE, Double.valueOf(param_lat));
        bundle.putDouble(EXTRA_LONGITUDE, Double.valueOf(param_lng));
    } catch (final NumberFormatException e) {
        finish();
        return;
    }
    final Fragment fragment = isNativeMapSupported() ? new NativeMapFragment() : new WebMapFragment();
    fragment.setArguments(bundle);
    final FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
    ft.replace(android.R.id.content, fragment).commit();
}

From source file:net.sf.fdshare.BaseProvider.java

@Override
public String getType(Uri uri) {
    if (TextUtils.isEmpty(uri.getPath()))
        return null;

    final String forcedType = uri.getQueryParameter("type");
    if (!TextUtils.isEmpty(forcedType)) {
        return "null".equals(forcedType) ? null : forcedType;
    } else {/*from   ww  w. j a va 2  s .  co m*/
        final TimestampedMime guess = guessTypeInternal(uri.getPath());
        return guess.mime.length == 0 ? null : guess.mime[0];
    }
}

From source file:com.dwdesign.tweetings.activity.MapViewerActivity.java

@Override
protected void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.map_viewer);
    final Uri uri = getIntent().getData();
    if (uri == null || !AUTHORITY_MAP.equals(uri.getAuthority())) {
        finish();/*  ww w  .j a  va 2 s .  c  om*/
        return;
    }
    final Bundle bundle = new Bundle();
    final String param_lat = uri.getQueryParameter(QUERY_PARAM_LAT);
    final String param_lng = uri.getQueryParameter(QUERY_PARAM_LNG);
    if (param_lat == null || param_lng == null) {
        finish();
        return;
    }
    try {
        bundle.putDouble(INTENT_KEY_LATITUDE, Double.valueOf(param_lat));
        bundle.putDouble(INTENT_KEY_LONGITUDE, Double.valueOf(param_lng));
    } catch (final NumberFormatException e) {
        finish();
        return;
    }
    mFragment = isNativeMapSupported() ? new NativeMapFragment() : new WebMapFragment();
    mFragment.setArguments(bundle);
    final FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
    ft.replace(R.id.map_frame, mFragment).commit();
}

From source file:me.philio.disqus.AuthorizeFragment.java

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    mWebView = (WebView) view.findViewById(R.id.disqus_authorize_webview);

    // Setup custom client to catch the redirect
    mWebView.setWebViewClient(new WebViewClient() {
        @Override//w ww .  ja  va2 s .com
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            if (url.startsWith(mRedirectUri)) {
                // Get fragment from url
                Log.d(TAG, "Processing redirect: " + url);
                Uri uri = Uri.parse(url);
                String uriFragment = uri.getFragment();

                // Extract data from fragment and pass to callback
                Uri queryUri = new Uri.Builder().encodedQuery(uriFragment).build();
                AccessToken accessToken = new AccessToken();
                accessToken.username = queryUri.getQueryParameter(DisqusConstants.PARAM_USERNAME);
                accessToken.userId = Long.parseLong(queryUri.getQueryParameter(DisqusConstants.PARAM_USER_ID));
                accessToken.accessToken = queryUri.getQueryParameter(DisqusConstants.PARAM_ACCESS_TOKEN);
                accessToken.expiresIn = Long
                        .parseLong(queryUri.getQueryParameter(DisqusConstants.PARAM_EXPIRES_IN));
                accessToken.tokenType = queryUri.getQueryParameter(DisqusConstants.PARAM_TOKEN_TYPE);
                accessToken.state = queryUri.getQueryParameter(DisqusConstants.PARAM_STATE);
                accessToken.scope = queryUri.getQueryParameter(DisqusConstants.PARAM_SCOPE);
                mListener.onSuccess(accessToken);
                return true;
            }
            return super.shouldOverrideUrlLoading(view, url);
        }
    });

    // Load authorize url
    String scope = AuthorizeUtils.buildScope(mScopes);
    Uri uri = AuthorizeUtils.buildAuthorizeUri(mApiKey, scope, mRedirectUri);
    Log.d(TAG, "Loading authorize url: " + uri.toString());
    mWebView.loadUrl(uri.toString());
}

From source file:org.mariotaku.twidere.receiver.NotificationReceiver.java

@Override
public void onReceive(Context context, Intent intent) {
    final String action = intent.getAction();
    if (action == null)
        return;/*from w  w  w  . j  av  a2 s  .  co m*/
    switch (action) {
    case BROADCAST_NOTIFICATION_DELETED: {
        final Uri uri = intent.getData();
        if (uri == null)
            return;
        DependencyHolder holder = DependencyHolder.get(context);
        @NotificationType
        final String notificationType = uri.getQueryParameter(QUERY_PARAM_NOTIFICATION_TYPE);
        final UserKey accountKey = UserKey.valueOf(uri.getQueryParameter(QUERY_PARAM_ACCOUNT_KEY));
        final long itemId = NumberUtils.toLong(UriExtraUtils.getExtra(uri, "item_id"), -1);
        final long itemUserId = NumberUtils.toLong(UriExtraUtils.getExtra(uri, "item_user_id"), -1);
        final boolean itemUserFollowing = Boolean
                .parseBoolean(UriExtraUtils.getExtra(uri, "item_user_following"));
        final long timestamp = NumberUtils.toLong(uri.getQueryParameter(QUERY_PARAM_TIMESTAMP), -1);
        if (CustomTabType.NOTIFICATIONS_TIMELINE.equals(CustomTabUtils.getTabTypeAlias(notificationType))
                && accountKey != null && itemId != -1 && timestamp != -1) {
            final HotMobiLogger logger = holder.getHotMobiLogger();
            logger.log(accountKey, NotificationEvent.deleted(context, timestamp, notificationType, accountKey,
                    itemId, itemUserId, itemUserFollowing));
        }
        final ReadStateManager manager = holder.getReadStateManager();
        final String paramReadPosition, paramReadPositions;
        @ReadPositionTag
        final String tag = getPositionTag(notificationType);
        if (tag != null
                && !TextUtils.isEmpty(paramReadPosition = uri.getQueryParameter(QUERY_PARAM_READ_POSITION))) {
            final long def = -1;
            manager.setPosition(Utils.getReadPositionTagWithAccounts(tag, accountKey),
                    NumberUtils.toLong(paramReadPosition, def));
        } else if (!TextUtils.isEmpty(paramReadPositions = uri.getQueryParameter(QUERY_PARAM_READ_POSITIONS))) {
            try {
                final StringLongPair[] pairs = StringLongPair.valuesOf(paramReadPositions);
                for (StringLongPair pair : pairs) {
                    manager.setPosition(tag, pair.getKey(), pair.getValue());
                }
            } catch (NumberFormatException ignore) {

            }
        }
        break;
    }
    }
}

From source file:com.yozio.android.YozioApiServiceImplTest.java

/****************************************************************************
 * GetYozioLink tests/*from   w  w w.  j a  va  2 s  .c o m*/
 ****************************************************************************/
public void testGetYozioLinkSuccess() {
    String expectedYozioLink = "www.foobar.com";
    fakeHttpClient.setHttpResonse(createJsonHttpResponse(200, "url", expectedYozioLink));

    try {
        JSONObject externalProperties = new JSONObject("{\"a\": \"b\", \"c\": \"d\"}");
        JSONObject experimentVariationSids = new JSONObject("{\"ooga\" : \"booga\"}");
        JSONObject yozioProperties = new JSONObject("{\"e\": \"f\"}");
        yozioProperties.put("experiment_variation_sids", experimentVariationSids);

        String yozioLink = apiService.getYozioLink(APP_KEY, UDID, LOOP_NAME, DEST_URL, yozioProperties,
                externalProperties);

        Uri requestUri = fakeHttpClient.getLastRequestUri();
        JSONObject returnedExternalProperties = new JSONObject(
                requestUri.getQueryParameter("external_properties"));
        JSONObject returnedYozioProperties = new JSONObject(requestUri.getQueryParameter("yozio_properties"));

        assertEquals(externalProperties.toString(), returnedExternalProperties.toString());
        assertEquals(yozioProperties.toString(), returnedYozioProperties.toString());
        assertEquals(expectedYozioLink, yozioLink);
    } catch (JSONException e) {
        fail();
    }
}