从Smartwatch Android Wear到智能手机获取数据 [英] Get data from Smartwatch Android Wear to Smartphone

查看:216
本文介绍了从Smartwatch Android Wear到智能手机获取数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为android穿戴的moto360制作了一些应用程序(计步器,心率,录音机).一切正常,但我不知道如何将数据保存在手表上以及如何访问智能手机上的数据.我已经设法向手表发送了消息,但是无法将数据从手表发送到手机.我可以将数据保存在智能手机上,但是我不知道如何在智能手表上进行管理.有人可以给我看一个教程或例子吗?非常感谢你!

I have made some apps (pedometer, heart rate, audio recorder) for the moto360 with android wear. everything works fine, but I don't know how to save the data on the watch and how to access the data on the smartphone. I have managed to send messages to the watch, but I can't send data from the watch to the phone. I can save my data on the smartphone, but I don't know how to manage it on the smartwatch. can someone show me a tutorial or an example? thank you so much!

下面的以下代码用于跟踪Moto360上的心率,并且可以正常工作. 我尝试将使用本教程的数据从手表传输到手机-> https://developer.android.com/training/wearables/data-layer/data-items.html

edit: The following Code below is used for tracking the heartrate on the Moto360 and it works fine. I tried to transfer the data from the watch to the Phone for that I used this tutorial -> https://developer.android.com/training/wearables/data-layer/data-items.html

从android页面实现代码后,我无法在设备上运行项目!

After implementing the Code from the android page I couldn`t run the Project on the device!

    public class MainActivity extends Activity implements SensorEventListener {


        private static final String TAG = "MainActivity";
        private TextView mTextViewStepCount;
        private TextView mTextViewStepDetect;
        private TextView mTextViewHeart;
        PutDataMapRequest dataMap = PutDataMapRequest.create("/count");
        GoogleApiClient mGoogleApiClient;

        @Override
        protected void onCreate(Bundle savedInstanceState) {


            getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);

            final WatchViewStub stub = (WatchViewStub) findViewById(R.id.watch_view_stub);
            stub.setOnLayoutInflatedListener(new WatchViewStub.OnLayoutInflatedListener() {
                @Override
                public void onLayoutInflated(WatchViewStub stub) {

                    mTextViewStepCount = (TextView) stub.findViewById(R.id.step_count);
                    mTextViewStepDetect = (TextView) stub.findViewById(R.id.step_detect);
                    mTextViewHeart = (TextView) stub.findViewById(R.id.heart);
                    getStepCount();

                }
            });
        }

        private void getStepCount() {
            SensorManager mSensorManager = ((SensorManager) getSystemService(SENSOR_SERVICE));
            Sensor mHeartRateSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_HEART_RATE);
            Sensor mStepCountSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_STEP_COUNTER);
            Sensor mStepDetectSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_STEP_DETECTOR);

            mSensorManager.registerListener(this, mHeartRateSensor, SensorManager.SENSOR_DELAY_NORMAL);
            mSensorManager.registerListener(this, mStepCountSensor, SensorManager.SENSOR_DELAY_NORMAL);
            mSensorManager.registerListener(this, mStepDetectSensor, SensorManager.SENSOR_DELAY_NORMAL);
        }

        private String currentTimeStr() {
            Calendar c = Calendar.getInstance();
            SimpleDateFormat df = new SimpleDateFormat("HH:mm:ss");
            return df.format(c.getTime());
        }

        public void onAccuracyChanged(Sensor sensor, int accuracy) {
            Log.d(TAG, "onAccuracyChanged - accuracy: " + accuracy);
        }

        public void onSensorChanged(SensorEvent event) {
            if (event.sensor.getType() == Sensor.TYPE_HEART_RATE) {
                String msg = "" + (int) event.values[0];

                mTextViewHeart.setText(msg);
                Log.d(TAG, msg);

            } else if (event.sensor.getType() == Sensor.TYPE_STEP_COUNTER) {
                String msg = "Count: " + (int) event.values[0];
                mTextViewStepCount.setText(msg);
                Log.d(TAG, msg);
            } else if (event.sensor.getType() == Sensor.TYPE_STEP_DETECTOR) {
                String msg = "Detected at " + currentTimeStr();
                mTextViewStepDetect.setText(msg);
                Log.d(TAG, msg);
            } else {
                Log.d(TAG, "Unknown sensor type");
            }
        }
    }

推荐答案

此代码对我有很大帮助,希望对其他人有帮助:)

this code helps me a lot, i hope it helps many other people :)

https://github.com/pocmo/SensorDashboard

这篇关于从Smartwatch Android Wear到智能手机获取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆