心率监测器不提供反馈

时间:2017-08-08 17:27:54

标签: android wear-os sensor android-sensors

我正试图显示佩戴智能手表的人的心率(LG Urbane)。然而,传感器从不提供任何反馈。我在stackoverflow上尝试了多个解决方案,但没有一个有所作为。我已经在我的手机和我的可穿戴Manifest中添加了使用身体传感器的许可请求,但我从未收到过要求获得许可的弹出窗口。卸载应用程序并重新安装它也无济于事。

这是我的活动:

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(WEAR)

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(MOBILE)

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'


}

1 个答案:

答案 0 :(得分:0)

来自Android guide for permissions

  

如果设备运行的是Android 6.0(API级别23)或更高版本,并且应用程序的targetSdkVersion为23或更高,则应用程序会在运行时请求用户的权限。

您的目标API为25,并且身体传感器被视为&#34;危险权限,&#34;所以你必须在运行时请求权限。请查看this以获取有关在运行时请求权限的指导。