安卓系统模拟位置(刷为系统app)

现在安卓玩pokemongo,虚拟定位比较常用的欺骗方法是将fake gps软件弄为系统app,用其他普通的方法模拟定位会被检测出来。不过之前不明白是什么原理,所以到github上找了找,找到了xiangtailiang/FakeGPS: FakeGPS is a GPS device simulator, GPS location signal keep output according to the coordinates. By the direction keys on the joystick, the user can simulate walking on the map. (github.com)

实现就是依靠反射得到LocationManager对象的ILocationManager这个对象,调用其reportLocation方法上传坐标,需要INSTALL_LOCATION_PROVIDER权限。ILocationManager是一个AIDL接口,所以还需要创建android.location.ILocationManager.aidl文件

    private static ILocationManager mILocationManager;
    private void mock(){
        mLocationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
        Field declaredField = null;
        try {
            declaredField = Class.forName(mLocationManager.getClass().getName()).getDeclaredField("mService");
            declaredField.setAccessible(true);
            mILocationManager = (ILocationManager) declaredField.get(mLocationManager);
        } catch (Exception e) {
            e.printStackTrace();
        }
        new Thread(new Runnable() {
            @Override
            public void run() {
                while(true){
                    try {
                        Thread.sleep(100);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    Location location = new Location(LocationManager.GPS_PROVIDER);
                    try {
                        location.setLatitude(35.6925);
                        location.setLongitude(139.7564);
                        location.setAltitude(5);
                        if (Build.VERSION.SDK_INT > Build.VERSION_CODES.JELLY_BEAN_MR1) {
                            location.setElapsedRealtimeNanos(SystemClock.elapsedRealtimeNanos());
                        }
                        location.setAccuracy(10);
                        location.setSpeed(0);
                        location.setTime(System.currentTimeMillis());
                        mILocationManager.reportLocation(location, false);
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            }
        }).start();
    }

这个只上报了gps provider。所以用的时候需要手机定位模式设为only gps

此方法不需要打开模拟位置开关也不需要手机root,所以能够避免被pokemongo检测到,只需要有个能够解锁BL刷TWRP或者其他的recovery包,用他们的文件管理器功能移动这个加入了上面代码的应用到/system/priv-app目录中即可。也可以用现成的应用,我目前用的是theappninjas的gpsjoystick这个应用,这个应用里面有隐私模式能够下载生成一个app的副本,将这个副本移动到/system/priv-app然后卸载掉原来的app即可。

其次这个方法:只是往系统的API中增加了一个GPS Provider,并没有改变原来GPS的读取。如果真实的GPS也定位成功,一个真信号一个假信号会交替出现,就会发生瞬移的现象。

     所以为了屏蔽真实的gps信号,买个gps屏蔽器就行了,某宝50元就能买到,自己去搜索,如果某宝买不到,那么就到搜不到gps信号的地方比如地下停车场或者房子内远离窗户的地方,或者用锡纸包住手机周围不让手机的GPS接收器接收到GPS即可。

  • 8
    点赞
  • 49
    收藏
    觉得还不错? 一键收藏
  • 6
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值