首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Xposed:如何使用PendingIntent钩子方法

Xposed:如何使用PendingIntent钩子方法
EN

Stack Overflow用户
提问于 2016-10-30 01:25:38
回答 1查看 397关注 0票数 0

我想在安卓上伪造位置。在android中,有一种使用PendingIntent获取位置的方法。下面是一个示例:

代码语言:javascript
复制
        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会收到事件:

代码语言:javascript
复制
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还没有任何数据。

请告诉我怎么做。

EN

回答 1

Stack Overflow用户

发布于 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),并且您可以设置自己的位置:

代码语言:javascript
复制
Location loc = new Location("yourprovider");
loc.setLatitude(66.6);
loc.setLongitude(66.6);
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/40321694

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档