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:net.sf.xfd.provider.PublicProvider.java

@Override
public Uri canonicalize(@NonNull Uri uri) {
    try {//from ww w.  j a  v  a2s.  co  m
        base.assertAbsolute(uri);

        String grantMode = uri.getQueryParameter(URI_ARG_MODE);
        if (TextUtils.isEmpty(grantMode)) {
            grantMode = "r";
        }

        verifyMac(uri, grantMode, grantMode);

        final int flags = ParcelFileDescriptor.parseMode(grantMode);

        final Context context = getContext();
        assert context != null;

        final String packageName = context.getPackageName();

        final Uri canon = DocumentsContract.buildDocumentUri(packageName + FileProvider.AUTHORITY_SUFFIX,
                canonString(uri.getPath()));

        final int callerUid = Binder.getCallingUid();

        if (callerUid != Process.myUid()) {
            int grantFlags = Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION;

            if ((flags & ParcelFileDescriptor.MODE_READ_ONLY) == flags) {
                grantFlags |= Intent.FLAG_GRANT_READ_URI_PERMISSION;
            } else if ((flags & ParcelFileDescriptor.MODE_WRITE_ONLY) == flags)
                grantFlags |= Intent.FLAG_GRANT_WRITE_URI_PERMISSION;
            else {
                grantFlags |= Intent.FLAG_GRANT_WRITE_URI_PERMISSION;
                grantFlags |= Intent.FLAG_GRANT_READ_URI_PERMISSION;
            }

            final String[] packages;

            final String caller = getCallingPackage();
            if (caller != null) {
                packages = new String[] { caller };
            } else {
                final PackageManager pm = context.getPackageManager();
                packages = pm.getPackagesForUid(callerUid);
            }

            if (packages != null) {
                for (String pkg : packages) {
                    context.grantUriPermission(pkg, canon, grantFlags);
                }
            }
        }

        return canon;
    } catch (FileNotFoundException e) {
        return null;
    }
}

From source file:org.mariotaku.twidere.provider.TwidereDataProvider.java

private void onDatabaseUpdated(final Uri uri) {
    if (uri == null)
        return;//  w  w w.j av  a 2 s . c  o m
    if ("false".equals(uri.getQueryParameter(QUERY_PARAM_NOTIFY)))
        return;
    final Context context = getContext();
    switch (getTableId(uri)) {
    case TABLE_ID_ACCOUNTS: {
        clearAccountColor();
        clearAccountName();
        context.sendBroadcast(new Intent(BROADCAST_ACCOUNT_LIST_DATABASE_UPDATED));
        break;
    }
    case TABLE_ID_DRAFTS: {
        context.sendBroadcast(new Intent(BROADCAST_DRAFTS_DATABASE_UPDATED));
        break;
    }
    case TABLE_ID_STATUSES:
    case TABLE_ID_MENTIONS:
    case TABLE_ID_DIRECT_MESSAGES_INBOX:
    case TABLE_ID_DIRECT_MESSAGES_OUTBOX: {
        notifyForUpdatedUri(context, uri);
        break;
    }
    case TABLE_ID_TRENDS_LOCAL: {
        context.sendBroadcast(new Intent(BROADCAST_TRENDS_UPDATED));
        break;
    }
    case TABLE_ID_TABS: {
        context.sendBroadcast(new Intent(BROADCAST_TABS_UPDATED));
        break;
    }
    case TABLE_ID_FILTERED_LINKS:
    case TABLE_ID_FILTERED_USERS:
    case TABLE_ID_FILTERED_KEYWORDS:
    case TABLE_ID_FILTERED_SOURCES: {
        context.sendBroadcast(new Intent(BROADCAST_FILTERS_UPDATED));
        break;
    }
    default:
        return;
    }
    context.sendBroadcast(new Intent(BROADCAST_DATABASE_UPDATED));
}

From source file:com.amazonaws.cognito.sync.demo.MainActivity.java

void retrieveTwitterCredentials(Intent intent) {

    final Uri uri = intent.getData();
    String callbackUrl = "callback://" + getString(R.string.twitter_callback_url);
    if (uri == null || !uri.toString().startsWith(callbackUrl)) {
        Log.e(TAG, "This is not our Twitter callback");
        return;/*from  ww  w. j a v a  2 s  . co m*/
    }

    new Thread(new Runnable() {
        @Override
        public void run() {
            try {
                // Get token and secret
                String verifier = uri.getQueryParameter(oauth.signpost.OAuth.OAUTH_VERIFIER);
                mOauthProvider.retrieveAccessToken(mOauthConsumer, verifier);
                String token = mOauthConsumer.getToken();
                String tokenSecret = mOauthConsumer.getTokenSecret();

                setTwitterSession(token, tokenSecret);

            } catch (Exception e) {
                Log.e("Exception", e.getMessage());
                e.printStackTrace();
            }
        }
    }).start();

}

From source file:com.krayzk9s.imgurholo.activities.MainActivity.java

private void processIntent(Intent intent) {
    String action = intent.getAction();
    String type = intent.getType();
    Log.d("New Intent", intent.toString());
    if (Intent.ACTION_SEND.equals(action) && type != null) {
        if (type.startsWith("image/")) {
            Toast.makeText(this, R.string.toast_uploading, Toast.LENGTH_SHORT).show();
            Intent serviceIntent = new Intent(this, UploadService.class);
            if (intent.getExtras() == null)
                finish();/*  ww  w  .  j av  a 2 s  .c o m*/
            serviceIntent.setData((Uri) intent.getExtras().get("android.intent.extra.STREAM"));
            startService(serviceIntent);
            finish();
        }
    } else if (Intent.ACTION_SEND_MULTIPLE.equals(action)) {
        Log.d("sending", "sending multiple");
        Toast.makeText(this, R.string.toast_uploading, Toast.LENGTH_SHORT).show();
        ArrayList<Parcelable> list = intent.getParcelableArrayListExtra(Intent.EXTRA_STREAM);
        Intent serviceIntent = new Intent(this, UploadService.class);
        serviceIntent.putParcelableArrayListExtra("images", list);
        startService(serviceIntent);
        finish();
    } else if (Intent.ACTION_VIEW.equals(action) && intent.getData().toString().startsWith("imgur-holo")) {
        Uri uri = intent.getData();
        Log.d("URI", "" + action + "/" + type);
        String uripath = "";
        if (uri != null)
            uripath = uri.toString();
        Log.d("URI", uripath);
        Log.d("URI", "HERE");

        if (uri != null && uripath.startsWith(ApiCall.OAUTH_CALLBACK_URL)) {
            apiCall.verifier = new Verifier(uri.getQueryParameter("code"));
            CallbackAsync callbackAsync = new CallbackAsync(apiCall, this);
            callbackAsync.execute();
        }
    } else if (getSupportFragmentManager().getFragments() == null) {
        loadDefaultPage();
    }
}

From source file:us.rader.wyfy.MainActivity.java

/**
 * Load the UI with the result of returned by {@link SavedRowsActivity}
 * /*from  w w  w . j av a 2 s .  c o m*/
 * @param resultCode
 *            result code
 * 
 * @param resultData
 *            <code>Intent</code> containing result data
 */
private void onLoadSavedData(int resultCode, Intent resultData) {

    if (resultCode != RESULT_OK) {

        return;

    }

    if (resultData == null) {

        return;

    }

    Uri uri = resultData.getData();

    if (uri == null) {

        return;

    }

    String ssid = uri.getQueryParameter(WiFiSettingsContract.WifiSettingsEntry.COLUMN_NAME_SSID);

    if (ssid == null) {

        return;

    }

    String password = uri.getQueryParameter(WiFiSettingsContract.WifiSettingsEntry.COLUMN_NAME_PASSWORD);
    String hidden = uri.getQueryParameter(WiFiSettingsContract.WifiSettingsEntry.COLUMN_NAME_HIDDEN);
    String security = uri.getQueryParameter(WiFiSettingsContract.WifiSettingsEntry.COLUMN_NAME_SECURITY);

    wifiSettings.setSsid(ssid);
    wifiSettings.setPassword(password);
    wifiSettings.setSecurity(Enum.valueOf(WifiSettings.Security.class, security));
    wifiSettings.setHidden(Boolean.valueOf(hidden));

    if (wifiSettingsFragment != null) {

        wifiSettingsFragment.onModelChanged(false);

    }
}

From source file:de.langerhans.wallet.ExchangeRatesProvider.java

@Override
public Cursor query(final Uri uri, final String[] projection, final String selection,
        final String[] selectionArgs, final String sortOrder) {
    final long now = System.currentTimeMillis();
    int provider = config.getExchangeProvider();
    boolean forceRefresh = config.getExchangeForceRefresh();
    if (forceRefresh) {
        config.setExchangeForceRefresh(false);
    }//from  ww w.j  av a2s .  c o  m

    final boolean offline = uri.getQueryParameter(QUERY_PARAM_OFFLINE) != null;

    if (!offline && (lastUpdated == 0 || now - lastUpdated > UPDATE_FREQ_MS) || forceRefresh) {
        double newDogeBtcConversion = -1;
        if ((dogeBtcConversion == -1 && newDogeBtcConversion == -1) || forceRefresh)
            newDogeBtcConversion = requestDogeBtcConversion(provider);

        if (newDogeBtcConversion != -1)
            dogeBtcConversion = newDogeBtcConversion;

        if (dogeBtcConversion == -1)
            return null;

        Map<String, ExchangeRate> newExchangeRates = null;
        if (newExchangeRates == null)
            newExchangeRates = requestExchangeRates(BITCOINAVERAGE_URL, dogeBtcConversion, userAgent,
                    BITCOINAVERAGE_SOURCE, BITCOINAVERAGE_FIELDS);
        if (newExchangeRates == null)
            newExchangeRates = requestExchangeRates(BLOCKCHAININFO_URL, dogeBtcConversion, userAgent,
                    BLOCKCHAININFO_SOURCE, BLOCKCHAININFO_FIELDS);

        if (newExchangeRates != null) {
            String providerUrl;
            switch (provider) {
            case 0:
                providerUrl = "http://www.cryptsy.com";
                break;
            case 1:
                providerUrl = "http://www.bter.com";
                break;
            default:
                providerUrl = "";
                break;
            }
            double mBTCRate = dogeBtcConversion * 1000;
            String strmBTCRate = String.format(Locale.US, "%.4f", mBTCRate).replace(',', '.');
            newExchangeRates.put("mBTC",
                    new ExchangeRate(
                            new com.dogecoin.dogecoinj.utils.ExchangeRate(Fiat.parseFiat("mBTC", strmBTCRate)),
                            providerUrl));
            newExchangeRates.put("DOGE",
                    new ExchangeRate(new com.dogecoin.dogecoinj.utils.ExchangeRate(Fiat.parseFiat("DOGE", "1")),
                            "priceofdoge.com"));
            exchangeRates = newExchangeRates;
            lastUpdated = now;

            final ExchangeRate exchangeRateToCache = bestExchangeRate(config.getExchangeCurrencyCode());
            if (exchangeRateToCache != null)
                config.setCachedExchangeRate(exchangeRateToCache);
        }
    }

    if (exchangeRates == null || dogeBtcConversion == -1)
        return null;

    final MatrixCursor cursor = new MatrixCursor(
            new String[] { BaseColumns._ID, KEY_CURRENCY_CODE, KEY_RATE_COIN, KEY_RATE_FIAT, KEY_SOURCE });

    if (selection == null) {
        for (final Map.Entry<String, ExchangeRate> entry : exchangeRates.entrySet()) {
            final ExchangeRate exchangeRate = entry.getValue();
            final com.dogecoin.dogecoinj.utils.ExchangeRate rate = exchangeRate.rate;
            final String currencyCode = exchangeRate.getCurrencyCode();
            cursor.newRow().add(currencyCode.hashCode()).add(currencyCode).add(rate.coin.value)
                    .add(rate.fiat.value).add(exchangeRate.source);
        }
    } else if (selection.equals(QUERY_PARAM_Q)) {
        final String selectionArg = selectionArgs[0].toLowerCase(Locale.US);
        for (final Map.Entry<String, ExchangeRate> entry : exchangeRates.entrySet()) {
            final ExchangeRate exchangeRate = entry.getValue();
            final com.dogecoin.dogecoinj.utils.ExchangeRate rate = exchangeRate.rate;
            final String currencyCode = exchangeRate.getCurrencyCode();
            final String currencySymbol = GenericUtils.currencySymbol(currencyCode);
            if (currencyCode.toLowerCase(Locale.US).contains(selectionArg)
                    || currencySymbol.toLowerCase(Locale.US).contains(selectionArg))
                cursor.newRow().add(currencyCode.hashCode()).add(currencyCode).add(rate.coin.value)
                        .add(rate.fiat.value).add(exchangeRate.source);
        }
    } else if (selection.equals(KEY_CURRENCY_CODE)) {
        final String selectionArg = selectionArgs[0];
        final ExchangeRate exchangeRate = bestExchangeRate(selectionArg);
        if (exchangeRate != null) {
            final com.dogecoin.dogecoinj.utils.ExchangeRate rate = exchangeRate.rate;
            final String currencyCode = exchangeRate.getCurrencyCode();
            cursor.newRow().add(currencyCode.hashCode()).add(currencyCode).add(rate.coin.value)
                    .add(rate.fiat.value).add(exchangeRate.source);
        }
    }

    return cursor;
}

From source file:com.android.contacts.common.model.ContactLoader.java

/**
 * Extracts Contact level columns from the cursor.
 *//*from   w  ww .  ja v  a2 s  .c  o  m*/
private Contact loadContactHeaderData(final Cursor cursor, Uri contactUri) {
    final String directoryParameter = contactUri.getQueryParameter(ContactsContract.DIRECTORY_PARAM_KEY);
    final long directoryId = directoryParameter == null ? Directory.DEFAULT
            : Long.parseLong(directoryParameter);
    final long contactId = cursor.getLong(ContactQuery.CONTACT_ID);
    final String lookupKey = cursor.getString(ContactQuery.LOOKUP_KEY);
    final long nameRawContactId = cursor.getLong(ContactQuery.NAME_RAW_CONTACT_ID);
    final int displayNameSource = cursor.getInt(ContactQuery.DISPLAY_NAME_SOURCE);
    final String displayName = cursor.getString(ContactQuery.DISPLAY_NAME);
    final String altDisplayName = cursor.getString(ContactQuery.ALT_DISPLAY_NAME);
    final String phoneticName = cursor.getString(ContactQuery.PHONETIC_NAME);
    final long photoId = cursor.getLong(ContactQuery.PHOTO_ID);
    final String photoUri = cursor.getString(ContactQuery.PHOTO_URI);
    final boolean starred = cursor.getInt(ContactQuery.STARRED) != 0;
    final Integer presence = cursor.isNull(ContactQuery.CONTACT_PRESENCE) ? null
            : cursor.getInt(ContactQuery.CONTACT_PRESENCE);
    final boolean sendToVoicemail = cursor.getInt(ContactQuery.SEND_TO_VOICEMAIL) == 1;
    final String customRingtone = cursor.getString(ContactQuery.CUSTOM_RINGTONE);
    final boolean isUserProfile = cursor.getInt(ContactQuery.IS_USER_PROFILE) == 1;

    Uri lookupUri;
    if (directoryId == Directory.DEFAULT || directoryId == Directory.LOCAL_INVISIBLE) {
        lookupUri = ContentUris.withAppendedId(Uri.withAppendedPath(Contacts.CONTENT_LOOKUP_URI, lookupKey),
                contactId);
    } else {
        lookupUri = contactUri;
    }

    return new Contact(mRequestedUri, contactUri, lookupUri, directoryId, lookupKey, contactId,
            nameRawContactId, displayNameSource, photoId, photoUri, displayName, altDisplayName, phoneticName,
            starred, presence, sendToVoicemail, customRingtone, isUserProfile);
}

From source file:org.mariotaku.twidere.provider.TwidereDataProvider.java

private void onNewItemsInserted(final Uri uri, final ContentValues... values) {
    if (uri == null || values == null || values.length == 0)
        return;/*  w ww .  ja  va 2 s .  c o m*/
    if ("false".equals(uri.getQueryParameter(QUERY_PARAM_NOTIFY)))
        return;
    final Context context = getContext();
    final Resources res = context.getResources();
    final NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
    switch (getTableId(uri)) {
    case TABLE_ID_STATUSES: {
        if (!mPreferences.getBoolean(PREFERENCE_KEY_NOTIFICATION_ENABLE_HOME_TIMELINE, false))
            return;
        final String message = res.getQuantityString(R.plurals.Ntweets, mNewStatusesCount, mNewStatusesCount);
        final Intent delete_intent = new Intent(BROADCAST_NOTIFICATION_CLEARED);
        final Bundle delete_extras = new Bundle();
        delete_extras.putInt(INTENT_KEY_NOTIFICATION_ID, NOTIFICATION_ID_HOME_TIMELINE);
        delete_intent.putExtras(delete_extras);
        final Intent content_intent = new Intent(context, HomeActivity.class);
        content_intent.setAction(Intent.ACTION_MAIN);
        content_intent.addCategory(Intent.CATEGORY_LAUNCHER);
        final Bundle content_extras = new Bundle();
        content_extras.putInt(INTENT_KEY_INITIAL_TAB, HomeActivity.TAB_POSITION_HOME);
        content_intent.putExtras(content_extras);
        builder.setOnlyAlertOnce(true);
        buildNotification(builder, res.getString(R.string.new_notifications), message, message,
                R.drawable.ic_stat_tweet, null, content_intent, delete_intent);
        mNotificationManager.notify(NOTIFICATION_ID_HOME_TIMELINE, builder.build());
        break;
    }
    case TABLE_ID_MENTIONS: {
        if (mPreferences.getBoolean(PREFERENCE_KEY_NOTIFICATION_ENABLE_MENTIONS, false)) {
            displayMentionsNotification(context, values);
        }
        break;
    }
    case TABLE_ID_DIRECT_MESSAGES_INBOX: {
        if (mPreferences.getBoolean(PREFERENCE_KEY_NOTIFICATION_ENABLE_DIRECT_MESSAGES, false)) {
            displayMessagesNotification(context, values);
        }
        break;
    }
    }
}

From source file:net.openid.appauth.AuthorizationRequestTest.java

@Test
public void testToUri() throws Exception {
    AuthorizationRequest request = mRequestBuilder.build();
    Uri uri = request.toUri();
    assertThat(uri.getQueryParameterNames())
            .isEqualTo(new HashSet<>(Arrays.asList(AuthorizationRequest.PARAM_CLIENT_ID,
                    AuthorizationRequest.PARAM_RESPONSE_TYPE, AuthorizationRequest.PARAM_REDIRECT_URI,
                    AuthorizationRequest.PARAM_STATE, AuthorizationRequest.PARAM_CODE_CHALLENGE,
                    AuthorizationRequest.PARAM_CODE_CHALLENGE_METHOD)));

    assertThat(uri.getQueryParameter(AuthorizationRequest.PARAM_CLIENT_ID)).isEqualTo(TEST_CLIENT_ID);
    assertThat(uri.getQueryParameter(AuthorizationRequest.PARAM_RESPONSE_TYPE))
            .isEqualTo(ResponseTypeValues.CODE);
    assertThat(uri.getQueryParameter(AuthorizationRequest.PARAM_REDIRECT_URI))
            .isEqualTo(TEST_APP_REDIRECT_URI.toString());
    assertThat(uri.getQueryParameter(AuthorizationRequest.PARAM_STATE)).isEqualTo(request.state);
    assertThat(uri.getQueryParameter(AuthorizationRequest.PARAM_CODE_CHALLENGE))
            .isEqualTo(request.codeVerifierChallenge);
    assertThat(uri.getQueryParameter(AuthorizationRequest.PARAM_CODE_CHALLENGE_METHOD))
            .isEqualTo(request.codeVerifierChallengeMethod);
}

From source file:com.zhongsou.souyue.activity.SplashActivity.java

private void wrapInterest(String str) {
    CircleResponseResultItem item = new CircleResponseResultItem();
    Uri uri = Uri.parse(str);
    if (uri != null) {
        String interest_id = uri.getQueryParameter("interestId");
        String blog_id = uri.getQueryParameter("blogId");
        String user_id = uri.getQueryParameter("userId");
        String isPrime = uri.getQueryParameter("isPrime");
        String top_status = uri.getQueryParameter("isTop");
        try {//w  ww.  j a v  a2  s . c  o  m
            item.setBlog_id(Long.valueOf(blog_id));
            item.setType(Integer.valueOf(uri.getQueryParameter("type")));
            item.setInterest_id(Long.valueOf(interest_id));
            item.setIs_prime(Integer.valueOf(isPrime));
            item.setTop_status(Integer.valueOf(top_status));
            item.setUser_id(Long.valueOf(user_id));
        } catch (NumberFormatException e) {
            e.printStackTrace();
        }
        pushInfo.setInterestBlog(item);
    }
}