簡體   English   中英

android:使用設備管理員鎖定卸載應用

[英]android: lock uninstall app using device admin

請幫忙 。 我正在構建應用程序,但我想在用戶嘗試卸載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>

實際上我真的很困惑,它是如何工作的。 請幫助我,我的最終項目真的需要它

如果未修改固件,則無法在Android中實現。 請參閱AOSP代碼以獲取進一步的管理策略

要么

在AndroidL中推送deviceower.xml,這將使您成為應用程序的設備所有者,因此您可以應用該策略,但前提條件是設備應該被銷毀

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM