How to activate DeviceAdmin when application start in Android?

anddev picture anddev · Nov 14, 2011 · Viewed 9.5k times · Source

Hello I want to start/activate Device Admin when application start without using Intent. Now I am using this code:

Intent intent = new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);
            intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, Global.mDeviceAdminSample);
            intent.putExtra(DevicePolicyManager.EXTRA_ADD_EXPLANATION,
                    "Additional text explaining why this needs to be added.");
            startActivityForResult(intent, RESULT_ENABLE);

But I dont want to use Intent. I want to start Device Admin directly .

Can anyone know how can I do that?

Thanks.

Answer

stevo.mit picture stevo.mit · Jan 24, 2014

Fortunately it's not possible without user interaction. User must confirm your app as device admin in settings so you can navigate user to the settings at best.

It would be a huge security risk if apps could activate device administrators without user interaction (device admin has pretty big privileges).