我想向我的位置管理器添加近似警报。我给出纬度和经度,并在距离参数中给出 20。当我从模拟器中给出相同的纬度和经度时,我的近似未决意图不会触发。怎么了?
这是我的 onCreate()
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
lm = (LocationManager) getSystemService(LOCATION_SERVICE);
lm.addProximityAlert(31.4474, 73.08, 20, -1, PendingIntent.getActivity(
Main.this, 0, new Intent(android.content.Intent.ACTION_VIEW,
Uri.parse("http://www.google.com")), 0));
lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, new LocationListener() {
@Override
public void onStatusChanged(String arg0, int arg1, Bundle arg2) {}
@Override
public void onProviderEnabled(String arg0) {}
@Override
public void onProviderDisabled(String arg0) {}
@Override
public void onLocationChanged(Location arg0) {
Toast.makeText(Main.this,arg0.getLatitude()+" "+arg0.getLongitude(), 300).show();
}
});
}
清单.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.proximityalert"
android:versionCode="1"
android:versionName="1.0"
>
<uses-sdk
android:minSdkVersion="6"
android:targetSdkVersion="10" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION"/>
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.proximityalert.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>