我想要顯示佩戴smartwatch(LG Urbane)的人的心率。然而,傳感器從不給出任何反饋。我在stackoverflow上嘗試了多種解決方案,但沒有一個有所作爲。我已經添加了在我的移動設備和我的可穿戴清單中使用身體感應器的權限請求,但是我從未收到要求所述權限的彈出窗口。卸載應用程序並重新安裝它也沒有幫助。心率監視器不給反饋
這是我的活動:
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(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'
}
您的最低和目標API級別是多少? –
將它們編輯爲帖子! –
你確定佩戴該設備的人還活着嗎? – Ikari