Code Monkey home page Code Monkey logo

dylanstepcount's Introduction

Android精准计步开发

亲测在小米.魅族.华为上可用

下载体验

万分感谢项目中使用两位大神的算法

1.需要在AndroidManifest.xml中添加权限

    <!--计歩需要的权限-->
    <uses-permission android:name="android.permission.VIBRATE" />
    <uses-permission android:name="android.permission.WRITE_SETTINGS" />
    <uses-feature android:name="android.hardware.sensor.accelerometer" />
    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
    <uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS" />
    <uses-feature
        android:name="android.hardware.sensor.stepcounter"
        android:required="true" />
    <uses-feature
        android:name="android.hardware.sensor.stepdetector"
        android:required="true" />

2.检测手机是否支持计歩

 /**
     * 判断该设备是否支持计歩
     *
     * @param context
     * @return
     */
    @TargetApi(Build.VERSION_CODES.KITKAT)
    public static boolean isSupportStepCountSensor(Context context) {
        // 获取传感器管理器的实例
        SensorManager sensorManager = (SensorManager) context
                .getSystemService(context.SENSOR_SERVICE);
        Sensor countSensor = sensorManager.getDefaultSensor(Sensor.TYPE_STEP_COUNTER);
        Sensor detectorSensor = sensorManager.getDefaultSensor(Sensor.TYPE_STEP_DETECTOR);
        return countSensor != null || detectorSensor != null;
    }

3.功能使用

   
    private boolean isBind = false;
    private Messenger mGetReplyMessenger = new Messenger(new Handler(this));
    private Messenger messenger;

    /**
     * 开启计步服务
     */
    private void setupService() {
        Intent intent = new Intent(this, StepService.class);
        isBind = bindService(intent, conn, Context.BIND_AUTO_CREATE);
        startService(intent);


    }
    /**
     * 从service服务中拿到步数
     *
     * @param msg
     * @return
     */
    @Override
    public boolean handleMessage(Message msg) {
        switch (msg.what) {
            case Constant.MSG_FROM_SERVER:
                cc.setCurrentCount(10000, msg.getData().getInt("step"));
                break;
        }
        return false;
    }


    /**
     * 用于查询应用服务(application Service)的状态的一种interface,
     * 更详细的信息可以参考Service 和 context.bindService()中的描述,
     * 和许多来自系统的回调方式一样,ServiceConnection的方法都是进程的主线程中调用的。
     */
    ServiceConnection conn = new ServiceConnection() {
        /**
         * 在建立起于Service的连接时会调用该方法,目前Android是通过IBind机制实现与服务的连接。
         * @param name 实际所连接到的Service组件名称
         * @param service 服务的通信信道的IBind,可以通过Service访问对应服务
         */
        @Override
        public void onServiceConnected(ComponentName name, IBinder service) {
            try {
                messenger = new Messenger(service);
                Message msg = Message.obtain(null, Constant.MSG_FROM_CLIENT);
                msg.replyTo = mGetReplyMessenger;
                messenger.send(msg);
            } catch (RemoteException e) {
                e.printStackTrace();
            }
        }

        /**
         * 当与Service之间的连接丢失的时候会调用该方法,
         * 这种情况经常发生在Service所在的进程崩溃或者被Kill的时候调用,
         * 此方法不会移除与Service的连接,当服务重新启动的时候仍然会调用 onServiceConnected()。
         * @param name 丢失连接的组件名称
         */
        @Override
        public void onServiceDisconnected(ComponentName name) {

        }
    };

dylanstepcount's People

Contributors

linglongxin24 avatar shade34321 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

dylanstepcount's Issues

多次计步的情况

把StepService类添加到自己的项目中,多次退出再进入后 onSensorChanged 方法会多次执行,步数比Demo多几倍,请问下这是什么情况了?

问题很大

人不动。一直摇动手机都在计步,哪门子的准确?

报错

在我的一加5t上运行会偶然出现如下报错导致崩溃
04-02 13:52:15.213 20931-20931/? E/BoostFramework: BoostFramework() : Exception_1 = java.lang.NoSuchMethodException: perfIOPrefetchStart [int, class java.lang.String]
04-02 13:52:15.214 20931-20931/? E/BoostFramework: BoostFramework() : Exception_1 = java.lang.NoSuchMethodException: perfIOPrefetchStart [int, class java.lang.String]
04-02 13:52:31.894 20931-20931/cn.bluemobi.dylan.step E/BoostFramework: BoostFramework() : Exception_1 = java.lang.NoSuchMethodException: perfIOPrefetchStart [int, class java.lang.String]
BoostFramework() : Exception_1 = java.lang.NoSuchMethodException: perfIOPrefetchStart [int, class java.lang.String]
04-02 13:52:35.831 20931-21150/cn.bluemobi.dylan.step E/chromium: [ERROR:instance.cc(49)] Unable to locate service manifest for metrics
[ERROR:service_manager.cc(890)] Failed to resolve service name: metrics

无效

我在华为荣耀5c上安装,永远0步,不计步。需要什么硬件要求吗

实现的很不错,不过还是有几个问题想请教

这个里面的services似乎都作废了呢,不知道是否还要保留呢==
https://github.com/linglongxin24/DylanStepCount/tree/master/app/src/main/java/cn/bluemobi/dylan/step/pedometer
计步算法有待优化。。。疯狂摇晃手机也会起到计步的效果。。。这样就可以作弊啊
如上提到的计步算法应该是在这里的,不过看项目虽然不用了但是似乎还是保留在里面
https://github.com/bagilevi/android-pedometer

小米手机3测试遇到的问题

不知道什么原因 服务是处于活跃状态 onSensorChanged只在注册是回调了一次 后续摇晃手机不回调 但是当我打开咕咚的计步器后 摇晃手机 又能正常回调 给人感觉是没有激活的状态 非常的奇怪

代码集成问题

我把代码集成到自己项目中,有两个问题

  1. notification不显示,针对android p的机器,我已经做了android 8.0的通知适配,还是不行
  2. 计步不工作,摇手机也不行

有啥好的思路或者还需要提供更多的信息吗?

请问如果防作弊的话,思路大概是怎么实现呀?

  1. 判断gps+移动网络信号。
  2. 写入步数的表同时记录时间,再次写入的步数和上次的时间,超过人类能达到的步数,就算作弊数据不记录。(但这种无法判断真实性,只是合理) ,只能做第一次判断。

大概还有什么方式能防作弊呢?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.