我想在android中伪造位置。在 android 中,有一种方法可以使用PendingIntent
. 这是一个例子:
LocationManager service = (LocationManager) getSystemService(LOCATION_SERVICE);
String proximitys = "ACTION";
IntentFilter filter = new IntentFilter(proximitys);
LocationReceiver mReceiver = new LocationReceiver();
registerReceiver(mReceiver, filter);
Intent intent = new Intent(proximitys);
PendingIntent proximityIntent = PendingIntent.getBroadcast(this, 0,
intent, PendingIntent.FLAG_CANCEL_CURRENT);
service.requestLocationUpdates("network", 1000, 0.001f, proximityIntent);
并BroadcastReceiver
在新位置更改时收到事件:
public class LocationReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
//Do this when the system sends the intent
Bundle b = intent.getExtras();
Location loc = (Location)b.get(android.location.LocationManager.KEY_LOCATION_CHANGED);
}
}
所以,我想挂钩这个方法。但我不知道如何挂钩这种方法(即 using PendingIntent
)。因为PendingIntent
在“某个未来”会有数据,我不知道什么时候会发生。所以在方法之前和之后挂钩requestLocationUpdates
似乎不起作用,因为当时PendingIntent
还没有任何数据。
请告诉我如何做到这一点。