I have a service, and I want the service to contribute to its inclusion as Device Admin, so far I have run such user interface interactions from the service, for example
Intent intent2 = new Intent();
intent2.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent2.setAction(android.content.Intent.ACTION_VIEW);
intent2.setDataAndType(uri, "application/vnd.android.package-archive");
context.startActivity(intent2);
and it works, but with DevicePolicyManager I cannot find a way:
Intent intent = new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, mAdminName);
intent.putExtra(DevicePolicyManager.EXTRA_ADD_EXPLANATION, "some text.");
context.startActivity(intent);
doesn't work: don't advertise anything, but don't crash either. Without intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);This is simply a failure, because this code is inside the tread inside the service. Ideas?
source
share