我正在尝试在下面设置接近警报是我的代码,但它根本没有触发
Intent intent = new Intent(ACTION_PROXIMITY_ALERT);
pendingIntent = PendingIntent.getBroadcast(GMapsActivity.this, 0, intent, 0);
locationManager.addProximityAlert(mNavigationDatas.get(CURRENT_INDEX).startCordinates.latitude,
mNavigationDatas.get(CURRENT_INDEX).startCordinates.longitude, 100f, -1, pendingIntent);
IntentFilter filter = new IntentFilter(ACTION_PROXIMITY_ALERT);
registerReceiver(new ProximityBroadcastListener(), filter);
权限如下
<uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
我正在发送模拟位置以在真实设备上测试 Android v4.1.2 模拟位置遵循正确的路径,但未调用广播侦听器
public class ProximityBroadcastListener extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
final String key = LocationManager.KEY_PROXIMITY_ENTERING;
final Boolean entering = intent.getBooleanExtra(key, false);
if (entering) {
String instruction = mNavigationDatas.get(CURRENT_INDEX).drivingInstuctions;
instruction = instruction.replaceAll("<[^>]*>", "");
Log.e("", instruction);
tts.speak(instruction, TextToSpeech.QUEUE_FLUSH, null);
Toast.makeText(context, "entering", Toast.LENGTH_SHORT).show();
} else {
locationManager.removeProximityAlert(pendingIntent);
CURRENT_INDEX++;
locationManager.addProximityAlert(mNavigationDatas.get(CURRENT_INDEX).startCordinates.latitude,
mNavigationDatas.get(CURRENT_INDEX).startCordinates.longitude, 100f, -1, pendingIntent);
Toast.makeText(context, "exiting", Toast.LENGTH_SHORT).show();
}
}
谢谢索拉布