Android: Programmatically remove my app from Device Administrator?

前端 未结 1 1146
情书的邮戳
情书的邮戳 2021-02-20 09:58

I\'m trying to add a button to my app to remove it from Device Administrator and am using the code below but my app just crashes.

Code:-

On Button Click:-

<
1条回答
  •  轮回少年
    2021-02-20 10:34

    It's as you do:

    DevicePolicyManager mDPM = (DevicePolicyManager)getSystemService(Context.DEVICE_POLICY_SERVICE);
    mDPM.removeActiveAdmin(mDeviceAdminReceiver);
    

    But you need to add these filters to the receiver in AndroidManifest.xml:

        
            
            
        
    
    
    @Override
    public CharSequence onDisableRequested(Context context, Intent intent) {
        return "Admin rights are beeing requested to be disabled for the app called: '" + context.getString(R.string.app_name) + "'.";
    }
    

    0 讨论(0)
提交回复
热议问题