{"id":15033198,"url":"https://github.com/linglongxin24/dylanstepcount","last_synced_at":"2025-04-08T11:08:06.341Z","repository":{"id":40669043,"uuid":"71214225","full_name":"linglongxin24/DylanStepCount","owner":"linglongxin24","description":"Android精准计步器","archived":false,"fork":false,"pushed_at":"2022-05-19T00:32:18.000Z","size":3226,"stargazers_count":1574,"open_issues_count":12,"forks_count":395,"subscribers_count":43,"default_branch":"master","last_synced_at":"2025-04-08T11:07:51.405Z","etag":null,"topics":["android"],"latest_commit_sha":null,"homepage":"http://blog.csdn.net/linglongxin24/article/details/52868803","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"wtfpl","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/linglongxin24.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-10-18T06:03:52.000Z","updated_at":"2025-03-23T08:46:51.000Z","dependencies_parsed_at":"2022-07-14T05:00:35.023Z","dependency_job_id":null,"html_url":"https://github.com/linglongxin24/DylanStepCount","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/linglongxin24%2FDylanStepCount","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/linglongxin24%2FDylanStepCount/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/linglongxin24%2FDylanStepCount/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/linglongxin24%2FDylanStepCount/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/linglongxin24","download_url":"https://codeload.github.com/linglongxin24/DylanStepCount/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247829491,"owners_count":21002995,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["android"],"created_at":"2024-09-24T20:20:21.759Z","updated_at":"2025-04-08T11:08:06.320Z","avatar_url":"https://github.com/linglongxin24.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Android精准计步开发\n 亲测在小米.魅族.华为上可用\n \u003cdiv  align=\"center\"\u003e    \n\u003cimg src=\"screenshots/主页.jpg\" width=\"30%\" height=\"30%\"/\u003e\n\u003cimg src=\"screenshots/锻炼计划.jpg\" width=\"30%\" height=\"30%\"/\u003e\n\u003cimg src=\"screenshots/历史记录.jpg\" width=\"30%\" height=\"30%\"/\u003e\n\u003c/div\u003e\n\n#### 下载体验\n\n![](screenshots/dylanstep.png)\n\n\n# 万分感谢项目中使用两位大神的算法\n\n * [xbase](http://www.jianshu.com/p/5d57f7fd84fa)\n\n * [finnfu](https://github.com/finnfu/stepcount/tree/master/demo%E4%BB%A5%E5%8F%8A%E7%AE%97%E6%B3%95%E6%96%87%E6%A1%A3)\n\n# 1.需要在AndroidManifest.xml中添加权限\n\n```xml\n    \u003c!--计歩需要的权限--\u003e\n    \u003cuses-permission android:name=\"android.permission.VIBRATE\" /\u003e\n    \u003cuses-permission android:name=\"android.permission.WRITE_SETTINGS\" /\u003e\n    \u003cuses-feature android:name=\"android.hardware.sensor.accelerometer\" /\u003e\n    \u003cuses-permission android:name=\"android.permission.RECEIVE_BOOT_COMPLETED\" /\u003e\n    \u003cuses-permission android:name=\"android.permission.MOUNT_UNMOUNT_FILESYSTEMS\" /\u003e\n    \u003cuses-feature\n        android:name=\"android.hardware.sensor.stepcounter\"\n        android:required=\"true\" /\u003e\n    \u003cuses-feature\n        android:name=\"android.hardware.sensor.stepdetector\"\n        android:required=\"true\" /\u003e\n\n```\n# 2.检测手机是否支持计歩\n\n```java\n /**\n     * 判断该设备是否支持计歩\n     *\n     * @param context\n     * @return\n     */\n    @TargetApi(Build.VERSION_CODES.KITKAT)\n    public static boolean isSupportStepCountSensor(Context context) {\n        // 获取传感器管理器的实例\n        SensorManager sensorManager = (SensorManager) context\n                .getSystemService(context.SENSOR_SERVICE);\n        Sensor countSensor = sensorManager.getDefaultSensor(Sensor.TYPE_STEP_COUNTER);\n        Sensor detectorSensor = sensorManager.getDefaultSensor(Sensor.TYPE_STEP_DETECTOR);\n        return countSensor != null || detectorSensor != null;\n    }\n```\n\n# 3.功能使用\n\n```java\n   \n    private boolean isBind = false;\n    private Messenger mGetReplyMessenger = new Messenger(new Handler(this));\n    private Messenger messenger;\n\n    /**\n     * 开启计步服务\n     */\n    private void setupService() {\n        Intent intent = new Intent(this, StepService.class);\n        isBind = bindService(intent, conn, Context.BIND_AUTO_CREATE);\n        startService(intent);\n\n\n    }\n    /**\n     * 从service服务中拿到步数\n     *\n     * @param msg\n     * @return\n     */\n    @Override\n    public boolean handleMessage(Message msg) {\n        switch (msg.what) {\n            case Constant.MSG_FROM_SERVER:\n                cc.setCurrentCount(10000, msg.getData().getInt(\"step\"));\n                break;\n        }\n        return false;\n    }\n\n\n    /**\n     * 用于查询应用服务（application Service）的状态的一种interface，\n     * 更详细的信息可以参考Service 和 context.bindService()中的描述，\n     * 和许多来自系统的回调方式一样，ServiceConnection的方法都是进程的主线程中调用的。\n     */\n    ServiceConnection conn = new ServiceConnection() {\n        /**\n         * 在建立起于Service的连接时会调用该方法，目前Android是通过IBind机制实现与服务的连接。\n         * @param name 实际所连接到的Service组件名称\n         * @param service 服务的通信信道的IBind，可以通过Service访问对应服务\n         */\n        @Override\n        public void onServiceConnected(ComponentName name, IBinder service) {\n            try {\n                messenger = new Messenger(service);\n                Message msg = Message.obtain(null, Constant.MSG_FROM_CLIENT);\n                msg.replyTo = mGetReplyMessenger;\n                messenger.send(msg);\n            } catch (RemoteException e) {\n                e.printStackTrace();\n            }\n        }\n\n        /**\n         * 当与Service之间的连接丢失的时候会调用该方法，\n         * 这种情况经常发生在Service所在的进程崩溃或者被Kill的时候调用，\n         * 此方法不会移除与Service的连接，当服务重新启动的时候仍然会调用 onServiceConnected()。\n         * @param name 丢失连接的组件名称\n         */\n        @Override\n        public void onServiceDisconnected(ComponentName name) {\n\n        }\n    };\n\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flinglongxin24%2Fdylanstepcount","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flinglongxin24%2Fdylanstepcount","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flinglongxin24%2Fdylanstepcount/lists"}