我尝试使用以下代码从我的应用程序中卸载应用程序
try
{
Log.e ( TAG, " Going to clear the application with startactivity alone " );;
Uri packageURI = Uri.parse("package:"+"com.example.canvas");
Intent uninstallIntent = new Intent(Intent.ACTION_UNINSTALL_PACKAGE, packageURI);
//uninstallIntent.putExtra(Intent.EXTRA_UNINSTALL_ALL_USERS, allUsers);
startActivityForResult(uninstallIntent, REQUEST_UNINSTALL);
Log.e ( TAG, " Cleared the applicaiton " );
}
catch ( Exception e )
{
String data = e.getMessage();
Log.e ( TAG, " data " + data );
}
但是我得到了一个execption而异常说
09-26 16:16:52.519: E/FActory reset(17246): data No Activity found to handle Intent { act=android.intent.action.UNINSTALL_PACKAGE dat=package:com.example.canvas }
答案 0 :(得分:0)
使用startActivity()
Intent intent = new Intent(Intent.ACTION_DELETE);
intent.setData(Uri.parse("package:com.example.canvas"));
startActivity(intent);
并确保您的设备上已安装该软件包。
答案 1 :(得分:0)
而 startActivityForResult()
使用 startActivity()
喜欢这个
Uri packageUri = Uri.parse("package:com.example.canvas");
Intent uninstallIntent = new Intent(Intent.ACTION_UNINSTALL_PACKAGE, packageUri);
startActivity(uninstallIntent);
确保您的软件包com.example.canvas已安装在您的设备中。