gpt4 book ai didi

android - 从 WallpaperService 启动 Intent 或向 WallpaperService 启动 Intent

转载 作者:太空宇宙 更新时间:2023-11-03 13:25:22 30 4
gpt4 key购买 nike

我有一个显示图像的动态壁纸。我在 Activity 中更改了该图像。然后我需要通知动态壁纸,以便它知道重新加载资源。

Intent 似乎是完美、简单的解决方案:

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

我和 MyWallpaperService

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

我还需要知道,在另一个服务中,用户何时点击屏幕。我使用完全相同的发送和接收 Intent 的机制。

一切都在 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

我的 list 在服务标签中包含正确的 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)到具有 BIND_WALLPAPER 权限的服务有关?最后,如果 Intent 不起作用,什么是替代的、简单的解决方案?

最佳答案

尝试在 list 文件中为您的服务添加权限,如下所示:

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

希望对你有帮助

关于android - 从 WallpaperService 启动 Intent 或向 WallpaperService 启动 Intent,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21253438/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com