Search code examples
androidandroid-activitycommunicationlive-wallpaper

Activity / Live Wallpaper communication in Android


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:

  1. Preview the live wallpaper from the Live Wallpaper Chooser
  2. Go into my custom Settings activity
  3. Click on a "Screen Shot" button or preference to open up a "Screen Shot" activity
  4. Send a message to my wallpaper, asking for a screen shot bitmap to be rendered
  5. The wallpaper service receives the message and renders its current visuals to a bitmap in the app's data directory
  6. The wallpaper sends a message back to the activity indicating success and location of the bitmap
  7. 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.


Solution

  • 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