听LocationManager.GPS_PROVIDER不引发任何LocationListener的事件 [英] listening to LocationManager.GPS_PROVIDER doesn't fire any LocationListener events

查看:362
本文介绍了听LocationManager.GPS_PROVIDER不引发任何LocationListener的事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:
  <一href="http://stackoverflow.com/questions/8732079/problems-with-getting-gps-status-from-the-locationmanager-in-android">Problems与得到GPS状态从LocationManager Android中

看来,当我requestLocationUpdates,听LocationManager.GPS_PROVIDER 我不要得到任何事件,但如果我听LocationManager.NETWORK_PROVIDER我的 DO 获取更新

It seems that when I requestLocationUpdates and listen to LocationManager.GPS_PROVIDER I DON'T get any events, but if I listen to LocationManager.NETWORK_PROVIDER I DO get updates

所以这一块,与NETWORK_PROVIDER工作。我到onLocationChanged方式:

So this one, with NETWORK_PROVIDER works. I get to the onLocationChanged method:

LocationManager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);

    // Define a listener that responds to location updates
    LocationListener locationListener = new LocationListener() {
        public void onLocationChanged(Location location) {
            // Called when a new location is found by the network location provider.
            textView.setText(textView.getText().toString() + "GOT SOMETHING\n");
        }

        public void onStatusChanged(String provider, int status, Bundle extras) {
            textView.setText(textView.getText().toString() + status + "onStatus Changed \n");
        }

        public void onProviderEnabled(String provider) {
            textView.setText(textView.getText().toString() + "onProviderEnabled \n");
        }

        public void onProviderDisabled(String provider) {
            textView.setText(textView.getText().toString() + "onProviderDisabled \n");
        }
    };
    locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locationListener);

本之一,GPS_PROVIDER不起作用。我从来没有任何实现的方法。 (onLocationChanged,onStatusChanged等):

This one with GPS_PROVIDER doesn't work. I never get to any of the implemented methods. (onLocationChanged,onStatusChanged etc):

LocationManager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);

    // Define a listener that responds to location updates
    LocationListener locationListener = new LocationListener() {
        public void onLocationChanged(Location location) {
            // Called when a new location is found by the network location provider.
            textView.setText(textView.getText().toString() + "GOT SOMETHING\n");
        }

        public void onStatusChanged(String provider, int status, Bundle extras) {
            textView.setText(textView.getText().toString() + status + "onStatus Changed \n");
        }

        public void onProviderEnabled(String provider) {
            textView.setText(textView.getText().toString() + "onProviderEnabled \n");
        }

        public void onProviderDisabled(String provider) {
            textView.setText(textView.getText().toString() + "onProviderDisabled \n");
        }
    };
    locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationListener);

这是与Android的错误?

Is this a bug with Android?

我的GPS上,并在状态栏有坚实的GPS图标。我不知道这是相当重要的一群,因为我应该得到的onStatusChanged在任何情况下... 另外,我有&LT;使用-权限的Andr​​oid:名称=android.permission.ACCESS_FINE_LOCATION/&GT;

My GPS is on, and the status bar has the GPS icon on solid. I don't know if this matters a bunch because I should be getting to the onStatusChanged in either case... Also, I have the <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

推荐答案

所以我做了什么NickT建议,并从我的大楼走了一段路走,最后我开始这些事件。所以,我的code是很好,这是我的设备上只是我的信号强度差。

So I did what NickT suggested and walked a ways away from my building and finally I started getting these events. So my code was fine, it was just my signal strength on my device was poor.

具有GPS测试的应用程序是非常有帮助。

Having the GPS Test app was very helpful as well.

这篇关于听LocationManager.GPS_PROVIDER不引发任何LocationListener的事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆