Android filter installed wallpaper service by category

301 Views Asked by At

I have created a plugin application which is composed by multiple .apk Some .apk provides only a Live Wallpaper service with the following XML:

<application
    ... omitted
    <service
        android:name=".DigitalWallpaperService"
        android:label="Wear Digital WatchFace">
        <intent-filter>
            <action android:name="android.service.wallpaper.WallpaperService" />
            <category android:name="xxx.WATCHFACE" />
        </intent-filter>
        <meta-data
            android:name="android.service.wallpaper"
            android:resource="@xml/clock"/>
    </service>
</application>

I have created an AsyncLoader that needs to retrieve only this type of service, so my query looks like this one:

// query the available watch faces
Intent filter = new Intent("android.service.wallpaper.WallpaperService");
filter.addCategory("xxx.WATCHFACE");
List<ResolveInfo> watchFaces = packageManager.queryIntentServices(filter, 0);

But I get back nothing. I though that packageManager.queryIntentServices would return them but it doesn't. Any alternative? I don't want all available Live Wallpapers but only those who implement the category I mention before.

1

There are 1 best solutions below

0
On

So I have resolved using a different Intent Filter. First, I declare my Live Wallpapers using a special category owned by my company namespace:

<service
    android:name=".DigitalWallpaperService"
    android:label="Wear Digital WatchFace"
    android:enabled="true"
    android:permission="android.permission.BIND_WALLPAPER" >
    <intent-filter>
        <action android:name="android.service.wallpaper.WallpaperService" />
        <category android:name="ltd.mycompany.WATCHFACE" />
    </intent-filter>
    <meta-data
        android:name="android.service.wallpaper"
        android:resource="@xml/clock"/>
</service>

Then I simply query the available Wallpaper Services and filter using my Category:

// search all wallpaper service
Intent filter = new Intent(WallpaperService.SERVICE_INTERFACE);
filter.addCategory("ltd.mycompany.WATCHFACE");
List<ResolveInfo> watchFaces = packageManager.queryIntentServices(filter, PackageManager.GET_META_DATA);

I hope it can help somebody else.