sd 完成加载后设备启动时运行服务
我在设备启动时运行一项服务,该服务仅从 SD 卡加载图像并将其设为壁纸。当设备启动时,我收到错误消息。但在 SD 卡完成加载后,服务会将图像设置为壁纸。
<action android:name="android.intent.action.BOOT_COMPLETED" />
我像这样启动服务^,我想问是否有办法在sd卡加载完成后启动服务。
I run a service when the device boots and that service just loads an image from sd card and makes it wallpaper. When the device starts i get an error. But after the sd card finishes the loading the service sets the image as wallpaper fine.
<action android:name="android.intent.action.BOOT_COMPLETED" />
I start the service like this ^ and i want to ask if there is a way to start the service after sd card finishes loading.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
编辑:我不知道 MEDIA_MOUNTED 的意图,我会使用下面发布的答案。
我要做的就是按照你拥有的方式启动服务,并在服务内部不断检查 SD 卡何时安装,也许每 300 毫秒或其他时间。这个问题展示了如何检测是否sdcard是否已挂载。
Edit: I didn't know there was a intent for MEDIA_MOUNTED, I would use the answer posted below instead.
What I would do is launch the service how you have it and inside of the service keep checking to see when the sdcard is mounted, maybe every 300ms or something. This question shows how to detect if the sdcard has been mounted or not.
MEDIA_MOUNTED 操作将在此处起作用,但您必须在清单文件中包含它的意图过滤器,并且还必须将接收器意图过滤器的数据方案更改为“文件”。
The MEDIA_MOUNTED action will work here, but you must include an intent filter for it in the manifest file, and you must also change the data scheme for the receiver's intent filter to "file" as well.
在安装媒体(SD 卡)并将操作设置为 MEDIA_MOUNTED。
There's an intent broadcast for after media (SD card) is mounted with the action set to MEDIA_MOUNTED.
您可以等待 SD 卡加载。一种方法是使用
android.intent.action.MEDIA_MOUNTED
操作。另一种方法是轮询到某个最大值,如果未安装则放弃:
希望这会有所帮助。
You can wait for the SD card to load. One way is to use the
android.intent.action.MEDIA_MOUNTED
action.Another way is to poll up to some maximum and give up if not mounted:
Hope this helps.