Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
301 views
in Technique[技术] by (71.8m points)

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

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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:

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...