首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在BroadcastReceiver类中使用BroadcastReceiver吗,安卓?

在BroadcastReceiver类中使用BroadcastReceiver吗,安卓?
EN

Stack Overflow用户
提问于 2013-08-06 05:35:55
回答 1查看 327关注 0票数 0

在我的应用程序中,如果用户在广播的帮助下关闭了应用程序,那么在固定的时间间隔之后,我会试图找到用户的位置。

然而,在我的广播接收类中,我得到了用户位置所需的纬度和经度。但我如何使用lat和long找到用户的地址在它的帮助下。

地理编码器需要活动上下文,但是我有一个扩展广播接收器的类。

代码语言:javascript
复制
public class LocationReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {

        Bundle b=intent.getExtras();
        Location loc=(Location)b.get(LocationPoller.EXTRA_LOCATION);

        // Getting latitude
        double latitude = loc.getLatitude();

        // Getting longitude
        double longitude = loc.getLongitude();
        System.out.println( loc.getLatitude());
        System.out.println(     loc.getLongitude());

        addGet(latitude,longitude) 
    }

    public void addGet(double latitude,double longitude) {

        Geocoder  geocoder = new Geocoder(this, Locale.getDefault());

        try
        {
            List<Address> addresses = geocoder.getFromLocation(latitude, longitude, 1);
            Log.e("Addresses","-->"+addresses);
        }
        catch (IOException e)
        {
            e.printStackTrace();
        }
    }
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-08-06 05:42:25

传递上下文。

代码语言:javascript
复制
    addGet(context, latitude,longitude);

    public void addGet(Context context,double latitude,double longitude) {
       Geocoder  geocoder = new Geocoder(context, Locale.getDefault());
}
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/18072481

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档