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:jp.bugscontrol.github.GithubLogin.java

@Override
protected void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    final Uri data = getIntent().getData();
    if (data != null) {
        final String responseState = data.getQueryParameter("state");
        if (state.equals(responseState)) {
            final String code = data.getQueryParameter("code");
            new OauthTask(code).execute();
        } else {//w ww. j  a  v a  2 s .c  o m
            // TODO give feedback to the user
            finish();
        }
        return;
    }

    state = String.valueOf(UUID.randomUUID().hashCode());
    final String githubUrl = "https://github.com/login/oauth/authorize?scope=user,repo&client_id=" + CLIENT_ID
            + "&state=" + state;
    startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(githubUrl)));
}

From source file:com.barryku.android.boxnet.AuthActivity.java

/** Called when the activity is first created. */
@Override/*  ww  w .  jav a  2s .c o m*/
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);

    Intent intent = getIntent();
    if (BOX_INTENT_SCHEME.equals(intent.getScheme())) {
        Uri uri = intent.getData();
        Log.d(LOG_TAG, "processing auth callback: " + uri);
        String authToken = uri.getQueryParameter("auth_token");
        if (authToken != null) {
            SharedPreferences.Editor editor = prefs.edit();
            editor.putString(AUTH_TOKEN_KEY, authToken);
            editor.commit();
        }
    }
    Button login = (Button) findViewById(R.id.btnLogin);
    login.setOnClickListener(new OnClickListener() {

        public void onClick(View v) {
            String requestToken = getRequestToken();
            Log.d(LOG_TAG, requestToken);
            Intent authIntent = new Intent("android.intent.action.VIEW",
                    Uri.parse(getString(R.string.auth_uri) + requestToken));
            startActivity(authIntent);
        }

        private String getRequestToken() {
            RestTemplate restTemplate = RestUtil.getRestTemplate();
            RequestToken resp = restTemplate.getForObject(getString(R.string.request_uri), RequestToken.class,
                    getString(R.string.api_key));
            return resp.getRequestToken();
        }
    });
}

From source file:com.davidivins.checkin4me.gowalla.GowallaOAuthConnector.java

/**
 * storeNecessaryAuthorizationResponseData
 * /* w w  w .  jav  a  2s  . co  m*/
 * @param persistent_storage_editor
 * @param response
 */
public void storeNecessaryAuthorizationResponseData(Editor persistent_storage_editor, Uri response) {
    Log.i(TAG, "code = " + response.getQueryParameter("code"));
    persistent_storage_editor.putString("gowalla_code", response.getQueryParameter("code"));
    persistent_storage_editor.commit();
}

From source file:com.davidivins.checkin4me.foursquare.FoursquareOAuthConnector.java

/**
 * storeNecessaryAuthorizationResponseData
 * //from   ww w. j  a va  2  s.  co  m
 * @param persistent_storage_editor
 * @param response
 */
public void storeNecessaryAuthorizationResponseData(Editor persistent_storage_editor, Uri response) {
    Log.i(TAG, "code = " + response.getQueryParameter("code"));
    persistent_storage_editor.putString("foursquare_code", response.getQueryParameter("code"));
    persistent_storage_editor.commit();
}

From source file:com.btmura.android.reddit.app.LoginFragment.java

boolean handleOAuthRedirectUrl(String url) {
    Uri uri = Uri.parse(url);

    String error = uri.getQueryParameter("error");
    if (!TextUtils.isEmpty(error)) {
        if (listener != null) {
            listener.onLoginCancelled();
        }/*ww  w.  j av  a 2  s  .co m*/
        return true;
    }

    String state = uri.getQueryParameter("state");
    String code = uri.getQueryParameter("code");
    if (TextUtils.equals(state, getExpectedStateTokenArg()) && !TextUtils.isEmpty(code)) {
        if (listener != null) {
            listener.onLoginSuccess(code);
        }
        return true;
    }

    return false;
}

From source file:mobisocial.musubi.social.QRInviteDialog.java

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);

    Activity context = getActivity();/*  ww w . j av a  2  s  .  c om*/
    getDialog().setTitle("Exchange Info");
    // This assumes the view is full screen, which is a bad assumption
    WindowManager manager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display display = manager.getDefaultDisplay();
    int width = display.getWidth();
    int height = display.getHeight();
    int smallerDimension = width < height ? width : height;

    Uri uri = EmailInviteActivity.getInvitationUrl(context);
    if (uri.getQueryParameter("n") == null) {
        Toast.makeText(getActivity(), "You must set up an account and a enter a name to connect with friends.",
                Toast.LENGTH_LONG).show();
        dismiss();
        return;
    }
    if (uri.getQueryParameter("t") == null) {
        dismiss();
        Toast.makeText(getActivity(), "No identities to share", Toast.LENGTH_SHORT).show();
        return;
    }
    Intent intent = new Intent(Intents.Encode.ACTION);
    intent.setClass(getActivity(), QRInviteDialog.class);
    intent.putExtra(Intents.Encode.TYPE, Contents.Type.TEXT);
    intent.putExtra(Intents.Encode.DATA, uri.toString());

    try {
        qrCodeEncoder = new QRCodeEncoder(context, intent, smallerDimension);
        //setTitle(getString(R.string.app_name) + " - " + qrCodeEncoder.getTitle());
        Bitmap bitmap = qrCodeEncoder.encodeAsBitmap();
        ImageView image = (ImageView) view.findViewById(R.id.image_view);
        image.setImageBitmap(bitmap);
        TextView contents = (TextView) view.findViewById(R.id.contents_text_view);
        contents.setText(qrCodeEncoder.getDisplayContents());
        view.findViewById(R.id.ok_button).setOnClickListener(mCameraListener);
    } catch (WriterException e) {
        Log.e(TAG, "Could not encode barcode", e);
        showErrorMessage(R.string.msg_encode_contents_failed);
        qrCodeEncoder = null;
    } catch (IllegalArgumentException e) {
        Log.e(TAG, "Could not encode barcode", e);
        showErrorMessage(R.string.msg_encode_contents_failed);
        qrCodeEncoder = null;
    }
}

From source file:com.digipom.manteresting.android.processor.json.JsonProcessor.java

public final Meta executeMethodAndApply() throws RestException {
    try {//ww  w.j a v a  2s.c o m
        final Meta metaToReturn = new Meta();
        final byte[] response = method.executeGet();
        final JSONObject object = new JSONObject(new String(response));
        final JSONObject meta = object.getJSONObject("meta");
        final String next = meta.getString("next");
        final JSONArray objects = object.getJSONArray("objects");
        final int objectsLength = objects.length();

        if (next != null) {
            try {
                final Uri nextUri = Uri.parse(next);

                final int nextOffset = Integer.parseInt(nextUri.getQueryParameter("offset"));
                final int nextLimit = Integer.parseInt(nextUri.getQueryParameter("limit"));

                metaToReturn.count = objectsLength;
                metaToReturn.nextOffset = nextOffset;
                metaToReturn.nextLimit = nextLimit;
            } catch (NumberFormatException e) {
                throw new RestException("Problem parsing meta 'next' URL");
            }
        }

        int greatestId = Integer.MIN_VALUE;
        int smallestId = Integer.MAX_VALUE;

        try {
            for (int i = 0; i < objectsLength; i++) {
                final int currentId = Integer.parseInt(objects.getJSONObject(i).getString("id"));

                if (greatestId < currentId)
                    greatestId = currentId;
                if (smallestId > currentId)
                    smallestId = currentId;
            }
        } catch (NumberFormatException e) {
            throw new RestException("Problem parsing ids");
        }

        metaToReturn.greatestId = greatestId;
        metaToReturn.smallestId = smallestId;

        final ArrayList<ContentProviderOperation> batch = parse(object, metaToReturn);
        resolver.applyBatch(ManterestingContract.CONTENT_AUTHORITY, batch);
        return metaToReturn;
    } catch (RemoteException e) {
        throw new RestException("Problem applying batch operation", e);
    } catch (OperationApplicationException e) {
        throw new RestException("Problem applying batch operation", e);
    } catch (JSONException e) {
        throw new RestException("Problem parsing JSON", e);
    } catch (ClientProtocolException e) {
        throw new RestException("Problem sending request", e);
    } catch (IOException e) {
        throw new RestException("Problem sending request", e);
    }
}

From source file:com.ubikod.capptain.android.sdk.track.CapptainTrackReceiver.java

@Override
public void onReceive(Context context, Intent intent) {
    /* Once the application identifier is known */
    if ("com.ubikod.capptain.intent.action.APPID_GOT".equals(intent.getAction())) {
        /* Init the tracking agent */
        String appId = intent.getStringExtra("appId");
        CapptainTrackAgent.getInstance(context).onAppIdGot(appId);
    }/*w ww  .  ja v  a2 s  . c  om*/

    /* During installation, an install referrer may be triggered */
    else if ("com.android.vending.INSTALL_REFERRER".equals(intent.getAction())) {
        /* Forward this action to configured receivers */
        String forwardList = CapptainUtils.getMetaData(context)
                .getString("capptain:track:installReferrerForwardList");
        if (forwardList != null)
            for (String component : forwardList.split(","))
                if (!component.equals(getClass().getName())) {
                    Intent clonedIntent = new Intent(intent);
                    clonedIntent.setComponent(new ComponentName(context, component));
                    context.sendBroadcast(clonedIntent);
                }

        /* Guess store from referrer */
        String referrer = Uri.decode(intent.getStringExtra("referrer"));
        String store;

        /* GetJar uses an opaque string always starting with z= */
        if (referrer.startsWith("z="))
            store = "GetJar";

        /* Assume Android Market otherwise */
        else
            store = "Android Market";

        /* Look for a source parameter */
        Uri uri = Uri.parse("a://a?" + referrer);
        String source = uri.getQueryParameter("utm_source");

        /*
         * Skip "androidmarket" source, this is the default one when not set or installed via web
         * Android Market.
         */
        if ("androidmarket".equals(source))
            source = null;

        /* Send app info to register store/source */
        Bundle appInfo = new Bundle();
        appInfo.putString("store", store);
        if (source != null) {
            /* Parse source, if coming from capptain, it may be a JSON complex object */
            try {
                /* Convert JSON to bundle (just flat strings) */
                JSONObject jsonInfo = new JSONObject(source);
                Iterator<?> keyIt = jsonInfo.keys();
                while (keyIt.hasNext()) {
                    String key = keyIt.next().toString();
                    appInfo.putString(key, jsonInfo.getString(key));
                }
            } catch (JSONException jsone) {
                /* Not an object, process as a string */
                appInfo.putString("source", source);
            }
        }

        /* Send app info */
        CapptainAgent.getInstance(context).sendAppInfo(appInfo);
    }
}

From source file:org.kepennar.android.client.social.twitter.TwitterWebOAuthActivity.java

@Override
public void onStart() {
    super.onStart();

    Uri uri = getIntent().getData();

    if (uri != null) {
        String oauthVerifier = uri.getQueryParameter("oauth_verifier");

        if (oauthVerifier != null) {
            getWebView().clearView();//from ww w .j  a  va2  s .c  om
            new TwitterPostConnectTask().execute(oauthVerifier);
        }
    } else {
        new TwitterPreConnectTask().execute();
    }
}

From source file:it.reyboz.bustorino.ActivityMain.java

/**
 * Try to extract the bus stop ID from a URi
 *
 * @param uri The URL/*from   w w w  .  ja  va 2s .  c  om*/
 * @return bus stop ID or null
 */
public static String getBusStopIDFromUri(Uri uri) {
    String busStopID;

    // everithing catches fire when passing null to a switch.
    String host = uri.getHost();
    if (host == null) {
        Log.e("ActivityMain", "Not an URL: " + uri);
        return null;
    }

    switch (host) {
    case "m.gtt.to.it":
        // http://m.gtt.to.it/m/it/arrivi.jsp?n=1254
        busStopID = uri.getQueryParameter("n");
        if (busStopID == null) {
            Log.e("ActivityMain", "Expected ?n from: " + uri);
        }
        break;
    case "www.gtt.to.it":
    case "gtt.to.it":
        // http://www.gtt.to.it/cms/percorari/arrivi?palina=1254
        busStopID = uri.getQueryParameter("palina");
        if (busStopID == null) {
            Log.e("ActivityMain", "Expected ?palina from: " + uri);
        }
        break;
    default:
        Log.e("ActivityMain", "Unexpected intent URL: " + uri);
        busStopID = null;
    }
    return busStopID;
}