Home > Software engineering >  How to access "device admin app" programtically in react native
How to access "device admin app" programtically in react native

Time:10-23

Anybody know, How to directing user to Device Admin App page programtically in react native ?

so, all into application without user have to go to manual menu in Settings > Privacy > Manage > Special app access > Device Admin Apps..

Thanks in advance

Device admin apps Image Checklist for permission apps Image

CodePudding user response:

I don't know in React but assuming you can use "pure" code:

Intent intent = new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);
intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, AdminManager.mDeviceAdminSample);
intent.putExtra(DevicePolicyManager.EXTRA_ADD_EXPLANATION, "Admin rights");
startActivityForResult(intent, REQUEST_ADMIN_PERMISSION);

Are the lines you need. Of course, you'll need the required objects. All info can be found:https://developer.android.com/guide/topics/admin/device-admin

CodePudding user response:

    // Initiate DevicePolicyManager.
        mDPM = (DevicePolicyManager)getSystemService(Context.DEVICE_POLICY_SERVICE);
        // Set DeviceAdminDemo Receiver for active the component with different option
        mAdminName = new ComponentName(this, MyAdminLocal.class);
        
        if (!mDPM.isAdminActive(mAdminName)) {
            // try to become active
            Intent intent = new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);
            intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, mAdminName);
            intent.putExtra(DevicePolicyManager.EXTRA_ADD_EXPLANATION, "Click on Activate button to secure your application.");
            startActivityForResult(intent, REQUEST_CODE);
        }
        else 
        {
            // Already is a device administrator, can do security operations now.
            mDPM.lockNow();
        }

Just copy this code to your MainActivity.java into function onStart()

  • Related