隐式意图卸载应用程序? [英] Implicit intent to uninstall application?
问题描述
我想有一个onclicklistener调用的意图,卸载应用程序,通过让意图调用默认的卸载程序的活动,从应用程序设置。我发现<一href="http://developer.android.com/reference/android/content/Intent.html#ACTION_UNINSTALL_PACKAGE">here 我可以卸载使用ACTION_UNINSTALL_PACKAGE,com.packageXYXY,这似乎是我要找的一个应用程序。 不过,我不能确定如何调用此。我已经试过如下:
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.
推荐答案
首先,请注意ACTION_UNINSTALL_PACKAGE只有菱到Android-14(即冰激凌三明治的Android 4.0)。这就是说,下面的code对我的作品:
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:
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
import android.view.View;
import android.net.Uri;
import android.content.Intent;
public class TestActivity extends Activity
{
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TextView view = (TextView)findViewById(R.id.test_view);
view.setOnClickListener(new View.OnClickListener(){
public void onClick(View view){
Uri packageUri = Uri.parse("package:org.klnusbaum.test");
Intent uninstallIntent =
new Intent(Intent.ACTION_UNINSTALL_PACKAGE, packageUri);
startActivity(uninstallIntent);
}
});
}
}
如果您希望能够做到这一点对所有版本的Android平台,只是改变从 Intent.ACTION_UNINSTALL_PACKAGE
意图意图。 ACTION_DELETE
像@ goto10一样。
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
to Intent.ACTION_DELETE
like @goto10 does.
这篇关于隐式意图卸载应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!