Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to know if my application admin or not

I am creation app which make my device as a admin work Great.

But i want trigger some message when my Application uninstall from device.

  1. when user remove from admin.

  2. How to know if my app Device admin is checked or not?

I am using android inbuilt admin application demo.

Please give me some idea.

like image 884
Harshid Avatar asked Jul 30 '13 09:07

Harshid


1 Answers

You will have to extend DeviceAdminReceiver and

public class DeviceAdmin extends DeviceAdminReceiver {

    @Override
    public void onEnabled(Context context, Intent intent) {
        Log.i(this, "admin_receiver_status_enabled");
        // admin rights
        App.getPreferences().edit().putBoolean(App.ADMIN_ENABLED, true).commit(); //App.getPreferences() returns the sharedPreferences

    }

    @Override
    public CharSequence onDisableRequested(Context context, Intent intent) {
        return "admin_receiver_status_disable_warning";
    }

    @Override
    public void onDisabled(Context context, Intent intent) {
        Log.info(this, "admin_receiver_status_disabled");
        // admin rights removed
        App.getPreferences().edit().putBoolean(App.ADMIN_ENABLED, false).commit(); //App.getPreferences() returns the sharedPreferences
    }
}

anywhere in your app:

DevicePolicyManager mDPM = (DevicePolicyManager)getSystemService(Context.DEVICE_POLICY_SERVICE);
ComponentName mAdminName = new ComponentName(this, DeviceAdmin.class); 

if(mDPM != null &&mDPM.isAdminActive(mAdminName)) {
    // admin active
}
like image 90
malimo Avatar answered Nov 07 '22 03:11

malimo