2017-08-08 86 views
0

我想要显示佩戴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' 


} 
+0

您的最低和目标API级别是多少? –

+0

将它们编辑为帖子! –

+0

你确定佩戴该设备的人还活着吗? – Ikari

回答

0

Android guide for permissions

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

您的目标API为25,身体传感器被认为是“危险的权限”,因此您必须在运行时请求权限。请参阅this以获取运行时请求权限的指导。

+0

哦,我必须读过“运行时间”部分。我现在检查它! –

+0

他们不_not_使它很明显,我有一个类似的问题,不久之前,让我知道它是否有效! –

+0

它的工作原理!非常感谢! –