简体   繁体   English

android:使用设备管理员锁定卸载应用

[英]android: lock uninstall app using device admin

please help . 请帮忙 。 . I build app, but i want to when user try to uninstall mp app, it's require password. 我正在构建应用程序,但我想在用户尝试卸载mp应用程序时要求输入密码。 I try this but it doesn't work: 我尝试这样做,但不起作用:
In myActivity : myActivity

 AdminReceiver a = new AdminReceiver();
 a.onDisableRequested(getApplicationContext(), getIntent());

AdminReceiver : 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;

 }

And in AndroidManifest : 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> 

and last in xml/deviceadmin : 最后在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>

actually i really confused, how it works. 实际上我真的很困惑,它是如何工作的。 Please help me i really need it for my final project 请帮助我,我的最终项目真的需要它

That is not possible in Android without firmware modifications. 如果未修改固件,则无法在Android中实现。 Refer AOSP code for further managing policy 请参阅AOSP代码以获取进一步的管理策略

OR 要么

IN AndroidL push deviceower.xml which will make ur app device owner hence u can apply the policy but prerequisites is device should be rroted 在AndroidL中推送deviceower.xml,这将使您成为应用程序的设备所有者,因此您可以应用该策略,但前提条件是设备应该被销毁

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM