Android onLocationChanged方法不调用

Android onLocationChanged方法不调用,android,location,Android,Location,我搜索了很多,在stackoverflow里面也看到了很多帖子,但是没有得到回复,或者说不清楚也不复杂。很简单,我想在从emulator控件发送经度和纬度时调用onLocationChanged方法,所以我在main.xml文件中编写了以下代码: <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tool

我搜索了很多,在stackoverflow里面也看到了很多帖子,但是没有得到回复,或者说不清楚也不复杂。很简单,我想在从emulator控件发送经度和纬度时调用onLocationChanged方法,所以我在main.xml文件中编写了以下代码:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.mrg.findlocation.Main$PlaceholderFragment" >

    <TextView
        android:id="@+id/textview"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/hello_world" />

</RelativeLayout>
和内部清单文件:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.mrg.findlocation"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="14"
        android:targetSdkVersion="19" />

    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
    <uses-permission android:name="android.permission.INTERNET"/>

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.mrg.findlocation.Main"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>
此代码在emulator上工作

locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationListner);

我认为问题在于,您正在向网络提供商请求更新,而仿真器使用GPS提供商

尝试更改:

locationManager.requestLocationUpdatesLocationManager.NETWORK\u提供程序,0,0,locationListner

与:


locationManager.requestLocationUpdatesLocationManager.GPS_提供程序,0,0,locationListner

尝试在活动类上实现LocationListener

public class Main extends Activity implements LocationListener { 

@Override
public void onLocationChange(Location location){
// do something
  }
}
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationListner);
public class Main extends Activity implements LocationListener { 

@Override
public void onLocationChange(Location location){
// do something
  }
}