quickfixes for lindenberg

disable heart rate sensor, because you have to ask for permissions sequentially! so we have to create a class for all these requests
now we only ask for location permission
fixed ble stuff
added some todos
This commit is contained in:
toni
2019-10-10 19:16:58 +02:00
parent 76bd80382e
commit 5e5aaff9d4
10 changed files with 176 additions and 39 deletions

Binary file not shown.

116
.idea/codeStyles/Project.xml generated Normal file
View File

@@ -0,0 +1,116 @@
<component name="ProjectCodeStyleConfiguration">
<code_scheme name="Project" version="173">
<codeStyleSettings language="XML">
<indentOptions>
<option name="CONTINUATION_INDENT_SIZE" value="4" />
</indentOptions>
<arrangement>
<rules>
<section>
<rule>
<match>
<AND>
<NAME>xmlns:android</NAME>
<XML_ATTRIBUTE />
<XML_NAMESPACE>^$</XML_NAMESPACE>
</AND>
</match>
</rule>
</section>
<section>
<rule>
<match>
<AND>
<NAME>xmlns:.*</NAME>
<XML_ATTRIBUTE />
<XML_NAMESPACE>^$</XML_NAMESPACE>
</AND>
</match>
<order>BY_NAME</order>
</rule>
</section>
<section>
<rule>
<match>
<AND>
<NAME>.*:id</NAME>
<XML_ATTRIBUTE />
<XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE>
</AND>
</match>
</rule>
</section>
<section>
<rule>
<match>
<AND>
<NAME>.*:name</NAME>
<XML_ATTRIBUTE />
<XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE>
</AND>
</match>
</rule>
</section>
<section>
<rule>
<match>
<AND>
<NAME>name</NAME>
<XML_ATTRIBUTE />
<XML_NAMESPACE>^$</XML_NAMESPACE>
</AND>
</match>
</rule>
</section>
<section>
<rule>
<match>
<AND>
<NAME>style</NAME>
<XML_ATTRIBUTE />
<XML_NAMESPACE>^$</XML_NAMESPACE>
</AND>
</match>
</rule>
</section>
<section>
<rule>
<match>
<AND>
<NAME>.*</NAME>
<XML_ATTRIBUTE />
<XML_NAMESPACE>^$</XML_NAMESPACE>
</AND>
</match>
<order>BY_NAME</order>
</rule>
</section>
<section>
<rule>
<match>
<AND>
<NAME>.*</NAME>
<XML_ATTRIBUTE />
<XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE>
</AND>
</match>
<order>ANDROID_ATTRIBUTE_ORDER</order>
</rule>
</section>
<section>
<rule>
<match>
<AND>
<NAME>.*</NAME>
<XML_ATTRIBUTE />
<XML_NAMESPACE>.*</XML_NAMESPACE>
</AND>
</match>
<order>BY_NAME</order>
</rule>
</section>
</rules>
</arrangement>
</codeStyleSettings>
</code_scheme>
</component>

4
.idea/gradle.xml generated
View File

@@ -3,6 +3,9 @@
<component name="GradleSettings">
<option name="linkedExternalProjectsSettings">
<GradleProjectSettings>
<compositeConfiguration>
<compositeBuild compositeDefinitionSource="SCRIPT" />
</compositeConfiguration>
<option name="distributionType" value="DEFAULT_WRAPPED" />
<option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="modules">
@@ -12,6 +15,7 @@
</set>
</option>
<option name="resolveModulePerSourceSet" value="false" />
<option name="testRunner" value="PLATFORM" />
</GradleProjectSettings>
</option>
</component>

2
.idea/misc.xml generated
View File

@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" />
</component>
<component name="ProjectType">

4
.idea/modules.xml generated
View File

@@ -2,8 +2,8 @@
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/app/app.iml" filepath="$PROJECT_DIR$/app/app.iml" />
<module fileurl="file://$PROJECT_DIR$/sensorreadout.iml" filepath="$PROJECT_DIR$/sensorreadout.iml" />
<module fileurl="file:///mnt/Daten/Dokumente/programme/localization/SensorReadout/SensorReadout.iml" filepath="/mnt/Daten/Dokumente/programme/localization/SensorReadout/SensorReadout.iml" />
<module fileurl="file:///mnt/Daten/Dokumente/programme/localization/SensorReadout/app/app.iml" filepath="/mnt/Daten/Dokumente/programme/localization/SensorReadout/app/app.iml" />
</modules>
</component>
</project>

View File

@@ -6,8 +6,8 @@ android {
defaultConfig {
applicationId "de.fhws.indoor.sensorreadout"
minSdkVersion 19
targetSdkVersion 23
minSdkVersion 23
targetSdkVersion 29
versionCode 1
versionName "1.0"
multiDexEnabled true
@@ -21,11 +21,11 @@ android {
}
dependencies {
implementation 'com.android.support:design:23.4.0'
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
implementation 'com.android.support:appcompat-v7:23.4.0'
implementation 'com.google.android.gms:play-services:10.2.0'
implementation 'com.android.support:design:28.0.0'
implementation fileTree(include: ['*.jar'], dir: 'libs')
testImplementation 'junit:junit:4.12'
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.google.android.gms:play-services:12.0.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'org.apmem.tools:layouts:1.10@aar'
//compile 'com.google.android.support:wearable:1.3.0'

View File

@@ -10,10 +10,9 @@
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.BODY_SENSORS" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> <!-- Needed only if your app targets Android 5.0 (API level 21) or higher. -->
<uses-feature android:name="android.hardware.location.gps" />
<uses-feature android:name="android.hardware.bluetooth_le" android:required="false"/>
<uses-permission-sdk-23 android:name="android.permission.ACCESS_FINE_LOCATION" />
<application
android:allowBackup="true"

View File

@@ -424,13 +424,13 @@ public class MainActivity extends Activity {
if(activeSensors.contains("PHONE")) {
// heartbeat permission
if(ActivityCompat.shouldShowRequestPermissionRationale(this,
Manifest.permission.BODY_SENSORS)) {
} else {
ActivityCompat.requestPermissions(this,
new String[]{Manifest.permission.BODY_SENSORS},
MY_PERMISSIONS_REQUEST_READ_HEART);
}
// if(ActivityCompat.shouldShowRequestPermissionRationale(this,
// Manifest.permission.BODY_SENSORS)) {
// } else {
// ActivityCompat.requestPermissions(this,
// new String[]{Manifest.permission.BODY_SENSORS},
// MY_PERMISSIONS_REQUEST_READ_HEART);
// }
//all Phone-Sensors (Accel, Gyro, Magnet, ...)
final PhoneSensors phoneSensors = new PhoneSensors(this);
@@ -468,6 +468,8 @@ public class MainActivity extends Activity {
MY_PERMISSIONS_REQUEST_READ_BT);
}
//TODO: add something that asks the user to also enable GPS!
// log iBeacons using sensor number 9
final mySensor beacon;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {

View File

@@ -24,7 +24,7 @@ import java.io.IOException;
*/
public class PhoneSensors extends mySensor implements SensorEventListener{
private static final int SENSOR_TYPE_HEARTRATE = 65562;
//private static final int SENSOR_TYPE_HEARTRATE = 65562;
private SensorManager sensorManager;
private Sensor acc;
@@ -34,7 +34,7 @@ public class PhoneSensors extends mySensor implements SensorEventListener{
private Sensor magnet;
private Sensor press;
private Sensor ori;
private Sensor heart;
//private Sensor heart;
private Sensor humidity;
private Sensor rotationVector;
private Sensor light;
@@ -61,7 +61,7 @@ public class PhoneSensors extends mySensor implements SensorEventListener{
magnet = sensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD);
press = sensorManager.getDefaultSensor(Sensor.TYPE_PRESSURE);
ori = sensorManager.getDefaultSensor(Sensor.TYPE_ORIENTATION);
heart = sensorManager.getDefaultSensor(Sensor.TYPE_HEART_RATE);
//heart = sensorManager.getDefaultSensor(Sensor.TYPE_HEART_RATE);
humidity = sensorManager.getDefaultSensor(Sensor.TYPE_RELATIVE_HUMIDITY);
rotationVector = sensorManager.getDefaultSensor(Sensor.TYPE_ROTATION_VECTOR);
light = sensorManager.getDefaultSensor(Sensor.TYPE_LIGHT);
@@ -103,7 +103,7 @@ public class PhoneSensors extends mySensor implements SensorEventListener{
dumpSensor(sb, SensorType.ORIENTATION_OLD, ori);
dumpSensor(sb, SensorType.LIGHT, light);
dumpSensor(sb, SensorType.AMBIENT_TEMPERATURE, temperature);
dumpSensor(sb, SensorType.HEART_RATE, heart);
//dumpSensor(sb, SensorType.HEART_RATE, heart);
dumpSensor(sb, SensorType.GAME_ROTATION_VECTOR, gameRotationVector);
// write
@@ -156,16 +156,16 @@ public class PhoneSensors extends mySensor implements SensorEventListener{
}
if(event.sensor.getType() == Sensor.TYPE_HEART_RATE) {
// inform listeners
if (listener != null){
listener.onData(SensorType.HEART_RATE, event.timestamp,
Float.toString(event.values[0])
);
}
}
// if(event.sensor.getType() == Sensor.TYPE_HEART_RATE) {
//
// // inform listeners
// if (listener != null){
// listener.onData(SensorType.HEART_RATE, event.timestamp,
// Float.toString(event.values[0])
// );
// }
//
// }
else if(event.sensor.getType() == Sensor.TYPE_LIGHT) {
@@ -410,7 +410,7 @@ public class PhoneSensors extends mySensor implements SensorEventListener{
registerIfPresent(magnet, SensorManager.SENSOR_DELAY_FASTEST);
registerIfPresent(press, SensorManager.SENSOR_DELAY_FASTEST);
registerIfPresent(ori, SensorManager.SENSOR_DELAY_FASTEST);
registerIfPresent(heart, SensorManager.SENSOR_DELAY_FASTEST);
//registerIfPresent(heart, SensorManager.SENSOR_DELAY_FASTEST);
registerIfPresent(humidity, SensorManager.SENSOR_DELAY_FASTEST);
registerIfPresent(rotationVector, SensorManager.SENSOR_DELAY_FASTEST);
registerIfPresent(light, SensorManager.SENSOR_DELAY_FASTEST);

View File

@@ -5,18 +5,24 @@ import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothManager;
import android.bluetooth.le.BluetoothLeScanner;
import android.bluetooth.le.ScanCallback;
import android.bluetooth.le.ScanFilter;
import android.bluetooth.le.ScanSettings;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.widget.Toast;
import java.util.ArrayList;
import java.util.List;
/**
* Created by Frank on 25.03.2015.
*/
public class iBeacon extends mySensor {
private BluetoothAdapter bt = null;
private BluetoothLeScanner scanner = null;
private BluetoothAdapter bt;
private BluetoothLeScanner scanner;
private static ScanSettings settings;
private static final int REQUEST_ENABLE_BT = 1;
private ScanCallback mLeScanCallback;
@@ -35,7 +41,9 @@ public class iBeacon extends mySensor {
bt = mgr.getAdapter();
// bluetooth supported?
if (bt == null) {
if (bt == null || !bt.isEnabled()) {
//TODO: add something that asks the user to enable BLE. this need also be called in onResum()
Toast.makeText(act, "Bluetooth not supported!", Toast.LENGTH_SHORT).show();
return;
}
@@ -53,9 +61,15 @@ public class iBeacon extends mySensor {
}
};
settings = new ScanSettings.Builder()
.setReportDelay(0)
.setScanMode(ScanSettings.SCAN_MODE_LOW_LATENCY)
.setNumOfMatches(ScanSettings.MATCH_NUM_MAX_ADVERTISEMENT)
.build();
}
private final void enableBT(final Activity act) {
private void enableBT(final Activity act) {
if (bt == null) {throw new RuntimeException("BT not supported!");}
if (!bt.isEnabled()) {
Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
@@ -66,7 +80,9 @@ public class iBeacon extends mySensor {
@Override public void onResume(final Activity act) {
if (bt != null) {
enableBT(act);
scanner.startScan(mLeScanCallback);
List<ScanFilter> filters = new ArrayList<ScanFilter>();
scanner.startScan(filters, settings, mLeScanCallback);
//scanner.startScan(mLeScanCallback);
}
}