How do I publish an update to Dashclock when my application receives an Intent?

对着背影说爱祢 提交于 2019-11-28 06:48:24

问题


I have added a location proximity later using Android's addProximityAlert method in the LocationManager class.

When the user's phone is a particular area, the LocationManager sends an Intent to my application's BroadcastReciver and here is the class that handles the intent:

public class ProximityTrigger extends BroadcastReceiver {

    @Override
    public void onReceive(Context ctxContext, Intent ittIntent) {            
        System.out.println(ittIntent.getIntExtra(WidgetService.KEY_STOP_IDENTIFIER, -1));               
    }

}

I'd like to use the DashClock API to show an update when this happens. DashClock has a publishUpdate method that can be used to show updates but I can only use this from my extension class that extends the DashClock class. This should be a possible somehow but I can't seem to figure out how. Any ideas on how I could accomplish this?


回答1:


Since the extension service must issue the publishUpdate call, your proximity trigger broadcast receiver should use something like a broadcast or an event bus to ask the extension to publish an update.

If the extension isn't initialized, meaning the user hasn't added it or DashClock isn't running, then nothing will happen, which is the expected and correct behavior. As soon as DashClock starts and your extension is added, onUpdateData will be called and you'll be able to publish your update.

For some ideas on the actual classes you can use, see below:

  • Global broadcasts, using Context.sendBroadcast along with a dynamically registered broadcast receiver in your DashClockExtension using Context.registerReceiver.

  • Local broadcasts, using LocalBroadcastManager.

  • Otto or EventBus, two frameworks that let application components publish and subscribe to events. In this case, the extension subscribes and your proximity sensor publishes.

A full code snippet for global broadcasts can be found in issue 292 on the DashClock project page.



来源:https://stackoverflow.com/questions/15567702/how-do-i-publish-an-update-to-dashclock-when-my-application-receives-an-intent

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!