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.gh4a.activities.DiffViewerActivity.java

@Override
protected boolean handleUrlLoad(String url) {
    if (!url.startsWith("comment://")) {
        return false;
    }/*from w ww.j  av a  2  s. c om*/

    Uri uri = Uri.parse(url);
    int line = Integer.parseInt(uri.getQueryParameter("position"));
    String lineText = Html.fromHtml(mDiffLines[line]).toString();
    String idParam = uri.getQueryParameter("id");
    long id = idParam != null ? Long.parseLong(idParam) : 0L;

    if (idParam == null) {
        openCommentDialog(id, lineText, line);
    } else {
        CommentActionPopup p = new CommentActionPopup(id, line, lineText, mLastTouchDown.x, mLastTouchDown.y);
        p.show();
    }
    return true;
}

From source file:menion.android.whereyougo.gui.activity.MainActivity.java

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

    checkPermissions();/*from   w  ww . j  a v  a  2s.c o  m*/

    if (Intent.ACTION_VIEW.equals(getIntent().getAction())) {
        Intent intent = new Intent(getIntent());
        intent.setClass(this, DownloadCartridgeActivity.class);
        startActivity(intent);
        finish();
    } else if (Intent.ACTION_SEND.equals(getIntent().getAction())) {
        try {
            Uri uri = Uri.parse(getIntent().getStringExtra(Intent.EXTRA_TEXT));
            if (uri.getQueryParameter("CGUID") == null)
                throw new Exception("Invalid URL");
            Intent intent = new Intent(this, DownloadCartridgeActivity.class);
            intent.setData(uri);
            startActivity(intent);
        } catch (Exception e) {
            ManagerNotify.toastShortMessage(this, getString(R.string.invalid_url));
        }
        finish();
    } else {
        String cguid = getIntent() == null ? null : getIntent().getStringExtra("cguid");
        if (cguid != null) {
            File file = FileSystem.findFile(cguid);
            if (file != null) {
                openCartridge(file);
            }
        }
    }
}

From source file:de.schildbach.wallet.data.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();

        if (newExchangeRates != null) {
            exchangeRates = newExchangeRates;
            lastUpdated = now;/*from  www.  j a  va  2 s  .c  om*/

            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:net.eledge.android.europeana.gui.activity.SearchActivity.java

private void handleIntent(Intent intent) {
    String query = null;/*from w w w.j  av a  2 s.  com*/
    String[] qf = null;
    if (intent != null) {

        if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
            query = intent.getStringExtra(SearchManager.QUERY);
            qf = splitFacets(intent.getStringExtra(SearchManager.USER_QUERY));
        } else if (NfcAdapter.ACTION_NDEF_DISCOVERED.equals(getIntent().getAction())) {
            Parcelable[] parcelables = intent.getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES);
            NdefMessage msg = (NdefMessage) parcelables[0];
            Uri uri = Uri.parse(new String(msg.getRecords()[0].getPayload()));
            query = uri.getQueryParameter("query");
            qf = StringArrayUtils.toArray(uri.getQueryParameters("qf"));
        } else if (Intent.ACTION_VIEW.equals(intent.getAction())) {
            query = intent.getDataString();
            if (!TextUtils.isEmpty(query)) {
                if (StringUtils.contains(query, "europeana.eu/")) {
                    Uri uri = Uri.parse(query);
                    query = uri.getQueryParameter("query");
                    qf = StringArrayUtils.toArray(uri.getQueryParameters("qf"));
                }
            }
        } else {
            // no search action recognized? end this activity...
            closeSearchActivity();
        }
        if (!TextUtils.isEmpty(query) && !TextUtils.equals(runningSearch, query)) {
            runningSearch = query;
            if (StringArrayUtils.isNotBlank(qf)) {
                searchController.newSearch(this, query, qf);
            } else {
                searchController.newSearch(this, query);
            }
            getSupportActionBar().setTitle(searchController.getSearchTitle(this));
        }
    }
}

From source file:com.androidquery.simplefeed.fragments.NotificationFragment.java

private String getStoryId(FeedItem item, String link) {

    String result = null;//from   ww  w. j a  v  a2  s .  c o m

    try {

        Uri uri = Uri.parse(link);
        String sid = uri.getQueryParameter("story_fbid");
        String id = uri.getQueryParameter("id");

        if (sid != null && id != null) {
            result = id + "_" + sid;
        }

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

    return result;
}

From source file:org.iota.wallet.ui.activity.MainActivity.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    switch (requestCode) {
    case Constants.REQUEST_CODE_LOGIN:
        inputManager.hideSoftInputFromWindow(getWindow().getDecorView().getWindowToken(), 0);
        navigationView.getMenu().performIdentifierAction(R.id.nav_wallet, 0);
    }//from  w w w  . ja v  a 2s . c o m
    if (data != null) {
        if (Intent.ACTION_VIEW.equals(data.getAction())) {
            QRCode qrCode = new QRCode();
            Uri uri = data.getData();
            qrCode.setAddress(uri.getQueryParameter("address:"));
            qrCode.setAddress(uri.getQueryParameter("amount:"));
            qrCode.setAddress(uri.getQueryParameter("message:"));

            Bundle bundle = new Bundle();
            bundle.putParcelable(Constants.QRCODE, qrCode);

            Fragment fragment = new NewTransferFragment();
            fragment.setArguments(bundle);
            showFragment(fragment, true);
        }
    }
}

From source file:com.androidquery.simplefeed.fragments.NotificationFragment.java

private String getProfileId(String link, Uri uri) {

    if (link.contains("profile")) {
        return uri.getQueryParameter("id");
    }//  w w w  .ja  va 2  s  .  co  m

    return null;
}

From source file:com.robertszkutak.androidexamples.tumblrexample.TumblrExampleActivity.java

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

    if (auth == false) {
        if (browser == true)
            browser2 = true;/* w  w  w .  j  a va 2 s.  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("TUMBLR_OAUTH_TOKEN", token);
                    editor.putString("TUMBLR_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();
                }
            }
        }
    } else {
        setContentView(R.layout.main);

        blogname = (EditText) findViewById(R.id.blogname);
        posttitle = (EditText) findViewById(R.id.posttitle);
        poststring = (EditText) findViewById(R.id.post);
        debugStatus = (TextView) findViewById(R.id.debug_status);
        post = (Button) findViewById(R.id.btn_post);
        loginorout = (Button) findViewById(R.id.loginorout);

        blogname.setText(pref.getString("TUMBLR_BLOG_NAME", ""));

        debug = "Access Token: " + token + "\n\nAccess Token Secret: " + secret;
        debugStatus.setText(debug);

        post.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                if (isAuthenticated()) {
                    saveBlogName();
                    sendPost();
                } else {
                    Toast toast = Toast.makeText(getApplicationContext(), "You are not logged into Tumblr",
                            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:tw.jwzhuang.ipcamviewer.devices.CaptureActivity.java

@Override
protected void onResume() {
    super.onResume();

    // CameraManager must be initialized here, not in onCreate(). This is
    // necessary because we don't
    // want to open the camera driver and measure the screen size if we're
    // going to show the help on
    // first launch. That led to bugs where the scanning rectangle was the
    // wrong size and partially
    // off screen.
    cameraManager = new CameraManager(getApplication());

    viewfinderView = (ViewfinderView) findViewById(R.id.viewfinder_view);
    viewfinderView.setCameraManager(cameraManager);

    handler = null;/*from  w w  w . j a va  2 s.c  o  m*/
    lastResult = null;

    resetStatusView();

    SurfaceView surfaceView = (SurfaceView) findViewById(R.id.preview_view);
    SurfaceHolder surfaceHolder = surfaceView.getHolder();
    if (hasSurface) {
        // The activity was paused but not stopped, so the surface still
        // exists. Therefore
        // surfaceCreated() won't be called, so init the camera here.
        initCamera(surfaceHolder);
    } else {
        // Install the callback and wait for surfaceCreated() to init the
        // camera.
        surfaceHolder.addCallback(this);
        surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
    }

    inactivityTimer.onResume();

    Intent intent = getIntent();

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
    copyToClipboard = prefs.getBoolean(Contant.KEY_COPY_TO_CLIPBOARD, true)
            && (intent == null || intent.getBooleanExtra(Intents.Scan.SAVE_HISTORY, true));

    source = IntentSource.NONE;
    decodeFormats = null;
    characterSet = null;

    if (intent != null) {

        String action = intent.getAction();
        String dataString = intent.getDataString();

        if (Intents.Scan.ACTION.equals(action)) {

            // Scan the formats the intent requested, and return the result
            // to the calling activity.
            source = IntentSource.NATIVE_APP_INTENT;
            decodeFormats = DecodeFormatManager.parseDecodeFormats(intent);

            if (intent.hasExtra(Intents.Scan.WIDTH) && intent.hasExtra(Intents.Scan.HEIGHT)) {
                int width = intent.getIntExtra(Intents.Scan.WIDTH, 0);
                int height = intent.getIntExtra(Intents.Scan.HEIGHT, 0);
                if (width > 0 && height > 0) {
                    cameraManager.setManualFramingRect(width, height);
                }
            }

        } else if (dataString != null && dataString.contains(PRODUCT_SEARCH_URL_PREFIX)
                && dataString.contains(PRODUCT_SEARCH_URL_SUFFIX)) {

            // Scan only products and send the result to mobile Product
            // Search.
            source = IntentSource.PRODUCT_SEARCH_LINK;
            sourceUrl = dataString;
            decodeFormats = DecodeFormatManager.PRODUCT_FORMATS;

        } else if (isZXingURL(dataString)) {

            // Scan formats requested in query string (all formats if none
            // specified).
            // If a return URL is specified, send the results there.
            // Otherwise, handle it ourselves.
            source = IntentSource.ZXING_LINK;
            sourceUrl = dataString;
            Uri inputUri = Uri.parse(sourceUrl);
            inputUri.getQueryParameter(RETURN_URL_PARAM);
            decodeFormats = DecodeFormatManager.parseDecodeFormats(inputUri);

        }

        characterSet = intent.getStringExtra(Intents.Scan.CHARACTER_SET);

    }
}

From source file:com.freerdp.freerdpcore.services.LibFreeRDP.java

public static boolean setConnectionInfo(Context context, long inst, Uri openUri) {
    ArrayList<String> args = new ArrayList<>();

    // Parse URI from query string. Same key overwrite previous one
    // freerdp://user@ip:port/connect?sound=&rfx=&p=password&clipboard=%2b&themes=-

    // Now we only support Software GDI
    args.add(TAG);//from   www  . j  a  v  a2 s  .  c  o  m
    args.add("/gdi:sw");

    final String clientName = ApplicationSettingsActivity.getClientName(context);
    if (!clientName.isEmpty()) {
        args.add("/client-hostname:" + clientName);
    }

    // Parse hostname and port. Set to 'v' argument
    String hostname = openUri.getHost();
    int port = openUri.getPort();
    if (hostname != null) {
        hostname = hostname + ((port == -1) ? "" : (":" + String.valueOf(port)));
        args.add("/v:" + hostname);
    }

    String user = openUri.getUserInfo();
    if (user != null) {
        args.add("/u:" + user);
    }

    for (String key : openUri.getQueryParameterNames()) {
        String value = openUri.getQueryParameter(key);

        if (value.isEmpty()) {
            // Query: key=
            // To freerdp argument: /key
            args.add("/" + key);
        } else if (value.equals("-") || value.equals("+")) {
            // Query: key=- or key=+
            // To freerdp argument: -key or +key
            args.add(value + key);
        } else {
            // Query: key=value
            // To freerdp argument: /key:value
            if (key.equals("drive") && value.equals("sdcard")) {
                // Special for sdcard redirect
                String path = android.os.Environment.getExternalStorageDirectory().getPath();
                value = "sdcard," + path;
            }

            args.add("/" + key + ":" + value);
        }
    }

    String[] arrayArgs = args.toArray(new String[args.size()]);
    return freerdp_parse_arguments(inst, arrayArgs);
}