Example usage for android.net Uri getQuery

List of usage examples for android.net Uri getQuery

Introduction

In this page you can find the example usage for android.net Uri getQuery.

Prototype

@Nullable
public abstract String getQuery();

Source Link

Document

Gets the decoded query component from this URI.

Usage

From source file:im.vector.receiver.VectorUniversalLinkReceiver.java

@Override
public void onReceive(final Context aContext, final Intent aIntent) {
    String action, uriString;//from www.j  a  va2 s .co m
    Uri intentUri;

    Log.d(LOG_TAG, "## onReceive() IN");

    // get session
    mSession = Matrix.getInstance(aContext).getDefaultSession();

    // user is not yet logged in
    if (null == mSession) {
        Log.e(LOG_TAG, "## onReceive() Warning - Unable to proceed URL link: Session is null");

        // No user is logged => no session. Just forward request to the login activity
        Intent intent = new Intent(aContext, LoginActivity.class);
        intent.putExtra(EXTRA_UNIVERSAL_LINK_URI, aIntent.getData());
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_CLEAR_TASK
                | Intent.FLAG_ACTIVITY_NEW_TASK);
        aContext.startActivity(intent);
        return;
    }

    // sanity check
    if (null != aIntent) {

        action = aIntent.getAction();
        uriString = aIntent.getDataString();
        boolean isSessionActive = mSession.isAlive();
        boolean isLoginStepDone = mSession.getDataHandler().isInitialSyncComplete();

        Log.d(LOG_TAG, "## onReceive() uri getDataString=" + uriString + "isSessionActive=" + isSessionActive
                + " isLoginStepDone=" + isLoginStepDone);

        if (TextUtils.equals(action, BROADCAST_ACTION_UNIVERSAL_LINK)) {
            Log.d(LOG_TAG, "## onReceive() action = BROADCAST_ACTION_UNIVERSAL_LINK");
            intentUri = aIntent.getData();

        } else if (TextUtils.equals(action, BROADCAST_ACTION_UNIVERSAL_LINK_RESUME)) {
            Log.d(LOG_TAG, "## onReceive() action = BROADCAST_ACTION_UNIVERSAL_LINK_RESUME");

            // A first BROADCAST_ACTION_UNIVERSAL_LINK has been received with a room alias that could not be translated to a room ID.
            // Translation has been asked to server, and the response is processed here.
            // ......................
            intentUri = aIntent.getParcelableExtra(EXTRA_UNIVERSAL_LINK_URI);
            // aIntent.getParcelableExtra(EXTRA_UNIVERSAL_LINK_SENDER_ID);
        } else {
            // unknown action (very unlikely)
            Log.e(LOG_TAG,
                    "## onReceive() Unknown action received (" + action + ") - unable to proceed URL link");
            return;
        }

        if (null != intentUri) {
            Log.d(LOG_TAG, "## onCreate() intentUri - host=" + intentUri.getHost() + " path="
                    + intentUri.getPath() + " queryParams=" + intentUri.getQuery());
            //intentUri.getEncodedSchemeSpecificPart() = //vector.im/beta/  intentUri.getSchemeSpecificPart() = //vector.im/beta/

            HashMap<String, String> params = parseUniversalLink(intentUri);

            if (null != params) {

                if (!isSessionActive) {
                    Log.w(LOG_TAG, "## onReceive() Warning: Session is not alive");
                }

                if (!isLoginStepDone) {
                    Log.w(LOG_TAG, "## onReceive() Warning: Session is not complete - start Login Activity");

                    // Start the login activity and wait for BROADCAST_ACTION_UNIVERSAL_LINK_RESUME.
                    // Once the login process flow is complete, BROADCAST_ACTION_UNIVERSAL_LINK_RESUME is
                    // sent back to resume the URL link processing.
                    Intent intent = new Intent(aContext, LoginActivity.class);
                    intent.putExtra(EXTRA_UNIVERSAL_LINK_URI, aIntent.getData());
                    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    aContext.startActivity(intent);
                } else {
                    mParameters = params;

                    if (mParameters.containsKey(ULINK_ROOM_ID_OR_ALIAS_KEY)) {
                        manageRoomOnActivity(aContext);
                    } else if (mParameters.containsKey(ULINK_MATRIX_USER_ID_KEY)) {
                        manageMemberDetailsActivity(aContext);
                    } else if (mParameters.containsKey(ULINK_GROUP_ID_KEY)) {
                        manageGroupDetailsActivity(aContext);
                    } else {
                        Log.e(LOG_TAG, "## onReceive() : nothing to do");
                    }
                }
            } else {
                Log.e(LOG_TAG, "## onReceive() Path not supported: " + intentUri.getPath());
            }
        }
    }
}

From source file:cgeo.geocaching.CacheDetailActivity.java

@Override
public void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState, R.layout.cachedetail_activity);

    // get parameters
    final Bundle extras = getIntent().getExtras();
    final Uri uri = AndroidBeam.getUri(getIntent());

    // try to get data from extras
    String name = null;//from w  w w .  j  a v a2 s .c  o m
    String guid = null;

    if (extras != null) {
        geocode = extras.getString(Intents.EXTRA_GEOCODE);
        name = extras.getString(Intents.EXTRA_NAME);
        guid = extras.getString(Intents.EXTRA_GUID);
    }

    // When clicking a cache in MapsWithMe, we get back a PendingIntent
    if (StringUtils.isEmpty(geocode)) {
        geocode = MapsMeCacheListApp.getCacheFromMapsWithMe(this, getIntent());
    }

    if (geocode == null && uri != null) {
        geocode = ConnectorFactory.getGeocodeFromURL(uri.toString());
    }

    // try to get data from URI
    if (geocode == null && guid == null && uri != null) {
        final String uriHost = uri.getHost().toLowerCase(Locale.US);
        final String uriPath = uri.getPath().toLowerCase(Locale.US);
        final String uriQuery = uri.getQuery();

        if (uriQuery != null) {
            Log.i("Opening URI: " + uriHost + uriPath + "?" + uriQuery);
        } else {
            Log.i("Opening URI: " + uriHost + uriPath);
        }

        if (uriHost.contains("geocaching.com")) {
            if (StringUtils.startsWith(uriPath, "/geocache/gc")) {
                geocode = StringUtils.substringBefore(uriPath.substring(10), "_").toUpperCase(Locale.US);
            } else {
                geocode = uri.getQueryParameter("wp");
                guid = uri.getQueryParameter("guid");

                if (StringUtils.isNotBlank(geocode)) {
                    geocode = geocode.toUpperCase(Locale.US);
                    guid = null;
                } else if (StringUtils.isNotBlank(guid)) {
                    geocode = null;
                    guid = guid.toLowerCase(Locale.US);
                } else {
                    showToast(res.getString(R.string.err_detail_open));
                    finish();
                    return;
                }
            }
        }
    }

    // no given data
    if (geocode == null && guid == null) {
        showToast(res.getString(R.string.err_detail_cache));
        finish();
        return;
    }

    // If we open this cache from a search, let's properly initialize the title bar, even if we don't have cache details
    setCacheTitleBar(geocode, name, null);

    final LoadCacheHandler loadCacheHandler = new LoadCacheHandler(this, progress);

    try {
        String title = res.getString(R.string.cache);
        if (StringUtils.isNotBlank(name)) {
            title = name;
        } else if (geocode != null && StringUtils.isNotBlank(geocode)) { // can't be null, but the compiler doesn't understand StringUtils.isNotBlank()
            title = geocode;
        }
        progress.show(this, title, res.getString(R.string.cache_dialog_loading_details), true,
                loadCacheHandler.disposeMessage());
    } catch (final RuntimeException ignored) {
        // nothing, we lost the window
    }

    final int pageToOpen = savedInstanceState != null ? savedInstanceState.getInt(STATE_PAGE_INDEX, 0)
            : Settings.isOpenLastDetailsPage() ? Settings.getLastDetailsPage() : 1;
    createViewPager(pageToOpen, new OnPageSelectedListener() {

        @Override
        public void onPageSelected(final int position) {
            if (Settings.isOpenLastDetailsPage()) {
                Settings.setLastDetailsPage(position);
            }
            // lazy loading of cache images
            if (getPage(position) == Page.IMAGES) {
                loadCacheImages();
            }
            requireGeodata = getPage(position) == Page.DETAILS;
            startOrStopGeoDataListener(false);

            // dispose contextual actions on page change
            if (currentActionMode != null) {
                currentActionMode.finish();
            }
        }
    });
    requireGeodata = pageToOpen == 1;

    final String realGeocode = geocode;
    final String realGuid = guid;
    AndroidRxUtils.networkScheduler.scheduleDirect(new Runnable() {
        @Override
        public void run() {
            search = Geocache.searchByGeocode(realGeocode, StringUtils.isBlank(realGeocode) ? realGuid : null,
                    false, loadCacheHandler);
            loadCacheHandler.sendMessage(Message.obtain());
        }
    });

    // Load Generic Trackables
    if (StringUtils.isNotBlank(geocode)) {
        AndroidRxUtils.bindActivity(this,
                // Obtain the active connectors and load trackables in parallel.
                Observable.fromIterable(ConnectorFactory.getGenericTrackablesConnectors())
                        .flatMap(new Function<TrackableConnector, Observable<Trackable>>() {
                            @Override
                            public Observable<Trackable> apply(final TrackableConnector trackableConnector) {
                                processedBrands.add(trackableConnector.getBrand());
                                return Observable.defer(new Callable<Observable<Trackable>>() {
                                    @Override
                                    public Observable<Trackable> call() {
                                        return Observable
                                                .fromIterable(trackableConnector.searchTrackables(geocode));
                                    }
                                }).subscribeOn(AndroidRxUtils.networkScheduler);
                            }
                        }).toList())
                .subscribe(new Consumer<List<Trackable>>() {
                    @Override
                    public void accept(final List<Trackable> trackables) {
                        // Todo: this is not really a good method, it may lead to duplicates ; ie: in OC connectors.
                        // Store trackables.
                        genericTrackables.addAll(trackables);
                        if (!trackables.isEmpty()) {
                            // Update the UI if any trackables were found.
                            notifyDataSetChanged();
                        }
                    }
                });
    }

    locationUpdater = new CacheDetailsGeoDirHandler(this);

    // If we have a newer Android device setup Android Beam for easy cache sharing
    AndroidBeam.enable(this, this);
}