请帮帮忙。。我建立应用程序,但我想当用户尝试卸载mp应用程序时,它需要密码。我试了一下,但它不起作用:
在myActivity中:
AdminReceiver a = new AdminReceiver();
a.onDisableRequested(getApplicationContext(), getIntent());AdminReceiver:
public class AdminReceiver extends DeviceAdminReceiver{
static DevicePolicyManager dpm;
static ComponentName devAdminReceiver;
public CharSequence onDisableRequested(final Context context, Intent intent) {
Intent startMain = new Intent(Intent.ACTION_MAIN);
startMain.addCategory(Intent.CATEGORY_HOME);
startMain.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(startMain); //switch to the home screen, not totally necessary
lockPhone(context, "pass");
//Log.i(TAG, "DEVICE ADMINISTRATION DISABLE REQUESTED & LOCKED PHONE");
return "haha. i locked your phone.";
}
public static boolean lockPhone(Context context, String password){
devAdminReceiver = new ComponentName(context, AdminReceiver.class);
dpm = (DevicePolicyManager)context.getSystemService(Context.DEVICE_POLICY_SERVICE);
boolean pwChange = dpm.resetPassword(password, 0);
dpm.lockNow();
return pwChange;
}在AndroidManifest中
<receiver android:name=".app.AdminReceiver"
android:label="@string/app_name"
android:description="@string/hello_world"
android:permission="android.permission.BIND_DEVICE_ADMIN">
<meta-data android:name="android.app.device_admin"
android:resource="@xml/deviceadmin" />
<intent-filter>
<action android:name="android.app.action.DEVICE_ADMIN_ENABLED" />
</intent-filter>
</receiver> 最后在xml/deviceadmin中
<device-admin xmlns:android="http://schemas.android.com/apk/res/android">
<uses-policies>
<limit-password />
<watch-login />
<reset-password />
<force-lock />
<wipe-data />
</uses-policies>
</device-admin>实际上,我真的很困惑,它是如何工作的。请帮帮我,我真的需要它做我的期末项目
发布于 2014-08-21 00:40:22
在没有固件修改的情况下,这在Android中是不可能的。有关进一步管理策略的信息,请参阅AOSP代码
或
在AndroidL push deviceower.xml中,这将使您的应用程序成为设备所有者,因此您可以应用该策略,但前提条件是设备应被转储
https://stackoverflow.com/questions/25409988
复制相似问题