简体   繁体   中英

No Activity found to handle Intent { act=android.app.action.ADD_DEVICE_ADMIN (has extras) }

I'm trying to enable the device administration, so I can create secondary users in Android 9.

First is to send an intent with ACTION_ADD_DEVICE_ADMIN like this below :

                    // Launch the activity to have the user enable our admin.
                Intent deviceAdminIntent = new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);
                deviceAdminIntent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, mDeviceAdminRen);
                deviceAdminIntent.putExtra(DevicePolicyManager.EXTRA_ADD_EXPLANATION,
                        getResources().getString(R.string.device_admin_activation_message));

                startActivityForResult(deviceAdminIntent, REQ_ENABLE_DEVICE_ADMIN);

A deviceAdminReceiver must be prior defined in the manifest.xml with the proper intent filter:

    <activity android:name=".AuthSessionActivity" />
    <activity android:name=".CreateRenUser"/>
    <receiver android:name=".DeviceAdminRen"
        android:label="@string/renault_device_admin"
        android:description="@string/ren_device_admin_description"
        android:permission="android.permission.BIND_DEVICE_ADMIN">
        <meta-data android:name="android.app.device_admin"
            android:resource="@xml/device_admin_ren" />
        <intent-filter>
            <action android:name="android.app.action.DEVICE_ADMIN_ENABLED" />
        </intent-filter>
    </receiver>

Also the deviceAdminReceiver class is defined :

public class DeviceAdminRen extends DeviceAdminReceiver {

.........

But then I'm getting the error :

03-28 16:44:54.573 7173 7173 E AndroidRuntime: java.lang.RuntimeException: Unable to resume activity {com.sensory.trulysecureexample/com.sensory.trulysecure.custom.CreateRenaultUser}: android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.app.action.ADD_DEVICE_ADMIN (has extras) } 03-28 16:44:54.573 7173 7173 E AndroidRuntime: at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3822) 03-28 16:44:54.573 7173 7173 E AndroidRuntime: at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3854) 03-28 16:44:54.573 7173 7173 E AndroidRuntime: at android.app.servertransaction.ResumeActivityItem.execute(ResumeActivityIte

My Android application has several activities and fragments but if I understand well, this should be an Android system activity. Also my device has "feature:android.software.device_admin" when listing with "adb shell pm list features" Is there any limitation in my device preventing to handle the ACTION_ADD_DEVICE_ADMIN intent ??

Note: I followed this Google Android guide https://developer.android.com/guide/topics/admin/device-admin.html

Thanks

What is the content of the constant / variable mDeviceAdminRen ? That seems to be missing from your code snippet.

It should contain the component name of the device admin component, so in your case DeviceAdminRen.getComponentName(Context context) .

Is this the case?

As I'm building my application with the Android NDK, I added the LOCAL_PRIVILEGED_MODULE build directive in the Makefile of the C++ lib. gnu-libstdc++/Android.mk:LOCAL_PRIVILEGED_MODULE := true

And it worked !! There is a prompt in Android asking for enabling device administration, and then it becomes easy to create secondary users.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM