デバイスからアプリケーションをサイレント モードで削除したい。このコードを試していますが、「ユーザー10051も現在のプロセスもandroid.permission.DELETE_PACKAGESを持っていません」という例外が発生します。
class PackageInstallObserver extends IPackageInstallObserver.Stub {
public void packageInstalled(String packageName, int returnCode) throws RemoteException {
if (onInstalledPackaged != null) {
onInstalledPackaged.packageInstalled(packageName, returnCode);
}
}
}
class PackageDeleteObserver extends IPackageDeleteObserver.Stub {
public void packageDeleted(String packageName, int returnCode) throws RemoteException {
/*if (onInstalledPackaged != null) {
onInstalledPackaged.packageInstalled(packageName, returnCode);
}*/
}
}
public ApplicationManager(Context context) throws SecurityException, NoSuchMethodException {
observer = new PackageInstallObserver();
observerdelete = new PackageDeleteObserver();
pm = context.getPackageManager();
Class<?>[] types = new Class[] {Uri.class, IPackageInstallObserver.class, int.class, String.class};
Class<?>[] uninstalltypes = new Class[] {String.class, IPackageDeleteObserver.class, int.class};
method = pm.getClass().getMethod("installPackage", types);
uninstallmethod = pm.getClass().getMethod("deletePackage", uninstalltypes);
}
public void setOnInstalledPackaged(OnInstalledPackaged onInstalledPackaged) {
this.onInstalledPackaged = onInstalledPackaged;
}
public void uninstallPackage(String packagename) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException {
uninstallmethod.invoke(pm, new Object[] {packagename, observerdelete, 0});
}