Example usage for android.net Uri isHierarchical

List of usage examples for android.net Uri isHierarchical

Introduction

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

Prototype

public abstract boolean isHierarchical();

Source Link

Document

Returns true if this URI is hierarchical like "http://google.com".

Usage

From source file:com.android.calendar.AllInOneActivity.java

private long parseViewAction(final Intent intent) {
    long timeMillis = -1;
    Uri data = intent.getData();
    if (data != null && data.isHierarchical()) {
        List<String> path = data.getPathSegments();
        if (path.size() == 2 && path.get(0).equals("events")) {
            try {
                mViewEventId = Long.valueOf(data.getLastPathSegment());
                if (mViewEventId != -1) {
                    mIntentEventStartMillis = intent.getLongExtra(EXTRA_EVENT_BEGIN_TIME, 0);
                    mIntentEventEndMillis = intent.getLongExtra(EXTRA_EVENT_END_TIME, 0);
                    mIntentAttendeeResponse = intent.getIntExtra(ATTENDEE_STATUS,
                            Attendees.ATTENDEE_STATUS_NONE);
                    mIntentAllDay = intent.getBooleanExtra(EXTRA_EVENT_ALL_DAY, false);
                    timeMillis = mIntentEventStartMillis;
                }// w w w .  j a va  2  s .com
            } catch (NumberFormatException e) {
                // Ignore if mViewEventId can't be parsed
            }
        }
    }
    return timeMillis;
}

From source file:id.ridon.keude.AppDetailsData.java

/**
 * Attempt to extract the appId from the intent which launched this activity.
 * Various different intents could cause us to show this activity, such as:
 * <ul>/* w  w w .  j  a va 2  s. co  m*/
 *     <li>market://details?id=[app_id]</li>
 *     <li>https://f-droid.org/app/[app_id]</li>
 *     <li>fdroid.app:[app_id]</li>
 * </ul>
 * @return May return null, if we couldn't find the appId. In this case, you will
 * probably want to do something drastic like finish the activity and show some
 * feedback to the user (this method will <em>not</em> do that, it will just return
 * null).
 */
private String getAppIdFromIntent() {
    Intent i = getIntent();
    Uri data = i.getData();
    String appId = null;
    if (data != null) {
        if (data.isHierarchical()) {
            if (data.getHost() != null && data.getHost().equals("details")) {
                // market://details?id=app.id
                appId = data.getQueryParameter("id");
            } else {
                // https://f-droid.org/app/app.id
                appId = data.getLastPathSegment();
                if (appId != null && appId.equals("app")) {
                    appId = null;
                }
            }
        } else {
            // fdroid.app:app.id
            appId = data.getEncodedSchemeSpecificPart();
        }
        Log.d(TAG, "AppDetails launched from link, for '" + appId + "'");
    } else if (!i.hasExtra(EXTRA_APPID)) {
        Log.e(TAG, "No application ID in AppDetails!?");
    } else {
        appId = i.getStringExtra(EXTRA_APPID);
    }
    return appId;
}