Question

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?

Was it helpful?

Solution 4

I still haven't found a exact explanation for why this isn't working, but I found a solution:

Creating a BroadcastReceiver that will receive my custom Intents. This means I will no longer be using startService(intent), but sendBroadcast(intent), which will not cause permission issues. See the references for more explanations and code.

References:

https://groups.google.com/forum/#!topic/android-developers/N8TzbbKwd5o

Permission to BIND_WALLPAPER required when messaging WallpaperService from Settings Activity

OTHER TIPS

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

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

means you probably forgot to declare the BIND_WALLPAPER permission within your AndroidManifest.xml like this:

 <service
   android:enabled="true"
   android:name="MyWallpaperService"
   android:permission="android.permission.BIND_WALLPAPER" />

Android Livewallpaper settings fail to load from 'configure...' menu

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
  package="com.android.RrD"
  android:versionCode="1"
  android:versionName="1.0">

<uses-sdk android:minSdkVersion="8" />

<uses-feature android:name="android.software.live_wallpaper" />

<uses-permission android:name="android.permission.INTERNET" />

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.BIND_WALLPAPER" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

   <application 
    android:icon="@drawable/icon" 
    android:label="@string/app_name" 
    >

    <service android:name=".LiveWallpaper"
        android:label="@string/app_name"
        android:icon="@drawable/icon"
        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" />

    </service>

<activity android:label="PAM_Prefs"
        android:name=".PAM_Prefs" 

        android:exported="true" android:icon="@drawable/icon">
         <intent-filter>

            <category android:name="android.intent.category.PREFERENCE" />
        </intent-filter>
    </activity>

</application>
</manifest>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top