Domanda

I am able to create an Activity that uses the DevicePolicyManager API's.

The tutorials show that I need use it the following fashion:

     if (!mDPM.isAdminActive(mAdminName)) {
        Intent intent = new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);
    intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, mAdminName);
    intent.putExtra("wipe-data", DeviceAdminInfo.USES_POLICY_WIPE_DATA);        
   startActivityForResult(intent, REQUEST_ENABLE);

} 
else {

mDPM.wipeData(0);

}

However I would like this to run inside a Service. But I cant call

startActivityForResult

from within a Service.

So what would be the best approach or strategy for me to try ?

È stato utile?

Soluzione

The only reason you need to call startActivityForResult() is if your app is not presently configured as a device administrator, to lead the user to go set that up for you. Hence, put that portion of your logic inside of your user interface.

Your service itself would just skip doing anything if isAdminActive() returns false.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top