List of usage examples for android.net Uri getQueryParameter
@Nullable
public String getQueryParameter(String key)
From source file:org.mozilla.gecko.NotificationHelper.java
public void handleNotificationIntent(SafeIntent i) { final Uri data = i.getData(); if (data == null) { Log.e(LOGTAG, "handleNotificationEvent: empty data"); return;/*from w w w. j a v a2 s. co m*/ } final String id = data.getQueryParameter(ID_ATTR); final String notificationType = data.getQueryParameter(EVENT_TYPE_ATTR); if (id == null || notificationType == null) { Log.e(LOGTAG, "handleNotificationEvent: invalid intent parameters"); return; } // In case the user swiped out the notification, we empty the id set. if (CLEARED_EVENT.equals(notificationType)) { mClearableNotifications.remove(id); // If Gecko isn't running, we throw away events where the notification was cancelled. // i.e. Don't bug the user if they're just closing a bunch of notifications. if (!GeckoThread.checkLaunchState(GeckoThread.LaunchState.GeckoRunning)) { return; } } JSONObject args = new JSONObject(); // The handler and cookie parameters are optional. final String handler = data.getQueryParameter(HANDLER_ATTR); final String cookie = i.getStringExtra(COOKIE_ATTR); try { args.put(ID_ATTR, id); args.put(EVENT_TYPE_ATTR, notificationType); args.put(HANDLER_ATTR, handler); args.put(COOKIE_ATTR, cookie); if (BUTTON_EVENT.equals(notificationType)) { final String actionName = data.getQueryParameter(ACTION_ID_ATTR); args.put(ACTION_ID_ATTR, actionName); } Log.i(LOGTAG, "Send " + args.toString()); GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent("Notification:Event", args.toString())); } catch (JSONException e) { Log.e(LOGTAG, "Error building JSON notification arguments.", e); } // If the notification was clicked, we are closing it. This must be executed after // sending the event to js side because when the notification is canceled no event can be // handled. if (CLICK_EVENT.equals(notificationType) && !i.getBooleanExtra(ONGOING_ATTR, false)) { hideNotification(id, handler, cookie); } }
From source file:com.androidquery.simplefeed.fragments.NotificationFragment.java
private String extractItemId(FeedItem item, String link, Uri uri) { String result = null;/*from w w w.j a v a 2s .c o m*/ try { result = uri.getQueryParameter("fbid"); if (result == null) result = getPostId(item, link, uri); if (result == null) result = getStoryId(item, link); if (result == null) result = getNoteId(item, link, uri); if (result == null) result = getVideoId(item, link, uri); } catch (Exception e) { AQUtility.report(e); } return result; }
From source file:net.openid.appauth.AuthorizationRequestTest.java
@Test public void testToUri_additionalParams() throws Exception { Map<String, String> additionalParams = new HashMap<>(); additionalParams.put("my_param", "1234"); additionalParams.put("another_param", "5678"); AuthorizationRequest req = mRequestBuilder.setAdditionalParameters(additionalParams).build(); Uri uri = req.toUri(); assertThat(uri.getQueryParameter("my_param")).isEqualTo("1234"); assertThat(uri.getQueryParameter("another_param")).isEqualTo("5678"); }
From source file:com.robertszkutak.androidexamples.imgurexample.ImgurExampleActivity.java
@Override public void onResume() { super.onResume(); if (auth == false) { if (browser == true) browser2 = true;//from w ww . jav a 2s .c o m if (browser == false) { browser = true; newIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(authURL)); startActivity(newIntent); } if (browser2 == true) { Uri uri = getIntent().getData(); uripath = uri.toString(); if (uri != null && uripath.startsWith(OAUTH_CALLBACK_URL)) { String verifier = uri.getQueryParameter(OAuth.OAUTH_VERIFIER); try { provider.retrieveAccessToken(consumer, verifier); token = consumer.getToken(); secret = consumer.getTokenSecret(); final Editor editor = pref.edit(); editor.putString("IMGUR_OAUTH_TOKEN", token); editor.putString("IMGUR_OAUTH_TOKEN_SECRET", secret); editor.commit(); auth = true; loggedin = true; } catch (OAuthMessageSignerException e) { e.printStackTrace(); } catch (OAuthNotAuthorizedException e) { e.printStackTrace(); } catch (OAuthExpectationFailedException e) { e.printStackTrace(); } catch (OAuthCommunicationException e) { e.printStackTrace(); } } } } if (auth == true) { setContentView(R.layout.main); path = (EditText) findViewById(R.id.imagepath); debugStatus = (TextView) findViewById(R.id.debug_status); upload = (Button) findViewById(R.id.upload); loginorout = (Button) findViewById(R.id.loginout); debug = "Access Token: " + token + "\n\nAccess Token Secret: " + secret; debugStatus.setText(debug); upload.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { if (isAuthenticated()) { uploadImage(); } else { Toast toast = Toast.makeText(getApplicationContext(), "You are not logged into Imgur", Toast.LENGTH_SHORT); toast.show(); } } }); loginorout.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { LogInOrOut(); } }); updateLoginStatus(); } if (auth == false && browser2 == true) finish(); }
From source file:id.ridon.keude.Keude.java
@Override protected void onCreate(Bundle savedInstanceState) { fdroidApp = ((KeudeApp) getApplication()); fdroidApp.applyTheme(this); super.onCreate(savedInstanceState); setContentView(R.layout.fdroid);/*from w w w . j a v a 2 s.c o m*/ createViews(); getTabManager().createTabs(); // Start a search by just typing setDefaultKeyMode(DEFAULT_KEYS_SEARCH_LOCAL); Intent i = getIntent(); Uri data = i.getData(); String appid = null; if (data != null) { if (data.isHierarchical()) { // http(s)://f-droid.org/repository/browse?fdid=app.id appid = data.getQueryParameter("fdid"); } } else if (i.hasExtra(EXTRA_TAB_UPDATE)) { boolean showUpdateTab = i.getBooleanExtra(EXTRA_TAB_UPDATE, false); if (showUpdateTab) { getTabManager().selectTab(2); } } if (appid != null && appid.length() > 0) { Intent call = new Intent(this, AppDetails.class); call.putExtra(AppDetails.EXTRA_APPID, appid); startActivityForResult(call, REQUEST_APPDETAILS); } Uri uri = AppProvider.getContentUri(); getContentResolver().registerContentObserver(uri, true, new AppObserver()); }
From source file:de.schildbach.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(); final boolean offline = uri.getQueryParameter(QUERY_PARAM_OFFLINE) != null; if (!offline && (lastUpdated == 0 || now - lastUpdated > UPDATE_FREQ_MS)) { Map<String, ExchangeRate> newExchangeRates = null; if (newExchangeRates == null) newExchangeRates = requestExchangeRates(BITCOINAVERAGE_URL, userAgent, BITCOINAVERAGE_SOURCE, BITCOINAVERAGE_FIELDS); if (newExchangeRates == null) newExchangeRates = requestExchangeRates(BLOCKCHAININFO_URL, userAgent, BLOCKCHAININFO_SOURCE, BLOCKCHAININFO_FIELDS); if (newExchangeRates != null) { exchangeRates = newExchangeRates; lastUpdated = now;// w w w.j a v a2 s . com final ExchangeRate exchangeRateToCache = bestExchangeRate(config.getExchangeCurrencyCode()); if (exchangeRateToCache != null) config.setCachedExchangeRate(exchangeRateToCache); } } if (exchangeRates == null) 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 org.bitcoinj.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 org.bitcoinj.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 org.bitcoinj.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.twitter4rk.TwitterAuthFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { mTwitterWebView = new WebView(getActivity()); final Bundle args = getArguments(); if (args == null) { // This wont be case because startTwitterAuth() handles args for // fragment throw new IllegalArgumentException( "No arguments passed to fragment, Please use startTwitterAuth(...) method for showing this fragment"); }// w w w.ja va2s .com // Get builder from args mBuilder = args.getParcelable(BUILDER_KEY); // Hide action bar if (mBuilder.hideActionBar) mBuilder.activity.getActionBar().hide(); // Init progress dialog mProgressDialog = new ProgressDialog(mBuilder.activity); mProgressDialog.setMessage(mBuilder.progressText == null ? "Loading ..." : mBuilder.progressText); if (mBuilder.isProgressEnabled) mProgressDialog.show(); // Init ConfigurationBuilder twitter4j final ConfigurationBuilder cb = new ConfigurationBuilder(); if (mBuilder.isDebugEnabled) cb.setDebugEnabled(true); cb.setOAuthConsumerKey(mBuilder.consumerKey); cb.setOAuthConsumerSecret(mBuilder.consumerSecret); // Web view client to handler url loading mTwitterWebView.setWebViewClient(new WebViewClient() { @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { // Get url first final Uri uri = Uri.parse(url); // Check if we need to see for callback URL if (mBuilder.callbackUrl != null && url.contains(mBuilder.callbackUrl)) { // Get req info String oauthToken = uri.getQueryParameter("oauth_token"); String oauthVerifier = uri.getQueryParameter("oauth_verifier"); if (mListener != null) mListener.onSuccess(oauthToken, oauthVerifier); if (mBuilder.isActionBarVisible && mBuilder.hideActionBar && getActivity() != null) getActivity().getActionBar().show(); mIsAuthenticated = true; removeMe(); return true; // If no callback URL then check for info directly } else if (uri.getQueryParameter("oauth_token") != null && uri.getQueryParameter("oauth_verifier") != null) { // Get req info String oauthToken = uri.getQueryParameter("oauth_token"); String oauthVerifier = uri.getQueryParameter("oauth_verifier"); if (mListener != null) mListener.onSuccess(oauthToken, oauthVerifier); if (mBuilder.isActionBarVisible && mBuilder.hideActionBar && getActivity() != null) getActivity().getActionBar().show(); mIsAuthenticated = true; removeMe(); return true; // If nothing then its failure } else { // Notify user if (mListener != null) mListener.onFailure( new Exception("Couldn't find the callback URL or oath parameters in response")); if (mBuilder.isActionBarVisible && mBuilder.hideActionBar && getActivity() != null) getActivity().getActionBar().show(); removeMe(); return false; } } }); // Web Crome client to handler progress dialog visibility mTwitterWebView.setWebChromeClient(new WebChromeClient() { @Override public void onProgressChanged(WebView view, int newProgress) { if (newProgress == 100) { if (mProgressDialog.isShowing()) mProgressDialog.dismiss(); } } }); final Handler handler = new Handler(); new Thread(new Runnable() { @Override public void run() { try { final TwitterFactory twitterFactory = new TwitterFactory(cb.build()); final Twitter twitter = twitterFactory.getInstance(); RequestToken requestToken = null; if (mBuilder.callbackUrl == null) requestToken = twitter.getOAuthRequestToken(); else requestToken = twitter.getOAuthRequestToken(mBuilder.callbackUrl); final RequestToken finalRequestToken = requestToken; handler.post(new Runnable() { @Override public void run() { final String url = finalRequestToken.getAuthorizationURL(); mTwitterWebView.loadUrl(url); } }); } catch (TwitterException e) { e.printStackTrace(); } } }).start(); return mTwitterWebView; }
From source file:com.androidquery.simplefeed.fragments.NotificationFragment.java
private String getGroupId(String link, Uri uri) { if (link.indexOf("group.php") > 0) { String gid = uri.getQueryParameter("gid"); if (gid != null) return gid; }/*from ww w . ja v a 2 s . c o m*/ if (link.charAt(link.length() - 1) == '/') { link = link.substring(0, link.length() - 1); } AQUtility.debug("check link", link); String[] splits = link.split("/"); if (splits.length < 2) return null; String last = null; if ("groups".equals(splits[splits.length - 2])) { last = splits[splits.length - 1]; } else if ("groups".equals(splits[splits.length - 3])) { last = splits[splits.length - 2]; } if (last == null) return null; try { Long.parseLong(last); return last; } catch (NumberFormatException e) { } catch (Exception e) { AQUtility.report(e); } return null; }
From source file:com.vuze.android.remote.VuzeEasyTrackerOld.java
public Map<String, String> getReferrerMapFromUri(Uri uri) { MapBuilder paramMap = new MapBuilder(); // If no URI, return an empty Map. if (uri == null) { return paramMap.build(); }/* w w w .jav a2s . co m*/ try { // Source is the only required campaign field. No need to continue if not // present. if (uri.isHierarchical() && uri.getQueryParameter(CAMPAIGN_SOURCE_PARAM) != null) { // MapBuilder.setCampaignParamsFromUrl parses Google Analytics campaign // ("UTM") parameters from a string URL into a Map that can be set on // the Tracker. paramMap.setCampaignParamsFromUrl(uri.toString()); // If no source parameter, set authority to source and medium to // "referral". } else if (uri.getAuthority() != null && uri.getAuthority().length() > 0) { paramMap.set(Fields.CAMPAIGN_MEDIUM, "referral"); paramMap.set(Fields.CAMPAIGN_SOURCE, uri.getAuthority()); } else if (uri.getScheme() != null) { paramMap.set(Fields.CAMPAIGN_MEDIUM, uri.getScheme()); } } catch (Throwable t) { // I found: java.lang.UnsupportedOperationException: This isn't a hierarchical URI. // Fixed above with isHeirarchical, but who knows what other throws there are if (AndroidUtils.DEBUG) { t.printStackTrace(); } } return paramMap.build(); }
From source file:com.androidquery.simplefeed.fragments.NotificationFragment.java
private String getEventId(String link, Uri uri) { List<String> paths = uri.getPathSegments(); AQUtility.debug(paths);/*from www.j ava2s .c o m*/ String eid = uri.getQueryParameter("eid"); if (eid != null) { return eid; } if (paths.size() < 2) return null; if ("events".equals(paths.get(0))) { return paths.get(1); } return null; }