心率监测器不提供反馈

Heart rate monitor doesn't give feedback

我正在尝试显示佩戴智能手表 (LG Urbane) 的人的心率。然而,传感器从不提供任何反馈。我在 Whosebug 上尝试了多种解决方案,但 none 有所作为。我已经添加了在我的手机和可穿戴设备清单中使用 body 传感器的许可请求,但我从未收到请求该许可的弹出窗口。卸载应用程序并重新安装也没有帮助。

这是我的 Activity:

public class Monitor extends WearableActivity implements SensorEventListener{

    // /Users/Lieven/Library/Android/sdk/platform-tools/adb connect 192.168.1.15
    // /Users/Lieven/Library/Android/sdk/platform-tools/adb -s 192.168.1.15:5555 uninstall be.ehb.dt.finalwork_lievenluyckx_v001


    private final String LOG_TAG = "Monitor";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_wear);
        setAmbientEnabled();


        Log.d(LOG_TAG, "onCreate");


        //JUISTE LETTERTYPE IN TEXTVIEWS ZETTEN
        Typeface custom_font = Typeface.createFromAsset(getAssets(),  "fonts/brusselineregular.ttf");

        TextView monitor_emotion_text = (TextView) findViewById(R.id.monitor_emotion_text);
        TextView monitor_bpm_counter = (TextView) findViewById(R.id.monitor_bpm_counter);
        TextView monitor_bpm_label = (TextView) findViewById(R.id.monitor_bpm_label);

        monitor_emotion_text.setTypeface(custom_font);
        monitor_bpm_counter.setTypeface(custom_font);
        monitor_bpm_label.setTypeface(custom_font);


       /*
       * SENSOR TUTORIAL
       * https://www.tutorialspoint.com/android/android_sensors.htm
       * DOOR tutorialspoint
       * */

        SensorManager sensorManager;
        sensorManager = (SensorManager)  this.getSystemService(SENSOR_SERVICE);

        Sensor heartRateSensor;
        heartRateSensor = sensorManager.getDefaultSensor(Sensor.TYPE_HEART_RATE);

        sensorManager.registerListener(this, heartRateSensor, SensorManager.SENSOR_DELAY_NORMAL);
        Log.d(LOG_TAG, "Listener registered");

    }

    @Override
    public void onSensorChanged(SensorEvent event) {
        //Log.d(LOG_TAG, event.sensor.getType() + "");
        if (event.sensor.getType() == Sensor.TYPE_HEART_RATE) {
            String msg = "" + (int)event.values[0];
            Log.d(LOG_TAG, msg);
        }
        else{
            Log.d(LOG_TAG, "Unknown sensor type");
        }
    }

    @Override
    public void onAccuracyChanged(Sensor sensor, int accuracy) {
        Log.d(LOG_TAG, "Accuracy changed to " + accuracy + "");
    }


    @Override
    public void onEnterAmbient(Bundle ambientDetails) {
        super.onEnterAmbient(ambientDetails);
        updateDisplay();
    }

    @Override
    public void onUpdateAmbient() {
        super.onUpdateAmbient();
        updateDisplay();
    }

    @Override
    public void onExitAmbient() {
        updateDisplay();
        super.onExitAmbient();
    }

    private void updateDisplay() {
        if (isAmbient()) {
           /* CODE VOOR WANNEER HET SCHERM IN STANDBY VALT */
        } else {

        }
    }

}

这是我的可穿戴清单:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="be.ehb.dt.finalwork_lievenluyckx_v001">

    <uses-feature android:name="android.hardware.type.watch" />

    <uses-permission android:name="android.permission.WAKE_LOCK" />

    <uses-permission android:name="android.permission.BODY_SENSORS"/>

    <application
        android:allowBackup="true"
        android:icon="@drawable/billie_coverdefault"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@android:style/Theme.DeviceDefault">
        <uses-library
            android:name="com.google.android.wearable"
            android:required="false" />

        <activity
            android:name=".Monitor"
            android:label="@string/app_name"
            android:theme="@android:style/Theme.DeviceDefault.Light">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

这是我第一次为可穿戴设备创建应用程序,感觉很难获得任何有用的文档。

build.grade(磨损)

apply plugin: 'com.android.application'

android {
    allprojects {
        repositories {
            jcenter()
            maven {
                url "https://maven.google.com"
            }
        }
    }

    compileSdkVersion 25
    buildToolsVersion "25.0.1"
    defaultConfig {
        applicationId "be.ehb.dt.finalwork_lievenluyckx_v001"
        minSdkVersion 25
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile 'com.android.support:wear:26.0.0'
    compile 'com.google.android.support:wearable:2.0.3'
    provided 'com.google.android.wearable:wearable:2.0.3'
}

build.gradle(手机)

apply plugin: 'com.android.application'


android {
    compileSdkVersion 25
    buildToolsVersion "25.0.0"
    defaultConfig {
        applicationId "be.ehb.dt.finalwork_lievenluyckx_v001"
        minSdkVersion 23
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

        jackOptions {
            enabled true
        }
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }

    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.1', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    wearApp project(':wear')
    compile 'com.google.android.gms:play-services:8.1.0'
    compile 'com.android.support:appcompat-v7:24.1.1'
    compile 'com.mpatric:mp3agic:0.9.0'
    testCompile 'junit:junit:4.12'


}

来自Android guide for permissions

If the device is running Android 6.0 (API level 23) or higher, and the app's targetSdkVersion is 23 or higher, the app requests permissions from the user at run-time.

您的目标 API 是 25,body 个传感器被视为 "dangerous permissions,",因此您必须在 run-time 请求权限。查看 this 以获取有关在 run-time.

请求权限的指南