我一直使用Android的 addProximityAlert
在 LocationManager
类方法添加了一个场所附近后。
I have added a location proximity later using Android's addProximityAlert
method in the LocationManager
class.
当用户的手机是一个特定的区域,在 LocationManager
发送意图
来我的应用程序的 BroadcastReciver
,这里是处理该意图类:
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));
}
}
我想用DashClock API显示更新时发生这种情况。 DashClock有一个 publishUpdate
方法,可以用来显示更新,但我只能用这个从我的扩展类,它扩展了 DashClock
类。这应该是一个可能的莫名其妙,但我似乎无法弄清楚如何。我如何能做到这一点任何想法?
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?
由于推广服务必须发出publishUpdate打电话,你接近触发广播接收器应该使用类似一个广播或事件总线要求扩展到发布更新。
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.
如果分机未初始化,意味着用户没有添加,或DashClock没有运行,那么什么都不会发生,这是预期和正确的行为。只要DashClock开始,你的扩展补充,onUpdateData将被调用,你就可以发布您的更新。
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:
全球广播,使用Context.sendBroadcast伴随着动态注册的广播接收器的 DashClockExtension
使用Context.registerReceiver.
Global broadcasts, using Context.sendBroadcast along with a dynamically registered broadcast receiver in your DashClockExtension
using Context.registerReceiver.
本地广播,使用LocalBroadcastManager.
一个完整的code段为全球广播可以在问题292中找到中的DashClock项目页面上。
A full code snippet for global broadcasts can be found in issue 292 on the DashClock project page.