- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我目前正在开发一个 Android 应用程序,它可以从 Microsoft Band 接收心率数据。这里我的 Activity 从项目示例 Accelerometer 修改而来:
package com.microsoft.band.sdk.sampleapp;
import com.microsoft.band.BandClient;
import com.microsoft.band.BandClientManager;
import com.microsoft.band.BandException;
import com.microsoft.band.BandInfo;
import com.microsoft.band.BandIOException;
import com.microsoft.band.ConnectionState;
import com.microsoft.band.UserConsent;
import com.microsoft.band.sdk.sampleapp.streaming.R;
import com.microsoft.band.sensors.SampleRate;
import com.microsoft.band.sensors.BandHeartRateEvent;
import com.microsoft.band.sensors.BandHeartRateEventListener;
import com.microsoft.band.sensors.HeartRateConsentListener;
import android.os.Bundle;
import android.view.View;
import android.app.Activity;
import android.os.AsyncTask;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
public class BandStreamingAppActivity extends Activity {
private BandClient client = null;
private Button btnStart;
private TextView txtStatus;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
txtStatus = (TextView) findViewById(R.id.txtStatus);
btnStart = (Button) findViewById(R.id.btnStart);
btnStart.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
txtStatus.setText("");
new appTask().execute();
}
});
}
@Override
protected void onResume() {
super.onResume();
txtStatus.setText("");
}
@Override
protected void onPause() {
super.onPause();
if (client != null) {
try {
client.getSensorManager().unregisterAccelerometerEventListeners();
} catch (BandIOException e) {
appendToUI(e.getMessage());
}
}
}
private class appTask extends AsyncTask<Void, Void, Void> {
@Override
protected Void doInBackground(Void... params) {
try {
if (getConnectedBandClient()) {
appendToUI("Band is connected.\n");
// client.getSensorManager().registerAccelerometerEventListener(mAccelerometerEventListener, SampleRate.MS128);
client.getSensorManager().registerHeartRateEventListener(heartRateListener);
} else {
appendToUI("Band isn't connected. Please make sure bluetooth is on and the band is in range.\n");
}
} catch (BandException e) {
String exceptionMessage="";
switch (e.getErrorType()) {
case UNSUPPORTED_SDK_VERSION_ERROR:
exceptionMessage = "Microsoft Health BandService doesn't support your SDK Version. Please update to latest SDK.";
break;
case SERVICE_ERROR:
exceptionMessage = "Microsoft Health BandService is not available. Please make sure Microsoft Health is installed and that you have the correct permissions.";
break;
default:
exceptionMessage = "Unknown error occured: " + e.getMessage();
break;
}
appendToUI(exceptionMessage);
} catch (Exception e) {
appendToUI(e.getMessage());
}
return null;
}
}
private void appendToUI(final String string) {
this.runOnUiThread(new Runnable() {
@Override
public void run() {
txtStatus.setText(string);
}
});
}
private BandHeartRateEventListener heartRateListener = new BandHeartRateEventListener() {
@Override
public void onBandHeartRateChanged(final BandHeartRateEvent event) {
if (event != null) {
appendToUI(String.format(" HR = %i", event.getHeartRate()));
}
}
};
private boolean getConnectedBandClient() throws InterruptedException, BandException {
if (client == null) {
BandInfo[] devices = BandClientManager.getInstance().getPairedBands();
if (devices.length == 0) {
appendToUI("Band isn't paired with your phone.\n");
return false;
}
client = BandClientManager.getInstance().create(getBaseContext(), devices[0]);
} else if (ConnectionState.CONNECTED == client.getConnectionState()) {
return true;
}
appendToUI("Band is connecting...\n");
return ConnectionState.CONNECTED == client.connect().await();
}
}
但是,我在应用程序运行时遇到此错误:
Unknown Error occured : User has not given consent for use of heart rate data
然后我查看文档,它说:
实现HeartRateConsentListener接口(interface)
@Override
public void userAccepted(boolean consentGiven) {
// handle user's heart rate consent decision
};
确保用户同意心率传感器流式传输
// check current user heart rate consent
if(client.getSensorManager().getCurrentHeartRateConsent() !=
UserConsent.GRANTED) {
// user has not consented, request it
// the calling class is both an Activity and implements
// HeartRateConsentListener
bandClient.getSensorManager().requestHeartRateConsent(this, this);
}
问题是我不知道如何在我的代码中实现文档所说的内容。
最佳答案
在他明确同意之前,您不会获得用户的 HR 数据(他只需要同意一次)。
因此,不是使用这行代码:client.getSensorManager().registerHeartRateEventListener(heartRateListener);
您必须检查 UserConsent.GRANTED == true
是否为在文档的第三点中说。如果为 true
,您可以像之前一样注册 HR 传感器事件监听器,但如果为 false
,则必须调用 requestHeartRateConsent
。
if(client.getSensorManager().getCurrentHeartRateConsent() == UserConsent.GRANTED) {
startHRListener();
} else {
// user has not consented yet, request it
client.getSensorManager().requestHeartRateConsent(BandStreamingAppActivity.this, mHeartRateConsentListener);
}
屏幕上会出现一个紫色对话框。用户可以选择是/否。他的选择将是 b
的值,并且还将保存在 UserConsent.GRANTED
中。如果 b == true
,现在您可以注册 HR 传感器事件监听器,如果它是 false
,请执行您想要的任何操作以通知用户不会获取 HR工作。如文档的第二点所述,所有这些都在 HeartRateConsentListener 接口(interface)中处理。您需要的代码是:
private HeartRateConsentListener mHeartRateConsentListener = new HeartRateConsentListener() {
@Override
public void userAccepted(boolean b) {
// handle user's heart rate consent decision
if (b == true) {
// Consent has been given, start HR sensor event listener
startHRListener();
} else {
// Consent hasn't been given
appendToUI(String.valueOf(b));
}
}
};
public void startHRListener() {
try {
// register HR sensor event listener
client.getSensorManager().registerHeartRateEventListener(mHeartRateEventListener);
} catch (BandIOException ex) {
appendToUI(ex.getMessage(), band);
} catch (BandException e) {
String exceptionMessage="";
switch (e.getErrorType()) {
case UNSUPPORTED_SDK_VERSION_ERROR:
exceptionMessage = "Microsoft Health BandService doesn't support your SDK Version. Please update to latest SDK.";
break;
case SERVICE_ERROR:
exceptionMessage = "Microsoft Health BandService is not available. Please make sure Microsoft Health is installed and that you have the correct permissions.";
break;
default:
exceptionMessage = "Unknown error occurred: " + e.getMessage();
break;
}
appendToUI(exceptionMessage, band);
} catch (Exception e) {
appendToUI(e.getMessage(), band);
}
}
关于安卓 : Streaming Heart Rate from Microsoft Band,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30090668/
我正在尝试通过重新创建类似 instagram 的类似应用程序来学习抖动。 我正在集思广益,尝试在喜欢每个帖子的同时思考帖子平滑滚动背后的逻辑。 在我的代码中,每当我尝试喜欢某个帖子时,它就会冻结一秒
所以我很喜欢 CSS。但是现在我想修改它并添加内部动态图像。这是我所拥有的: .heart { position: relative; width: 100px; height: 90px
我有以下代码 .heart { float: left; margin-top: 10px; width: 10px; height: 10px; -webkit-transfor
我已经挖掘出一些 CSS 代码,可以从拼图之类的东西中组装和分解一颗心。但是,我无法将其作为图标与我的 HTML 段落一起显示。 CSS 非常复杂,因为它使用了很多其他定位,但我可以通过快速破解获得它
我使用脚本开始发布: #!/bin/bash ERL_FLAGS=" -args_file config/vm.args -config config/sys.config" rebar3 shell
标题已经概括了一切。我有一个使用 -heart 运行的 zotonic 站点,它使用大量的 cpu 时间,而且我无法获得 erlang shell。那么,有没有办法杀死虚拟机呢? killall he
我使用纯 CSS 完成了简单的心脏。它由两 block 组成,所以一 block 有白色 box-shadow,另一 block 有红色。 可在此处找到示例:JsFiddle (它有一个没有渐变的简化
(function( $ ) { $.fn.htmlCodes = function(){ var $this = this; var body = this.
我目前正在开发一个 Android 应用程序,它可以从 Microsoft Band 接收心率数据。这里我的 Activity 从项目示例 Accelerometer 修改而来: packag
我在 android widget 中使用 ❤ 符号,但在某些 Android 2.x 设备和 Android 2.x 模拟器上,我得到一个像这样的方形符号 □ 而不是 ❤ 您会向我推荐什么?我正在考
我在互联网上的一些博客上偶然发现了这段代码。这是一个非常有趣的程序,但我一段时间以来一直试图弄清楚该程序实际上是如何工作的,从那时起我就一直坚持下去。我只是不明白程序如何打印对称性。心脏的一半是打印出
我正在尝试创建一个类似于 twitter 之心的按钮,但我似乎无法让 JS/CSS 正常工作(或者我做错了)。每当一个帖子被喜欢时,我想要 this播放动画,仅供引用:我已经解决了导致所有动画同时播放
我今天看到一个页面,其中有一些细节,我发现它非常整洁。 http://www.songkick.com/feedback 如果你看一下右上角,你会看到: 我试图检查元素,这是如何完成的,但我只得到这段
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 这个问题似乎不是关于 a specific programming problem, a softwar
我有下面的代码: heart.html("   "+count); 我想要 heart.html() 之外的 count 元素。像这样: heart.html(" &
我正在开发一款健身应用,目前我不想通过 HealthKit 获取任何数据。实际上,通过 HKWorkoutSession 将我的应用程序保持在后台是唯一迫使我现在使用 HealtKit 的东西。 我遇
下面的代码创建了一个没有填充的心,它必须由用户点击填充,但这段代码对我不起作用: .fa { font-size: 50px; cursor: pointer; user-sel
This commit to gpxpy library包括对 Garmin 1.1 扩展的额外解析。然而,自这次提交以来,代码似乎发生了很大变化,而且现在似乎可以自动解析扩展。 但是我一直无法弄清楚
我有一个 pig 脚本,它将从 cassandra 获取所有数据,进行少量转换并存储到 hdfs 上。在pig的grunt控制台执行时,cassandra数据量大,耗时将近30分钟。 但是当我使用 o
根据我的理解,下面的 HTML 标记应该显示心形符号,但事实并非如此。我缺少什么?我在这里得到了关于 Unicode 字符的数据: http://en.wikipedia.org/wiki/Html_
我是一名优秀的程序员,十分优秀!