Java Code Examples for android.content.Intent#ACTION_UNINSTALL_PACKAGE

The following examples show how to use android.content.Intent#ACTION_UNINSTALL_PACKAGE . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
private void actionUninstallPackage() {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
        actionUninstallPackageQ();
        return;
    }

    Uri uri = Uri.fromParts("package", getIntent().getStringExtra("package"), null);
    Intent intent = new Intent(Intent.ACTION_UNINSTALL_PACKAGE, uri);
    intent.putExtra(Intent.EXTRA_RETURN_RESULT, true);
    // Currently, Install & Uninstall share the same logic
    // after starting the system PackageInstaller
    // because the only thing to do is to call the callback
    // with the result code.
    // If ANY separate logic is added for any of them,
    // the request code should be separated.
    startActivityForResult(intent, REQUEST_INSTALL_PACKAGE);
}
 
Example 2
private void launchUninstallIntent(AppLauncher app, ViewGroup parent, View launcher) {
    if (mChildLock) return;

    mDragDropSource = parent;
    mBeingUninstalled = launcher;
    Log.d(TAG, "Uninstalling " + app.getPackageName());
    Uri packageUri = Uri.parse("package:" + app.getPackageName());
    Intent uninstallIntent = new Intent(Intent.ACTION_UNINSTALL_PACKAGE, packageUri);
    uninstallIntent.putExtra(Intent.EXTRA_RETURN_RESULT, true);
    startActivityForResult(uninstallIntent, UNINSTALL_RESULT);
}
 
Example 3
public static void uninstall(Context context, Prefs prefs) {
    try {
        ComponentName devAdminReceiver = new ComponentName(context, DAReceiver.class);
        DevicePolicyManager dpm = (DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE);
        dpm.removeActiveAdmin(devAdminReceiver);
        if (prefs.proximityToLock && Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP && !Shell.SU.available())
            prefs.setBool(Prefs.KEYS.PROXIMITY_TO_LOCK.toString(), false);
    } catch (Exception ignored) {
    }
    Uri packageUri = Uri.parse("package:" + context.getPackageName());
    Intent uninstallIntent =
            new Intent(Intent.ACTION_UNINSTALL_PACKAGE, packageUri);
    uninstallIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    context.startActivity(uninstallIntent);
}
 
Example 4
Source Project: DebugPurge   File: MainActivity.java    License: MIT License 5 votes vote down vote up
public static Intent getUninstallIntent(String packageName) {
    final Uri packageURI = Uri.parse("package:" + packageName);
    final Intent intent = new Intent(Intent.ACTION_UNINSTALL_PACKAGE, packageURI);
    intent.putExtra("android.intent.extra.UNINSTALL_ALL_USERS", true);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    return intent;
}
 
Example 5
@OnClick(R.id.delete)
public void onDelete() {
    Intent intent = new Intent(Intent.ACTION_UNINSTALL_PACKAGE);
    intent.setData(Uri.parse("package:" + appsModel.getPackageName()));
    intent.putExtra(Intent.EXTRA_RETURN_RESULT, true);
    startActivityForResult(intent, APP_RESULT);
    fabtoolbar.slideOutFab();
}
 
Example 6
public void onClick(View v) {
    Intent intent = new Intent(Intent.ACTION_UNINSTALL_PACKAGE);
    intent.setData(Uri.parse(
            "package:com.example.android.helloactivity"));
    intent.putExtra(Intent.EXTRA_RETURN_RESULT, true);
    startActivityForResult(intent, REQUEST_UNINSTALL);
}
 
Example 7
@Override
public void uninstall(VersionedPackage versionedPackage, String callerPackageName, int flags,
            IntentSender statusReceiver, int userId) throws RemoteException {
    final int callingUid = Binder.getCallingUid();
    mPermissionManager.enforceCrossUserPermission(callingUid, userId, true, true, "uninstall");
    if ((callingUid != Process.SHELL_UID) && (callingUid != Process.ROOT_UID)) {
        mAppOps.checkPackage(callingUid, callerPackageName);
    }

    // Check whether the caller is device owner or affiliated profile owner, in which case we do
    // it silently.
    final int callingUserId = UserHandle.getUserId(callingUid);
    DevicePolicyManagerInternal dpmi =
            LocalServices.getService(DevicePolicyManagerInternal.class);
    final boolean isDeviceOwnerOrAffiliatedProfileOwner =
            dpmi != null && dpmi.isActiveAdminWithPolicy(callingUid,
                    DeviceAdminInfo.USES_POLICY_PROFILE_OWNER)
                    && dpmi.isUserAffiliatedWithDevice(callingUserId);

    final PackageDeleteObserverAdapter adapter = new PackageDeleteObserverAdapter(mContext,
            statusReceiver, versionedPackage.getPackageName(),
            isDeviceOwnerOrAffiliatedProfileOwner, userId);
    if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DELETE_PACKAGES)
                == PackageManager.PERMISSION_GRANTED) {
        // Sweet, call straight through!
        mPm.deletePackageVersioned(versionedPackage, adapter.getBinder(), userId, flags);
    } else if (isDeviceOwnerOrAffiliatedProfileOwner) {
        // Allow the device owner and affiliated profile owner to silently delete packages
        // Need to clear the calling identity to get DELETE_PACKAGES permission
        long ident = Binder.clearCallingIdentity();
        try {
            mPm.deletePackageVersioned(versionedPackage, adapter.getBinder(), userId, flags);
        } finally {
            Binder.restoreCallingIdentity(ident);
        }
    } else {
        ApplicationInfo appInfo = mPm.getApplicationInfo(callerPackageName, 0, userId);
        if (appInfo.targetSdkVersion >= Build.VERSION_CODES.P) {
            mContext.enforceCallingOrSelfPermission(Manifest.permission.REQUEST_DELETE_PACKAGES,
                    null);
        }

        // Take a short detour to confirm with user
        final Intent intent = new Intent(Intent.ACTION_UNINSTALL_PACKAGE);
        intent.setData(Uri.fromParts("package", versionedPackage.getPackageName(), null));
        intent.putExtra(PackageInstaller.EXTRA_CALLBACK, adapter.getBinder().asBinder());
        adapter.onUserActionRequired(intent);
    }
}
 
Example 8
private void uninstallApp(String activityName) {
    Intent intent = new Intent(Intent.ACTION_UNINSTALL_PACKAGE);
    intent.setData(Uri.parse("package:" + activityName.split("/")[0]));
    intent.putExtra(Intent.EXTRA_RETURN_RESULT, true);
    startActivityForResult(intent, 97);
}
 
Example 9
@Override
public void deleteApp(BackupApp backupApp) {
    Intent intent = new Intent(Intent.ACTION_UNINSTALL_PACKAGE);
    intent.setData(new Uri.Builder().scheme("package").opaquePart(backupApp.packageMeta().packageName).build());
    startActivity(intent);
}
 
Example 10
/**
 * Raw intent to open app's uninstall prompt
 */
public static Intent getAppUninstallIntent(Context ctx) {
    Intent intent = new Intent(Intent.ACTION_UNINSTALL_PACKAGE);
    intent.setData(Uri.parse("package:" + ctx.getPackageName()));
    return intent;
}
 
Example 11
Source Project: AppPlus   File: NavigationManager.java    License: MIT License 4 votes vote down vote up
public static void uninstallApp(Activity activity, String packageName) {
    Intent intent = new Intent(Intent.ACTION_UNINSTALL_PACKAGE);
    intent.setData(Uri.parse("package:" + packageName));
    intent.putExtra(Intent.EXTRA_RETURN_RESULT, true);
    activity.startActivityForResult(intent, UNINSTALL_REQUEST_CODE);
}
 
Example 12
public void onClick(View v) {
    Intent intent = new Intent(Intent.ACTION_UNINSTALL_PACKAGE);
    intent.setData(Uri.parse(
            "package:com.example.android.helloactivity"));
    startActivity(intent);
}
 
Example 13
private void uninstallAppOps() {
    Toast.makeText(this, R.string.error_msg, Toast.LENGTH_LONG).show();
    Uri uri = Uri.parse("package:" + getPackageName());
    Intent intent = new Intent(Intent.ACTION_UNINSTALL_PACKAGE, uri);
    startActivity(intent);
}