【发布时间】:2014-01-30 16:34:48
【问题描述】:
我有一个显示图像的动态壁纸。我在活动中更改了该图像。然后我需要通知动态壁纸,让它知道重新加载资源。
Intents 似乎是完美、简单的解决方案:
Intent intent = new Intent(MyActivity.this, MyWallpaperService.class);
startService(intent);
我在 MyWallpaperService 中
@Override
public int onStartCommand (Intent intent, int flags, int startId) {...}
我还需要知道,在另一项服务中,用户何时点击屏幕。我使用完全相同的机制来发送和接收意图。
一切都在 Android 4.0+ 设备和模拟器上完美运行。 但我在 Android 2.2 和 2.3.3 模拟器上测试并得到以下错误:
java.lang.SecurityException: Not allowed to start service Intent { cmp=com.domain.name/.liveWallpaper.MyWallpaperService } without permission android.permission.BIND_WALLPAPER
我的清单在服务标签内包含正确的 android:permission:
<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>
为什么我只在旧版本(Android 2.2 和 2.3.3)上收到此错误?是否不允许或不推荐将 Intent 发送到 WallpaperService?这是否与只有系统才能绑定到具有 BIND_WALLPAPER 权限的服务这一事实有关? 最后,如果意图不起作用,有什么替代的、简单的解决方案?
【问题讨论】:
-
我不认为 WallpaperService 存在于 2.3 中?我认为只有在 API16 之后。所有的演示似乎都表明了这一点。
标签: android android-intent android-service live-wallpaper