2
我試圖卸載應用程序本身上的按鈕的點擊,因爲我的應用程序是無法被用戶卸載時,它已經增加了一些Context.DEVICE_POLICY_SERVICE
卸載應用程序本身按鈕
try {
try {
ComponentName devAdminReceiver = new ComponentName(mContext, AdminReceiver.class);
DevicePolicyManager dpm = (DevicePolicyManager) mContext.getSystemService(Context.DEVICE_POLICY_SERVICE);
dpm.removeActiveAdmin(devAdminReceiver);
} catch (Exception e) {
e.printStackTrace();
}
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
try {
Uri packageUri = Uri.parse(getPackageName());
Intent uninstallIntent =
new Intent(Intent.ACTION_DELETE, packageUri);
uninstallIntent.putExtra(Intent.EXTRA_RETURN_RESULT, false);
//new Intent(Intent.ACTION_UNINSTALL_PACKAGE, packageUri);
startActivity(uninstallIntent);
} catch (Exception e) {
e.printStackTrace();
Uri packageURI = Uri.parse(getPackageName());
Intent uninstallIntent = new Intent(Intent.ACTION_UNINSTALL_PACKAGE, packageURI);
startActivity(uninstallIntent);
}
}
}, 1200);
} catch (Exception e) {
e.printStackTrace();
}
錯誤日誌
的點擊android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.UNINSTALL_PACKAGE dat=zcode.assistive.easy.touch }
at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1669)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1441)
at android.app.Activity.startActivityForResult(Activity.java:3464)
at android.support.v4.app.BaseFragmentActivityJB.startActivityForResult(BaseFragmentActivityJB.java:48)
at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:75)
at android.app.Activity.startActivityForResult(Activity.java:3425)
at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:856)
at android.app.Activity.startActivity(Activity.java:3661)
at android.app.Activity.startActivity(Activity.java:3629)
編輯:問題解決BY @CommonsWare評論
'Uri packageUri = Uri.parse(getPackageName());'是錯誤的。這需要'Uri packageUri = Uri.parse(「package:」+ getPackageName());'。 – CommonsWare