added suport for smartwatches + wifi hack
This commit is contained in:
8
.idea/gradle.xml
generated
8
.idea/gradle.xml
generated
@@ -5,13 +5,19 @@
|
|||||||
<GradleProjectSettings>
|
<GradleProjectSettings>
|
||||||
<option name="distributionType" value="LOCAL" />
|
<option name="distributionType" value="LOCAL" />
|
||||||
<option name="externalProjectPath" value="$PROJECT_DIR$" />
|
<option name="externalProjectPath" value="$PROJECT_DIR$" />
|
||||||
<option name="gradleHome" value="D:\programme\android-studio\gradle\gradle-2.10" />
|
<option name="gradleHome" value="$APPLICATION_HOME_DIR$/gradle/gradle-2.10" />
|
||||||
<option name="modules">
|
<option name="modules">
|
||||||
<set>
|
<set>
|
||||||
<option value="$PROJECT_DIR$" />
|
<option value="$PROJECT_DIR$" />
|
||||||
<option value="$PROJECT_DIR$/app" />
|
<option value="$PROJECT_DIR$/app" />
|
||||||
</set>
|
</set>
|
||||||
</option>
|
</option>
|
||||||
|
<option name="myModules">
|
||||||
|
<set>
|
||||||
|
<option value="$PROJECT_DIR$" />
|
||||||
|
<option value="$PROJECT_DIR$/app" />
|
||||||
|
</set>
|
||||||
|
</option>
|
||||||
</GradleProjectSettings>
|
</GradleProjectSettings>
|
||||||
</option>
|
</option>
|
||||||
</component>
|
</component>
|
||||||
|
|||||||
2
.idea/misc.xml
generated
2
.idea/misc.xml
generated
@@ -37,7 +37,7 @@
|
|||||||
<ConfirmationsSetting value="0" id="Add" />
|
<ConfirmationsSetting value="0" id="Add" />
|
||||||
<ConfirmationsSetting value="0" id="Remove" />
|
<ConfirmationsSetting value="0" id="Remove" />
|
||||||
</component>
|
</component>
|
||||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
|
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
|
||||||
<output url="file://$PROJECT_DIR$/build/classes" />
|
<output url="file://$PROJECT_DIR$/build/classes" />
|
||||||
</component>
|
</component>
|
||||||
<component name="ProjectType">
|
<component name="ProjectType">
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ apply plugin: 'com.android.application'
|
|||||||
|
|
||||||
android {
|
android {
|
||||||
compileSdkVersion 23
|
compileSdkVersion 23
|
||||||
buildToolsVersion '23.0.3'
|
buildToolsVersion '23.0.2'
|
||||||
|
|
||||||
defaultConfig {
|
defaultConfig {
|
||||||
applicationId "de.fhws.indoor.sensorreadout"
|
applicationId "de.fhws.indoor.sensorreadout"
|
||||||
|
|||||||
@@ -2,9 +2,9 @@
|
|||||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
package="de.fhws.indoor.sensorreadout">>
|
package="de.fhws.indoor.sensorreadout">>
|
||||||
|
|
||||||
<!--
|
|
||||||
<uses-feature android:name="android.hardware.type.watch" />
|
<uses-feature android:name="android.hardware.type.watch" />
|
||||||
-->
|
|
||||||
|
|
||||||
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
|
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
|
||||||
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
|
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package de.fhws.indoor.sensorreadout;
|
|||||||
|
|
||||||
import android.Manifest;
|
import android.Manifest;
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
|
import android.app.ActivityManager;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.res.Configuration;
|
import android.content.res.Configuration;
|
||||||
import android.graphics.Color;
|
import android.graphics.Color;
|
||||||
@@ -9,6 +10,9 @@ import android.media.MediaPlayer;
|
|||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.v4.app.ActivityCompat;
|
import android.support.v4.app.ActivityCompat;
|
||||||
|
import android.support.v4.content.pm.ActivityInfoCompat;
|
||||||
|
import android.support.wearable.activity.WearableActivity;
|
||||||
|
import android.util.Log;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.ArrayAdapter;
|
import android.widget.ArrayAdapter;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
@@ -31,7 +35,7 @@ import de.fhws.indoor.sensorreadout.sensors.mySensor;
|
|||||||
import de.fhws.indoor.sensorreadout.sensors.SensorType;
|
import de.fhws.indoor.sensorreadout.sensors.SensorType;
|
||||||
|
|
||||||
|
|
||||||
public class MainActivity extends Activity {
|
public class MainActivity extends WearableActivity {
|
||||||
|
|
||||||
private final ArrayList<mySensor> sensors = new ArrayList<mySensor>();
|
private final ArrayList<mySensor> sensors = new ArrayList<mySensor>();
|
||||||
private final Logger logger = new Logger(this);
|
private final Logger logger = new Logger(this);
|
||||||
@@ -195,6 +199,7 @@ public class MainActivity extends Activity {
|
|||||||
@Override public void onData(final SensorType id, final String csv) {return; }
|
@Override public void onData(final SensorType id, final String csv) {return; }
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
// bluetooth permission
|
// bluetooth permission
|
||||||
if(ActivityCompat.shouldShowRequestPermissionRationale(this,
|
if(ActivityCompat.shouldShowRequestPermissionRationale(this,
|
||||||
Manifest.permission.ACCESS_FINE_LOCATION)) {
|
Manifest.permission.ACCESS_FINE_LOCATION)) {
|
||||||
@@ -204,6 +209,7 @@ public class MainActivity extends Activity {
|
|||||||
MY_PERMISSIONS_REQUEST_READ_BT);
|
MY_PERMISSIONS_REQUEST_READ_BT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// heartbeat permission
|
// heartbeat permission
|
||||||
/* if(ActivityCompat.shouldShowRequestPermissionRationale(this,
|
/* if(ActivityCompat.shouldShowRequestPermissionRationale(this,
|
||||||
Manifest.permission.BODY_SENSORS)) {
|
Manifest.permission.BODY_SENSORS)) {
|
||||||
@@ -221,7 +227,8 @@ public class MainActivity extends Activity {
|
|||||||
loadCounterAny = 0;
|
loadCounterAny = 0;
|
||||||
logger.start();
|
logger.start();
|
||||||
final TextView txt = (TextView) findViewById(R.id.txtFile);
|
final TextView txt = (TextView) findViewById(R.id.txtFile);
|
||||||
txt.setText(logger.getFile().getAbsolutePath());
|
String path = logger.getFile().getAbsolutePath();
|
||||||
|
txt.setText(path.substring(path.length()-17, path.length()));
|
||||||
for (final mySensor s : sensors) {s.onResume(this);}
|
for (final mySensor s : sensors) {s.onResume(this);}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -272,6 +279,23 @@ public class MainActivity extends Activity {
|
|||||||
/** resume activity */
|
/** resume activity */
|
||||||
protected void onResume() {
|
protected void onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
|
|
||||||
|
|
||||||
|
//print memory info
|
||||||
|
ActivityManager.MemoryInfo mi = new ActivityManager.MemoryInfo();
|
||||||
|
ActivityManager activityManager = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
|
||||||
|
activityManager.getMemoryInfo(mi);
|
||||||
|
long availableMegs = mi.availMem / 1048576L;
|
||||||
|
|
||||||
|
Runtime info = Runtime.getRuntime();
|
||||||
|
long freeSize = info.freeMemory();
|
||||||
|
long totalSize = info.totalMemory();
|
||||||
|
long usedSize = totalSize - freeSize;
|
||||||
|
|
||||||
|
Log.d("MemoryInfo: ", String.valueOf(availableMegs));
|
||||||
|
Log.d("FreeSize: ", String.valueOf(freeSize));
|
||||||
|
Log.d("TotalSize: ", String.valueOf(totalSize));
|
||||||
|
Log.d("usedSize: ", String.valueOf(usedSize));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import android.content.Intent;
|
|||||||
import android.content.IntentFilter;
|
import android.content.IntentFilter;
|
||||||
import android.net.wifi.ScanResult;
|
import android.net.wifi.ScanResult;
|
||||||
import android.net.wifi.WifiManager;
|
import android.net.wifi.WifiManager;
|
||||||
|
import android.os.Debug;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -28,21 +29,35 @@ public class WiFi extends mySensor {
|
|||||||
this.wifi = (WifiManager) act.getSystemService(Context.WIFI_SERVICE);
|
this.wifi = (WifiManager) act.getSystemService(Context.WIFI_SERVICE);
|
||||||
isReceiverRegistered = true;
|
isReceiverRegistered = true;
|
||||||
|
|
||||||
this.receiver = new BroadcastReceiver() {
|
|
||||||
@Override public void onReceive(Context context, Intent intent) {
|
|
||||||
final StringBuilder sb = new StringBuilder(1024);
|
|
||||||
final List<ScanResult> res = wifi.getScanResults();
|
|
||||||
for(final ScanResult sr : res) {
|
|
||||||
sb.append(Helper.stripMAC(sr.BSSID)).append(';');
|
|
||||||
sb.append(sr.frequency).append(';');
|
|
||||||
sb.append(sr.level).append(';');
|
|
||||||
}
|
|
||||||
if (listener != null && isReceiverRegistered) {listener.onData(sb.toString());}
|
|
||||||
startScan();
|
|
||||||
//Log.d("wifi", sb.toString());
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
this.wifi.setWifiEnabled(false);
|
||||||
|
this.wifi.setWifiEnabled(true);
|
||||||
|
|
||||||
|
if (wifi == null) {
|
||||||
|
throw new MyException("WIFI not supported!");
|
||||||
|
}
|
||||||
|
if (wifi.isWifiEnabled()) {
|
||||||
|
this.receiver = new BroadcastReceiver() {
|
||||||
|
@Override
|
||||||
|
public void onReceive(Context context, Intent intent) {
|
||||||
|
final StringBuilder sb = new StringBuilder(1024);
|
||||||
|
final List<ScanResult> res = wifi.getScanResults();
|
||||||
|
for (final ScanResult sr : res) {
|
||||||
|
sb.append(Helper.stripMAC(sr.BSSID)).append(';');
|
||||||
|
sb.append(sr.frequency).append(';');
|
||||||
|
sb.append(sr.level).append(';');
|
||||||
|
}
|
||||||
|
if (listener != null && isReceiverRegistered) {
|
||||||
|
listener.onData(sb.toString());
|
||||||
|
}
|
||||||
|
startScan();
|
||||||
|
//Log.d("wifi", sb.toString());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
throw new MyException("WIFI not supported!");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -52,8 +67,10 @@ public class WiFi extends mySensor {
|
|||||||
try {
|
try {
|
||||||
//Method startScanActiveMethod = wifi.getClass().getMethod("startScanActive");
|
//Method startScanActiveMethod = wifi.getClass().getMethod("startScanActive");
|
||||||
//startScanActiveMethod.invoke(wifi);
|
//startScanActiveMethod.invoke(wifi);
|
||||||
wifi.startScan();
|
if(!wifi.startScan()){
|
||||||
Log.d("wifi", "start scan");
|
throw new MyException("Cant start WiFi!");
|
||||||
|
}
|
||||||
|
//Log.d("wifi", "start scan");
|
||||||
}catch (final Exception e) {
|
}catch (final Exception e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
@@ -64,7 +81,7 @@ public class WiFi extends mySensor {
|
|||||||
act.registerReceiver(this.receiver, new IntentFilter(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION));
|
act.registerReceiver(this.receiver, new IntentFilter(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION));
|
||||||
isReceiverRegistered = true;
|
isReceiverRegistered = true;
|
||||||
wifi.createWifiLock(wifi.WIFI_MODE_SCAN_ONLY, "ipin");
|
wifi.createWifiLock(wifi.WIFI_MODE_SCAN_ONLY, "ipin");
|
||||||
wifi.disconnect();
|
//wifi.disconnect();
|
||||||
startScan();
|
startScan();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -57,8 +57,10 @@ public class iBeacon extends mySensor {
|
|||||||
|
|
||||||
private final void enableBT(final Activity act) {
|
private final void enableBT(final Activity act) {
|
||||||
if (bt == null) {throw new RuntimeException("BT not supported!");}
|
if (bt == null) {throw new RuntimeException("BT not supported!");}
|
||||||
Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
|
if (!bt.isEnabled()) {
|
||||||
act.startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT);
|
Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
|
||||||
|
act.startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public void onResume(final Activity act) {
|
@Override public void onResume(final Activity act) {
|
||||||
|
|||||||
Reference in New Issue
Block a user