unistall android application programmatically

无人久伴 提交于 2019-12-11 08:57:00

问题


I want to be able to allow my users to uninstall application from my application. Just like what Google Play Store allow to their users(Please below image)

the main question is that how can define a button that by pressing it we can uninstall an app by giving the package name or some other info.Just like the uninstall button on the image.


回答1:


try

Intent intent = new Intent(Intent.ACTION_DELETE);
intent.setData(Uri.parse("package:app package name"));
startActivity(intent);

If this doesn't work then change intent to:

Intent.ACTION_UNINSTALL_PACKAGE); 

and set datatype as:

intent.setDataAndType(Uri.parse("package:" + your app package name));



回答2:


Try this:

Intent intent = null;
if (VERSION.SDK_INT >= VERSION_CODES.ICE_CREAM_SANDWICH) {
    intent = new Intent(Intent.ACTION_UNINSTALL_PACKAGE);
} else {
    intent = new Intent(Intent.ACTION_DELETE);
}

intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setData(Uri.fromParts("package", packageName, null));
if(intent.resolveActivity(getActivity( ).getPackageManager()) != null) {
    startActivity(intent);
}


来源:https://stackoverflow.com/questions/27358672/unistall-android-application-programmatically

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!