Android 中的活动/动态壁纸通信
我有一个动态壁纸,我想与同一包中的活动进行通信。我从来没有做过任何服务方面的工作。我可以使用本地服务模式吗?我受到限制,因为我的服务是动态壁纸,需要使用 Intents 或 AIDL?
我认为流程会是这样的,请纠正我的过程可能失败的地方:
- 从动态壁纸选择器预览动态壁纸
- 进入我的自定义设置活动
- 单击“屏幕截图”按钮或首选项以打开“屏幕” Shot”活动
- 向我的壁纸发送消息,要求渲染屏幕截图位
- 图 壁纸服务接收消息并将其当前视觉效果渲染为应用程序数据目录中的
- 位图 壁纸向活动发回一条消息,指示成功并位图的位置
- 活动接收此消息,从给定位置加载位图,并将其显示给用户以进行进一步处理/共享
我不确定的部分是 4-7 中传递的消息。
I've got a live wallpaper that I'd like to communicate with from an Activity in the same package. I've never done any work with services. Would I be able to use the Local Service pattern, or am I restricted because my service is a live wallpaper, and need to use Intents or AIDL?
I think the flow would go something like this, please correct me where my process might fail:
- Preview the live wallpaper from the Live Wallpaper Chooser
- Go into my custom Settings activity
- Click on a "Screen Shot" button or preference to open up a "Screen Shot" activity
- Send a message to my wallpaper, asking for a screen shot bitmap to be rendered
- The wallpaper service receives the message and renders its current visuals to a bitmap in the app's data directory
- The wallpaper sends a message back to the activity indicating success and location of the bitmap
- The activity receives this message, loads the bitmap from the given location, and displays it to the user for further processing / sharing
The parts I'm not sure about are the message passing in 4-7.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这就是我最终所做的。我的主要目标是让我的动态壁纸创建其内容的屏幕截图。我不需要当前预览或主屏幕上实际显示的任何内容,只需基于当前共享首选项的渲染。
我将壁纸服务的渲染方面分解为一个单独的类。我的壁纸服务拥有此渲染类的一个实例,通过调用此渲染器,动态壁纸可以正常运行。断开的类允许我从任何其他活动实例化一个独立的渲染器,我可以向其发送位图。然后,渲染器只需绘制指向所提供位图的画布,而不是在正常情况下从壁纸服务提供的画布
Here's what I ended up doing. My primary goal was to get my live wallpaper to create a screenshot of its contents. I didn't need the current preview or whatever was actually being displayed on the home screen, just a render based on the current shared preferences.
I broke out the rendering aspects of the wallpaper service into a separate class. My wallpaper service holds an instance of this rendering class, and by making calls to this renderer, the live wallpaper functions as normal. The broken-out class allows me to instantiate an independent renderer from any other activity, to which I can send a bitmap. The renderer then simply draws to a canvas pointing at the provided bitmap, as opposed to the canvas provided from the wallpaper service under normal circumstances