我想在安卓上伪造位置。在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);
}
}所以,我想挂接这个方法。但我不知道如何挂接这种方法(使用PendingIntent)。因为PendingIntent在“某一天”会有数据,我不知道什么时候会发生。因此,方法requestLocationUpdates的前后挂钩似乎都不起作用,因为那时PendingIntent还没有任何数据。
请告诉我怎么做。
发布于 2016-11-01 00:49:40
您需要拦截广播接收器,而不是挂起的意图。您可以拦截LocationReceiver.onReceive并更改intent的内容。
要执行此操作,请通过定义onReceive来截取beforeHookedMethod。使用其参数(MethodHookParam params)检索意图(params.args[1])并更改其附加内容(intent.replaceExtras(bundle))。
确保您的新捆绑包具有相同的键(android.location.LocationManager.KEY_LOCATION_CHANGED),并且您可以设置自己的位置:
Location loc = new Location("yourprovider");
loc.setLatitude(66.6);
loc.setLongitude(66.6);https://stackoverflow.com/questions/40321694
复制相似问题