DevicePolicyManager deviceManger;
ActivityManager activityManager;
ComponentName compName;
hinzufügen Code in onCreate()
deviceManger = (DevicePolicyManager)getSystemService(
Context.DEVICE_POLICY_SERVICE);
activityManager = (ActivityManager)getSystemService(
Context.ACTIVITY_SERVICE);
compName = new ComponentName(this, DeviceAdminLock.class);
fügen Sie Code in Manifest-Datei
<receiver android:name=".DeviceAdminLock"
android:permission="android.permission.BIND_DEVICE_ADMIN">
<meta-data android:name="android.app.device_admin"
android:resource="@xml/device_admin_sample" />
<intent-filter>
<action android:name="android.app.action.DEVICE_ADMIN_ENABLED" />
</intent-filter>
</receiver>
Erstellen Sie eine XML-Ressourcendatei in res/xml als device_admin_sample.xml, und fügen Sie Folgendes hinzu:
<device-admin xmlns:android="http://schemas.android.com/apk/res/android">
<uses-policies>
<limit-password />
<watch-login />
<reset-password />
<force-lock />
<wipe-data />
<expire-password />
<encrypted-storage />
<disable-camera />
</uses-policies>
Add Berechtigungen in Manifest-Datei -
<uses-permission android:name="android.permission.DISABLE_KEYGUARD"/>
<uses-permission android:name="android.permission.WAKE_LOCK"/>
einen Empfänger Klasse erstellen, die DeviceAdminReceiver-Klasse erweitert.
public class DeviceAdminLock extends DeviceAdminReceiver {
@Override
public void onEnabled(Context context, Intent intent) {
}
@Override
public CharSequence onDisableRequested(Context context, Intent intent) {
return "This is an optional message to warn the user about disabling.";
}
@Override
public void onDisabled(Context context, Intent intent) {
}
@Override
public void onPasswordChanged(Context context, Intent intent) {
}
@Override
public void onPasswordFailed(Context context, Intent intent) {
}
@Override
public void onPasswordSucceeded(Context context, Intent intent) {
}
}
fragen aktivieren Sperre Erlaubnis in Aktivitätsklasse
Intent intent = new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);
intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN,compName);
intent.putExtra(DevicePolicyManager.EXTRA_ADD_EXPLANATION,"Additional text explaining why this needs to be added.");
startActivityForResult(intent, 1);
Scheck Erlaubnis erteilt wird oder nicht
boolean active = deviceManger.isAdminActive(compName);
if (active) {
// if available then lock
deviceManger.lockNow();
}
Entriegelungssystem
deviceManger.removeActiveAdmin(compName);
Um
KeyguardManager km = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE);
final KeyguardManager.KeyguardLock kl = km .newKeyguardLock("MyKeyguardLock");
kl.disableKeyguard();
PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
WakeLock wakeLock = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK
| PowerManager.ACQUIRE_CAUSES_WAKEUP
| PowerManager.ON_AFTER_RELEASE, "MyWakeLock");
wakeLock.acquire();
dem Sie versuchen, haben Antworten zu so kennen wir sie nicht vorschlagen? – CodingIntrigue
"niemand arbeitet" ist keine nützliche Beschreibung Ihrer Symptome. Bitte erläutern Sie * vollständig und genau * was Sie ausprobiert haben und welche Probleme aufgetreten sind. – CommonsWare
@BladeOrz: Ich habe einige der besuchten Seiten hinzugefügt Links –