Nuubles
Nuubles

Reputation: 187

How to set another application as wallpaper drawer in Android?

When selecting a wallpaper in android through the wallpaper selector, the os prompts the user to select from a list of wallpapers and to my knowledge some wallpaper applications, such as Wallpaper Engine, but when setting the wallpaper through code, it seems to be possible to only set a drawable image as a wallpaper. Is there any way to, for example, open this system prompt etc. and allow the user to select the wallpaper or wallpaper application?

Currently it seems it's possible to select images with this method and use them through this method.

I suppose it could be done somehow with the ACTION_LIVE_WALLPAPER_CHOOSER constant specified in android studio, but I wasn't able to find documentation on how to create a system selector prompt with that?

Just to clarify, the application itself is not supposed to be a wallpaper displayer, but rather it only sets the wallpaper drawable or another independent wallpaper drawer application.

Edit: The wallpaper/engine has to be chosen beforehand by the user, after which the app will automatically at some point in time apply it

Edit 2: I tested some methods posted previously on SO, but wasn't able to get them working on API 30, even when trying to copy paste the code directly as a last result. The code was taken from here and can be summarized as such:

PackageManager m_package_manager = getContext().getPackageManager();
        List<ResolveInfo> available_wallpapers_list =
                m_package_manager.queryIntentServices(
                        new Intent(WallpaperService.SERVICE_INTERFACE),
                        PackageManager.GET_META_DATA);
        return available_wallpapers_list;

The returned list is empty even if some additional live wallpaper applications have been installed

Upvotes: 0

Views: 558

Answers (1)

HapaxLegomenon
HapaxLegomenon

Reputation: 121

If you add this intent filter to your activity in the manifest, it should appear in the chooser:

    <activity
        android:name=".ChangeWallpaperActivity"
        android:exported="true">
        <intent-filter>
            <!-- This is the important part -->
            <action android:name="android.intent.action.SET_WALLPAPER" />
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>

You can test this with the following bit of code:

    Intent intent = new Intent("android.intent.action.SET_WALLPAPER");
    try {
        startActivity(intent);
        } catch (ActivityNotFoundException e) {
        Log.w(TAG, "No activity found to handle " + intent.toString());
    }

Upvotes: 1

Related Questions