List of usage examples for android.net Uri getQueryParameter
@Nullable
public String getQueryParameter(String key)
From source file:org.privatenotes.sync.web.SnowySyncMethod.java
public void remoteAuthComplete(final Uri uri, final Handler handler) { execInThread(new Runnable() { public void run() { try { // TODO: might be intelligent to show something like a progress dialog // else the user might try to sync before the authorization process // is complete OAuthConnection auth = SyncServer.getAuthConnection(); boolean result = auth.getAccess(uri.getQueryParameter("oauth_verifier")); if (result) { if (Tomdroid.LOGGING_ENABLED) Log.i(TAG, "The authorization process is complete."); } else { Log.e(TAG, "Something went wrong during the authorization process."); }//from ww w . j a va 2 s . c om } catch (UnknownHostException e) { Log.e(TAG, "Internet connection not available"); sendMessage(NO_INTERNET); } // We don't care what we send, just remove the dialog handler.sendEmptyMessage(0); } }); }
From source file:net.openid.appauth.AuthorizationRequestTest.java
@Test public void testToUri_loginHint() { Uri uri = mRequestBuilder.setLoginHint(TEST_EMAIL_ADDRESS).build().toUri(); assertThat(uri.getQueryParameterNames()).contains(AuthorizationRequest.PARAM_LOGIN_HINT); assertThat(uri.getQueryParameter(AuthorizationRequest.PARAM_LOGIN_HINT)).isEqualTo(TEST_EMAIL_ADDRESS); }
From source file:net.openid.appauth.AuthorizationRequestTest.java
@Test public void testToUri_scopeParam() { Uri uri = mRequestBuilder.setScope(AuthorizationRequest.Scope.EMAIL).build().toUri(); assertThat(uri.getQueryParameterNames()).contains(AuthorizationRequest.PARAM_SCOPE); assertThat(uri.getQueryParameter(AuthorizationRequest.PARAM_SCOPE)) .isEqualTo(AuthorizationRequest.Scope.EMAIL); }
From source file:net.openid.appauth.AuthorizationRequestTest.java
@Test public void testToUri_displayParam() { Uri uri = mRequestBuilder.setDisplay(AuthorizationRequest.Display.PAGE).build().toUri(); assertThat(uri.getQueryParameterNames()).contains(AuthorizationRequest.PARAM_DISPLAY); assertThat(uri.getQueryParameter(AuthorizationRequest.PARAM_DISPLAY)) .isEqualTo(AuthorizationRequest.Display.PAGE); }
From source file:net.openid.appauth.AuthorizationRequestTest.java
@Test public void testToUri_promptParam() { Uri uri = mRequestBuilder.setPrompt(AuthorizationRequest.Prompt.CONSENT).build().toUri(); assertThat(uri.getQueryParameterNames()).contains(AuthorizationRequest.PARAM_PROMPT); assertThat(uri.getQueryParameter(AuthorizationRequest.PARAM_PROMPT)) .isEqualTo(AuthorizationRequest.Prompt.CONSENT); }
From source file:com.breadwallet.tools.security.RequestHandler.java
public static void processBitIdResponse(final Activity app) { final byte[] phrase; final byte[] nulTermPhrase; final byte[] seed; if (app == null) { Log.e(TAG, "processBitIdResponse: app is null"); return;//from w ww . ja v a 2 s . c o m } if (_bitUri == null) { Log.e(TAG, "processBitIdResponse: _bitUri is null"); return; } final Uri uri = Uri.parse(_bitUri); try { phrase = KeyStoreManager.getKeyStorePhrase(app, REQUEST_PHRASE_BITID); } catch (BRKeystoreErrorException e) { Log.e(TAG, "processBitIdResponse: failed to getKeyStorePhrase: " + e.getCause().getMessage()); return; } nulTermPhrase = TypesConverter.getNullTerminatedPhrase(phrase); seed = BRWalletManager.getSeedFromPhrase(nulTermPhrase); if (seed == null) { Log.e(TAG, "processBitIdResponse: seed is null!"); return; } //run the callback new Thread(new Runnable() { @Override public void run() { try { if (_strToSign == null) { //meaning it's a link handling String nonce = null; String scheme = "https"; String query = uri.getQuery(); if (query == null) { Log.e(TAG, "run: Malformed URI"); return; } String u = uri.getQueryParameter("u"); if (u != null && u.equalsIgnoreCase("1")) { scheme = "http"; } String x = uri.getQueryParameter("x"); if (Utils.isNullOrEmpty(x)) { nonce = newNonce(app, uri.getHost() + uri.getPath()); // we are generating our own nonce } else { nonce = x; // service is providing a nonce } String callbackUrl = String.format("%s://%s%s", scheme, uri.getHost(), uri.getPath()); // build a payload consisting of the signature, address and signed uri String uriWithNonce = String.format("bitid://%s%s?x=%s", uri.getHost(), uri.getPath(), nonce); final byte[] key = BRBIP32Sequence.getInstance().bip32BitIDKey(seed, _index, callbackUrl); if (key == null) { Log.d(TAG, "processBitIdResponse: key is null!"); return; } // Log.e(TAG, "run: uriWithNonce: " + uriWithNonce); final String sig = BRBitId.signMessage(_strToSign == null ? uriWithNonce : _strToSign, new BRKey(key)); final String address = new BRKey(key).address(); JSONObject postJson = new JSONObject(); try { postJson.put("address", address); postJson.put("signature", sig); if (_strToSign == null) postJson.put("uri", uriWithNonce); } catch (JSONException e) { e.printStackTrace(); } RequestBody requestBody = RequestBody.create(null, postJson.toString()); Request request = new Request.Builder().url(callbackUrl + "?x=" + nonce).post(requestBody) .header("Content-Type", "application/json").build(); Response res = APIClient.getInstance(app).sendRequest(request, true, 0); Log.e(TAG, "processBitIdResponse: res.code: " + res.code()); Log.e(TAG, "processBitIdResponse: res.code: " + res.message()); try { Log.e(TAG, "processBitIdResponse: body: " + res.body().string()); } catch (IOException e) { e.printStackTrace(); } } else { //meaning its the wallet plugin, glidera auth String biUri = uri.getHost() == null ? uri.toString() : uri.getHost(); final byte[] key = BRBIP32Sequence.getInstance().bip32BitIDKey(seed, _index, biUri); if (key == null) { Log.d(TAG, "processBitIdResponse: key is null!"); return; } // Log.e(TAG, "run: uriWithNonce: " + uriWithNonce); final String sig = BRBitId.signMessage(_strToSign, new BRKey(key)); final String address = new BRKey(key).address(); JSONObject postJson = new JSONObject(); try { postJson.put("address", address); postJson.put("signature", sig); } catch (JSONException e) { e.printStackTrace(); } WalletPlugin.handleBitId(postJson); } } finally { //release everything _bitUri = null; _strToSign = null; _bitCallback = null; _authString = null; _index = 0; if (phrase != null) Arrays.fill(phrase, (byte) 0); if (nulTermPhrase != null) Arrays.fill(nulTermPhrase, (byte) 0); if (seed != null) Arrays.fill(seed, (byte) 0); } } }).start(); }
From source file:edu.stanford.mobisocial.dungbeetle.HandleNfcContact.java
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Intent intent = getIntent();//from ww w . j a v a2 s .co m final Uri uri = intent.getData(); setContentView(R.layout.handle_give); Button saveButton = (Button) findViewById(R.id.save_contact_button); Button cancelButton = (Button) findViewById(R.id.cancel_button); Button mutualFriendsButton = (Button) findViewById(R.id.mutual_friends_button); mutualFriendsButton.setVisibility(View.GONE); if (uri != null && (uri.getScheme().equals(HomeActivity.SHARE_SCHEME) || uri.getSchemeSpecificPart().startsWith(FriendRequest.PREFIX_JOIN))) { mEmail = uri.getQueryParameter("email"); mName = uri.getQueryParameter("name"); if (mName == null) { mName = mEmail; } TextView nameView = (TextView) findViewById(R.id.name_text); nameView.setText("Would you like to be friends with " + mName + "?"); final long cid = FriendRequest.acceptFriendRequest(HandleNfcContact.this, uri, false); saveButton.setOnClickListener(new OnClickListener() { public void onClick(View v) { DBHelper helper = DBHelper.getGlobal(HandleNfcContact.this); IdentityProvider ident = new DBIdentityProvider(helper); try { JSONObject profile = new JSONObject(ident.userProfile()); byte[] data = FastBase64.decode(profile.getString("picture")); Helpers.updatePicture(HandleNfcContact.this, data); } catch (Exception e) { } // If asymmetric friend request, send public key. if (!NfcAdapter.ACTION_NDEF_DISCOVERED.equals(getIntent().getAction())) { FriendRequest.sendFriendRequest(HandleNfcContact.this, cid, uri.getQueryParameter("cap")); } Toast.makeText(HandleNfcContact.this, "Added " + mName + " as a friend.", Toast.LENGTH_SHORT) .show(); finish(); } }); cancelButton.setOnClickListener(new OnClickListener() { public void onClick(View v) { Helpers.deleteContact(HandleNfcContact.this, cid); finish(); } }); ImageView portraitView = (ImageView) findViewById(R.id.image); if (uri != null) { /* ((App)getApplication()).contactImages.lazyLoadImage( mEmail.hashCode(), Gravatar.gravatarUri(mEmail, 100), portraitView); */ //((App)getApplication()).contactImages.lazyLoadImage(mPicture.hashCode(), mPicture, portraitView); } } else { saveButton.setEnabled(false); cancelButton.setOnClickListener(new OnClickListener() { public void onClick(View v) { finish(); } }); Toast.makeText(this, "Failed to receive contact.", Toast.LENGTH_SHORT).show(); Log.d(TAG, "Failed to handle " + uri); } }
From source file:com.google.samples.apps.iosched.myschedule.MyScheduleActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_my_schedule); // Pre-process the intent received to open this activity to determine if it was a deep // link to a SessionDetail. Typically you wouldn't use this type of logic, but we need to // because of the path of session details page on the website is only /schedule and session // ids are part of the query parameters (sid). Intent intent = getIntent();/*from ww w .j a v a 2 s . co m*/ if (intent != null && !TextUtils.isEmpty(intent.getDataString())) { // Check format against website format. String intentDataString = intent.getDataString(); try { Uri dataUri = Uri.parse(intentDataString); String sessionId = dataUri.getQueryParameter("sid"); if (!TextUtils.isEmpty(sessionId)) { Uri data = ScheduleContract.Sessions.buildSessionUri(sessionId); Intent sessionDetailIntent = new Intent(MyScheduleActivity.this, SessionDetailActivity.class); sessionDetailIntent.setData(data); startActivity(sessionDetailIntent); finish(); } LOGD(TAG, "SessionId: " + sessionId); } catch (Exception exception) { LOGE(TAG, "Data uri existing but wasn't parsable for a session detail deep link"); } } // ANALYTICS SCREEN: View the My Schedule screen // Contains: Nothing (Page name is a constant) AnalyticsHelper.sendScreenView(SCREEN_LABEL); mViewPager = (ViewPager) findViewById(R.id.view_pager); mScrollViewWide = (ScrollView) findViewById(R.id.main_content_wide); mWideMode = findViewById(R.id.my_schedule_first_day) != null; if (SettingsUtils.isAttendeeAtVenue(this)) { mDayZeroAdapter = new MyScheduleAdapter(this, getLUtils()); prepareDayZeroAdapter(); } for (int i = 0; i < Config.CONFERENCE_DAYS.length; i++) { mScheduleAdapters[i] = new MyScheduleAdapter(this, getLUtils()); } mViewPagerAdapter = new OurViewPagerAdapter(getFragmentManager()); mViewPager.setAdapter(mViewPagerAdapter); if (mWideMode) { mMyScheduleViewWide[0] = (MyScheduleView) findViewById(R.id.my_schedule_first_day); mMyScheduleViewWide[0].setAdapter(mScheduleAdapters[0]); mMyScheduleViewWide[1] = (MyScheduleView) findViewById(R.id.my_schedule_second_day); mMyScheduleViewWide[1].setAdapter(mScheduleAdapters[1]); TextView firstDayHeaderView = (TextView) findViewById(R.id.day_label_first_day); TextView secondDayHeaderView = (TextView) findViewById(R.id.day_label_second_day); if (firstDayHeaderView != null) { firstDayHeaderView.setText(getDayName(0)); } if (secondDayHeaderView != null) { secondDayHeaderView.setText(getDayName(1)); } TextView zerothDayHeaderView = (TextView) findViewById(R.id.day_label_zeroth_day); MyScheduleView dayZeroView = (MyScheduleView) findViewById(R.id.my_schedule_zeroth_day); if (mDayZeroAdapter != null) { dayZeroView.setAdapter(mDayZeroAdapter); dayZeroView.setVisibility(View.VISIBLE); zerothDayHeaderView.setText(getDayName(-1)); zerothDayHeaderView.setVisibility(View.VISIBLE); } else { dayZeroView.setVisibility(View.GONE); zerothDayHeaderView.setVisibility(View.GONE); } } else { // it's PagerAdapter set. mTabLayout = (TabLayout) findViewById(R.id.sliding_tabs); mTabLayout.setTabsFromPagerAdapter(mViewPagerAdapter); mTabLayout.setOnTabSelectedListener(new TabLayout.OnTabSelectedListener() { @Override public void onTabSelected(TabLayout.Tab tab) { mViewPager.setCurrentItem(tab.getPosition(), true); TextView view = (TextView) findViewById(baseTabViewId + tab.getPosition()); view.setContentDescription( getString(R.string.talkback_selected, getString(R.string.a11y_button, tab.getText()))); } @Override public void onTabUnselected(TabLayout.Tab tab) { TextView view = (TextView) findViewById(baseTabViewId + tab.getPosition()); view.setContentDescription(getString(R.string.a11y_button, tab.getText())); } @Override public void onTabReselected(TabLayout.Tab tab) { // Do nothing } }); mViewPager.setPageMargin(getResources().getDimensionPixelSize(R.dimen.my_schedule_page_margin)); mViewPager.setPageMarginDrawable(R.drawable.page_margin); setTabLayoutContentDescriptions(); } mButterBar = findViewById(R.id.butter_bar); removeLoginFailed(); overridePendingTransition(0, 0); addDataObservers(); }
From source file:uk.org.rivernile.edinburghbustracker.android.fragments.general.EnterStopCodeFragment.java
/** * {@inheritDoc}/*from ww w .j av a 2 s. c o m*/ */ @Override public void onActivityResult(final int requestCode, final int resultCode, final Intent data) { final Activity activity = getActivity(); // The result code signified success. if (resultCode == Activity.RESULT_OK) { // Make sure there is a data Intent. There have been some crashes // caused by this being null. if (data == null) { Toast.makeText(activity, R.string.enterstopcode_scan_error, Toast.LENGTH_LONG).show(); return; } // Get the data from the Intent. final Uri uri = Uri.parse(data.getStringExtra("SCAN_RESULT")); // We can only handle hierarchical URIs. Make sure it is so. if (!uri.isHierarchical()) { // Tell the user the URI was invalid. Toast.makeText(activity, R.string.enterstopcode_invalid_qrcode, Toast.LENGTH_LONG).show(); return; } // Get the busStopCode parameter from the URI. final String stopCode = uri.getQueryParameter("busStopCode"); // Do basic sanity checking on the parameter. if (stopCode != null && stopCode.length() > 0) { // Set the EditText to the value of this stop code. txt.setText(stopCode); // Launch bus times. callbacks.onShowBusTimes(stopCode); } else { Toast.makeText(activity, R.string.enterstopcode_invalid_qrcode, Toast.LENGTH_LONG).show(); } } }
From source file:net.openid.appauth.AuthorizationRequestTest.java
@Test public void testToUri_responseModeParam() { Uri uri = mRequestBuilder.setResponseMode(AuthorizationRequest.ResponseMode.QUERY).build().toUri(); assertThat(uri.getQueryParameterNames()).contains(AuthorizationRequest.PARAM_RESPONSE_MODE); assertThat(uri.getQueryParameter(AuthorizationRequest.PARAM_RESPONSE_MODE)) .isEqualTo(AuthorizationRequest.ResponseMode.QUERY); }