/*
* Copyright (C) 2013 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.samsung.ble.hrpcollector;
import java.io.UnsupportedEncodingException;
import java.math.BigInteger;
import java.util.ArrayList;
import com.samsung.ble.hrpcollector.R;
import android.app.Activity;
import android.app.AlertDialog;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.ServiceConnection;
import android.os.Bundle;
import android.os.Handler;
import android.os.IBinder;
import android.os.Message;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
import android.util.Log;
import android.content.res.Configuration;
public class HRPCollectorActivity extends Activity {
private static final int REQUEST_SELECT_DEVICE = 1;
private static final int REQUEST_ENABLE_BT = 2;
private static final int STATE_READY = 10;
public static final String TAG = "HRPCollector";
private static final int HRP_PROFILE_CONNECTED = 20;
private static final int HRP_PROFILE_DISCONNECTED = 21;
private static final int STATE_OFF = 10;
private Context mContext = null;
public int mState = HRP_PROFILE_DISCONNECTED;
private HRPService mService = null;
private BluetoothDevice mDevice = null;
private BluetoothAdapter mBtAdapter = null;
Button mbtnHrmNoti,mReadBsl,mResetEE,mdisableHrcp,mRead2a29,mRead2a2a
,mRead2a25,mSelectDevice,btn_conn;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mContext = getApplicationContext();
mBtAdapter = BluetoothAdapter.getDefaultAdapter();
if (mBtAdapter == null) {
Toast.makeText(this, "Bluetooth is not available", Toast.LENGTH_LONG).show();
finish();
return;
}
init();
mSelectDevice = (Button)findViewById(R.id.btn_select);
mbtnHrmNoti = (Button)findViewById(R.id.btn_write_HRM_Noty);
mReadBsl = (Button)findViewById(R.id.btn_BSL);
mResetEE= (Button)findViewById(R.id.btn_HRCP);
mdisableHrcp= (Button)findViewById(R.id.btn_Disable_HRCP);
mRead2a29= (Button)findViewById(R.id.btn_uuid_read_0x2A29);
mRead2a2a= (Button)findViewById(R.id.btn_uuid_read_0x2A2A);
mRead2a25= (Button)findViewById(R.id.btn_uuid_read_0x2A25);
btn_conn = (Button) findViewById(R.id.btn_connect_or_disconnect);
((Button) findViewById(R.id.btn_select)).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (!mBtAdapter.isEnabled()) {
Log.i(TAG, "onClick - BT not enabled yet");
Intent enableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
startActivityForResult(enableIntent, REQUEST_ENABLE_BT);
}
else {
Intent newIntent = new Intent(HRPCollectorActivity.this, DeviceListActivity.class);
startActivityForResult(newIntent, REQUEST_SELECT_DEVICE);
}
}
});
((Button) findViewById(R.id.btn_connect_or_disconnect)).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (mState == STATE_READY || (mState == HRP_PROFILE_CONNECTED)) {
mService.disableNotification(mDevice);//disable HR notifications, if enabled
mService.disconnect(mDevice);
} else if (mState == HRP_PROFILE_DISCONNECTED) {
mService.connect(mDevice, false);
}
}
});
((Button) findViewById(R.id.btn_write_HRM_Noty)).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mService.enableHRNotification(mDevice);
}
});
((Button) findViewById(R.id.btn_Disable_HRCP)).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mService.disableHRNotification(mDevice);
}
});
((Button) findViewById(R.id.btn_BSL)).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mService.getBodySensorLoc(mDevice);
}
});
((Button) findViewById(R.id.btn_uuid_read_0x2A25)).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mService.read_uuid_read_25(mDevice);
}
});
((Button) findViewById(R.id.btn_HRCP)).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mService.ResetEnergyExpended(mDevice);
}
});
((Button) findViewById(R.id.btn_remove_bond)).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mService.removeBond(mDevice);
}
});
((Button) findViewById(R.id.btn_uuid_read_0x2A29)).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mService.read_uuid_read_29(mDevice);
}
});
((Button) findViewById(R.id.btn_uuid_read_0x2A2A)).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mService.read_uuid_read_2A(mDevice);
}
});
}
private BroadcastReceiver deviceStateListener = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
final Intent mIntent = intent;
if (action.equals(BluetoothDevice.ACTION_BOND_STATE_CHANGED)) {
BluetoothDevice device = mIntent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
int devState = mIntent.getIntExtra(BluetoothDevice.EXTRA_BOND_STATE, -1);
Log.d(TAG, "BluetoothDevice.ACTION_BOND_STATE_CHANGED");
setUiState();
if (device.equals(mDevice) && devState == BluetoothDevice.BOND_NONE) {
runOnUiThread(new Runnable() {
public void run() {
mDevice = null;
setUiState();
}
});
}
}
if (action.equals(BluetoothAdapter.ACTION_STATE_CHANGED)) {
final int state = mIntent.getIntExtra(BluetoothAdapter.EXTRA_STATE,BluetoothAdapter.ERROR);
Log.d(TAG, "BluetoothAdapter.ACTION_STATE_CHANGED" + "state is" + state);
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
samsung android ble4.0 测心跳源码.rar (90个子文件)
BleHrpCollector
.project 851B
project.properties 563B
src
com
samsung
ble
hrpcollector
HRPCollectorActivity.java 27KB
HRPService.java 24KB
DeviceListActivity.java 11KB
lib
AndroidManifest.xml 2KB
res
drawable-ldpi
drawable-hdpi
drawable-mdpi
layout
device_list.xml 3KB
title_bar.xml 428B
device_element.xml 2KB
dis_values.xml 3KB
main.xml 8KB
drawable-xhdpi
values
strings.xml 4KB
styles.xml 1KB
.settings
org.eclipse.jdt.core.prefs 177B
assets
Android.mk 909B
gen
com
samsung
ble
hrpcollector
BuildConfig.java 170B
R.java 7KB
.classpath 430B
bin
resources.ap_ 11KB
classes
com
samsung
ble
hrpcollector
HRPCollectorActivity$3$4.class 4KB
R$layout.class 564B
R$style.class 461B
HRPCollectorActivity$3$2.class 1KB
BuildConfig.class 365B
HRPCollectorActivity$9.class 1KB
R$attr.class 370B
DeviceListActivity$DeviceAdapter.class 4KB
DeviceListActivity$4.class 2KB
HRPCollectorActivity$6.class 1KB
DeviceListActivity$5.class 885B
DeviceListActivity$2.class 3KB
HRPCollectorActivity.class 15KB
HRPCollectorActivity$13.class 1KB
HRPCollectorActivity$10.class 1KB
DeviceListActivity$3.class 2KB
HRPService.class 13KB
HRPCollectorActivity$1$1.class 1KB
HRPCollectorActivity$8.class 1KB
DeviceListActivity$1.class 2KB
HRPCollectorActivity$4.class 2KB
R$id.class 2KB
HRPCollectorActivity$5.class 1KB
HRPService$1.class 2KB
HRPService$LocalBinder.class 671B
HRPCollectorActivity$15.class 963B
R.class 595B
HRPCollectorActivity$11.class 1KB
R$string.class 3KB
HRPCollectorActivity$3.class 3KB
DeviceListActivity$1$1.class 1KB
HRPCollectorActivity$3$1.class 1KB
HRPCollectorActivity$12.class 1KB
HRPCollectorActivity$3$3.class 1KB
HRPCollectorActivity$1.class 3KB
HRPCollectorActivity$1$2.class 1KB
HRPCollectorActivity$7.class 1KB
HRPService$2.class 6KB
HRPCollectorActivity$2.class 2KB
DeviceListActivity.class 8KB
HRPCollectorActivity$14.class 747B
AndroidManifest.xml 2KB
dexedLibs
res
classes.dex 48KB
BleHrpCollector.apk 34KB
samsung_ble_sdk_200
com
samsung
android
sdk
bt
gatt
e.class 1KB
i.class 3KB
IBluetoothGattServerCallback.class 901B
f.class 5KB
IBluetoothGatt$Stub.class 6KB
BluetoothGattCharacteristic.class 5KB
BluetoothGattDescriptor.class 1KB
h.class 4KB
BluetoothGattAdapter.class 788B
MutableBluetoothGattCharacteristic.class 1KB
IBluetoothGattCallback.class 1KB
IBluetoothGatt.class 2KB
g.class 7KB
d.class 2KB
BluetoothGattServerCallback.class 1KB
BluetoothGattCallback.class 1KB
c.class 8KB
BluetoothGatt.class 13KB
MutableBluetoothGattService.class 1KB
b.class 1KB
BluetoothGattServer.class 10KB
IBluetoothGattCallback$Stub.class 4KB
BluetoothGattService.class 2KB
IBluetoothGattServerCallback$Stub.class 3KB
a.class 2KB
MutableBluetoothGattDescriptor.class 515B
META-INF
MANIFEST.MF 71B
共 90 条
- 1
980205
- 粉丝: 1w+
- 资源: 18
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
- 3
- 4
前往页