隐含卸载应用程序的意图?
我试图让 onclicklistener 调用卸载应用程序的意图,方法是让该意图从应用程序设置中调用默认的“卸载应用程序”活动。我找到了这里 我可以使用 ACTION_UNINSTALL_PACKAGE, com.packageXYXY 卸载应用程序,这似乎就是我正在寻找的。 但是,我不确定如何称呼它。我已尝试以下操作:
public void onClick(DialogInterface dialog, int which) {
Uri packageURI = Uri.parse("package:com.packageName");
Intent uninstallIntent = new Intent(Intent.ACTION_UNINSTALL_PACKAGE, packageURI);
startActivity(uninstallIntent);
但语法错误。尝试了多种不同的调用方式,但我有点卡住了。不知道如何称呼这个。感谢您的帮助。
I am trying to have an onclicklistener call an intent to uninstall an app, by having the intent call the default "uninstall app" activity from the applications settings. I have found here
that I can uninstall an app using ACTION_UNINSTALL_PACKAGE, com.packageXYXY, which seems to be what I'm looking for.
However, I am unsure how to call this. I have tried the following:
public void onClick(DialogInterface dialog, int which) {
Uri packageURI = Uri.parse("package:com.packageName");
Intent uninstallIntent = new Intent(Intent.ACTION_UNINSTALL_PACKAGE, packageURI);
startActivity(uninstallIntent);
but the syntax is wrong. Have tried a number of different ways of calling this, and am kind of stuck. Not sure how to call this. Thanks for your help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
首先,请注意,ACTION_UNINSTALL_PACKAGE 仅适用于 android-14(即 Ice Cream Sandwich、Android 4.0)。也就是说,以下代码对我有用:
如果您希望能够在 Android 平台的所有版本上执行此操作,只需将意图从
Intent.ACTION_UNINSTALL_PACKAGE
更改为Intent.ACTION_DELETE< /code> 就像@goto10 一样。
First of all, note that the ACTION_UNINSTALL_PACKAGE is only availible to android-14 (i.e. Ice Cream Sandwich, Android 4.0). That said, the following code works for me:
If you want to be able to do this on all versions of the android platform, just change the intent from
Intent.ACTION_UNINSTALL_PACKAGE
toIntent.ACTION_DELETE
like @goto10 does.尝试使用 ACTION_DELETE 代替。这就是此示例建议的内容。
编辑:我刚刚自己测试过,效果很好。
Try ACTION_DELETE instead. That's what this example suggests.
EDIT: I just tested this myself and it worked great.
在 Api 演示 看起来他们提供了活动的完整路径,而不仅仅是包本身。这看起来很奇怪,因为
helloactivity
活动没有在该项目的清单中声明。所以也许这只是包路径...但是,在您的意图中将额外的
EXTRA_RETURN_RESULT
设置为true
,然后启动结果活动并检查结果代码,也许它将在数据意图中返回一个代码/额外字段,说明错误是什么(请阅读文档)In the Api Demos it looks like they are giving the full path to the activty, not just the package itself. This seems weird, because
helloactivity
activity is not declared in the manifest of that project. So maybe it is just the package path...However, set the extra
EXTRA_RETURN_RESULT
totrue
in your intent, then start the activity for result and check the result code, maybe it will return a code/extra field in the data intent saying what is the error (Read in the documentation for that)