Example usage for android.content Intent EXTRA_ORIGINATING_URI

List of usage examples for android.content Intent EXTRA_ORIGINATING_URI

Introduction

In this page you can find the example usage for android.content Intent EXTRA_ORIGINATING_URI.

Prototype

String EXTRA_ORIGINATING_URI

To view the source code for android.content Intent EXTRA_ORIGINATING_URI.

Click Source Link

Document

Used as a URI extra field with #ACTION_INSTALL_PACKAGE and #ACTION_VIEW to indicate the URI from which the local APK in the Intent data field originated from.

Usage

From source file:com.android.packageinstaller.PackageInstallerActivity.java

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

    mPm = getPackageManager();/*from  ww  w. ja v  a2 s . c om*/
    mInstaller = mPm.getPackageInstaller();
    mUserManager = (UserManager) getSystemService(Context.USER_SERVICE);

    final Intent intent = getIntent();
    mOriginatingUid = getOriginatingUid(intent);

    final Uri packageUri;

    if (PackageInstaller.ACTION_CONFIRM_PERMISSIONS.equals(intent.getAction())) {
        final int sessionId = intent.getIntExtra(PackageInstaller.EXTRA_SESSION_ID, -1);
        final PackageInstaller.SessionInfo info = mInstaller.getSessionInfo(sessionId);
        if (info == null || !info.sealed || info.resolvedBaseCodePath == null) {
            Log.w(TAG, "Session " + mSessionId + " in funky state; ignoring");
            finish();
            return;
        }

        mSessionId = sessionId;
        packageUri = Uri.fromFile(new File(info.resolvedBaseCodePath));
        mOriginatingURI = null;
        mReferrerURI = null;
    } else {
        mSessionId = -1;
        packageUri = intent.getData();
        mOriginatingURI = intent.getParcelableExtra(Intent.EXTRA_ORIGINATING_URI);
        mReferrerURI = intent.getParcelableExtra(Intent.EXTRA_REFERRER);
    }

    // if there's nothing to do, quietly slip into the ether
    if (packageUri == null) {
        Log.w(TAG, "Unspecified source");
        setPmResult(PackageManager.INSTALL_FAILED_INVALID_URI);
        finish();
        return;
    }

    if (DeviceUtils.isWear(this)) {
        showDialogInner(DLG_NOT_SUPPORTED_ON_WEAR);
        return;
    }

    //set view
    setContentView(R.layout.install_start);
    mInstallConfirm = findViewById(R.id.install_confirm_panel);
    mInstallConfirm.setVisibility(View.INVISIBLE);
    mOk = (Button) findViewById(R.id.ok_button);
    mCancel = (Button) findViewById(R.id.cancel_button);
    mOk.setOnClickListener(this);
    mCancel.setOnClickListener(this);

    // Block the install attempt on the Unknown Sources setting if necessary.
    final boolean requestFromUnknownSource = isInstallRequestFromUnknownSource(intent);
    if (!requestFromUnknownSource) {
        processPackageUri(packageUri);
        return;
    }

    // If the admin prohibits it, or we're running in a managed profile, just show error
    // and exit. Otherwise show an option to take the user to Settings to change the setting.
    final boolean isManagedProfile = mUserManager.isManagedProfile();
    if (!isUnknownSourcesAllowedByAdmin()) {
        startActivity(new Intent(Settings.ACTION_SHOW_ADMIN_SUPPORT_DETAILS));
        clearCachedApkIfNeededAndFinish();
    } else if (!isUnknownSourcesEnabled() && isManagedProfile) {
        showDialogInner(DLG_ADMIN_RESTRICTS_UNKNOWN_SOURCES);
    } else if (!isUnknownSourcesEnabled()) {
        // Ask user to enable setting first

        showDialogInner(DLG_UNKNOWN_SOURCES);
    } else {
        processPackageUri(packageUri);
    }
}

From source file:com.android.packageinstaller.PackageInstallerActivity.java

private void startInstall() {
    // Start subactivity to actually install the application
    Intent newIntent = new Intent();
    newIntent.putExtra(PackageUtil.INTENT_ATTR_APPLICATION_INFO, mPkgInfo.applicationInfo);
    newIntent.setData(mPackageURI);//from w  w w  .j ava  2s  .  c o m
    newIntent.setClass(this, InstallAppProgress.class);
    String installerPackageName = getIntent().getStringExtra(Intent.EXTRA_INSTALLER_PACKAGE_NAME);
    if (mOriginatingURI != null) {
        newIntent.putExtra(Intent.EXTRA_ORIGINATING_URI, mOriginatingURI);
    }
    if (mReferrerURI != null) {
        newIntent.putExtra(Intent.EXTRA_REFERRER, mReferrerURI);
    }
    if (mOriginatingUid != VerificationParams.NO_UID) {
        newIntent.putExtra(Intent.EXTRA_ORIGINATING_UID, mOriginatingUid);
    }
    if (installerPackageName != null) {
        newIntent.putExtra(Intent.EXTRA_INSTALLER_PACKAGE_NAME, installerPackageName);
    }
    if (getIntent().getBooleanExtra(Intent.EXTRA_RETURN_RESULT, false)) {
        newIntent.putExtra(Intent.EXTRA_RETURN_RESULT, true);
        newIntent.addFlags(Intent.FLAG_ACTIVITY_FORWARD_RESULT);
    }
    if (localLOGV)
        Log.i(TAG, "downloaded app uri=" + mPackageURI);
    startActivity(newIntent);
    finish();
}