3

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?

Twinsen
  • 458
  • 3
  • 12
  • 1
    Try this solution: http://stackoverflow.com/questions/20915926/communicate-with-a-wallpaperservice – Chiral Code Jan 23 '14 at 13:25
  • I dont think the WallpaperService exists in 2.3? I think it is only after API16. All the demos seem to indicate this. – Radu Dec 24 '14 at 04:49

4 Answers4

1

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" />
Ben Weiss
  • 17,182
  • 6
  • 67
  • 87
  • Adding this to the manifest gives me: "Permission is only granted to system apps". This permission is meant to be added to the service, like this: . The permission is added correctly, since everything works well on all the Android 4.0+ devices I tested. – Twinsen Jan 21 '14 at 09:09
  • See https://stackoverflow.com/questions/13801984/permission-is-only-granted-to-system-app for another solution. – Ben Weiss Jan 21 '14 at 09:12
  • My app is not a system app and must work on non-rooted devices – Twinsen Jan 21 '14 at 09:15
  • I just re-checked and have updated my answer. You'll need to declare the permission for your wallpaper service. – Ben Weiss Jan 21 '14 at 09:19
  • Like I said in the original question and in the first comment, I have added this permission. It is recognized, since removing the permission completely removes my live wallpaper functionality. – Twinsen Jan 21 '14 at 09:28
1

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

  • Adding this to the manifest gives me: "Permission is only granted to system apps" – Twinsen Jan 21 '14 at 09:10
  • Window -> Preferences -> Android -> Lint Error Checking. Find ProtectedPermission from the list and set the severity to something other than error(info for example). This way your project will still compile. –  Jan 21 '14 at 09:41
1

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>
Community
  • 1
  • 1
rajahsekar
  • 916
  • 1
  • 11
  • 25
  • I tried adding android.permission.BIND_WALLPAPER to the root, or in the application, service and in my activity tags. All in different combinations. This really isn't the issue. The permission was added correctly from the beginning. – Twinsen Jan 30 '14 at 08:41
1

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

Community
  • 1
  • 1
Twinsen
  • 458
  • 3
  • 12