Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Launch Intent from and to a WallpaperService

I have a live wallpaper which displays an image. I change that image in an activity. I then need to notify the live wallpaper, so it knows to reload the resources.

Intents seemed like the perfect, simple, solution:

Intent intent = new Intent(MyActivity.this, MyWallpaperService.class);
startService(intent);

I and in MyWallpaperService

@Override   
public int onStartCommand (Intent intent, int flags, int startId) {...}

I also need to know, in another service, when the user taps the screen. I use the exact same mechanism of sending and receiving the intent.

Everything is working perfectly on Android 4.0+ devices and emulators. But I tested on Android 2.2 and 2.3.3 emulator and get the following error:

java.lang.SecurityException: Not allowed to start service Intent { cmp=com.domain.name/.liveWallpaper.MyWallpaperService } without permission android.permission.BIND_WALLPAPER

My manifest contains the correct android:permission inside the service tag:

    <service
        android:name=".liveWallpaper.MyWallpaperService"
        android:label="@string/app_name"
        android:permission="android.permission.BIND_WALLPAPER" >
        <intent-filter>
            <action android:name="android.service.wallpaper.WallpaperService" />
        </intent-filter>
        <meta-data
            android:name="android.service.wallpaper"
            android:resource="@xml/livewallpaper_data" />
    </service>

Why do I get this error only on old versions(Android 2.2 and 2.3.3)? Is sending Intents to a WallpaperService not allowed or recommended? Does it have something to do with the fact that only the system can bind to a service with the BIND_WALLPAPER permission? In the end, if intents do not work, what is an alternative, simple, solution?

like image 788
Twinsen Avatar asked Nov 20 '25 03:11

Twinsen


1 Answers

try to add the permission to your Service in the manifest file , like the following :

<service android:name=".LiveWallpaper"
android:label="@string/app_name"
android:icon="@drawable/icon"
android:permission="android.permission.BIND_WALLPAPER">

Hope that Helps


Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!