Added broadcastreceiver to receive data from external data sources
This commit is contained in:
@@ -23,10 +23,12 @@
|
|||||||
*/
|
*/
|
||||||
package uk.org.openseizuredetector;
|
package uk.org.openseizuredetector;
|
||||||
|
|
||||||
|
import android.content.BroadcastReceiver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.IntentFilter;
|
import android.content.IntentFilter;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
|
import android.net.ConnectivityManager;
|
||||||
import android.os.BatteryManager;
|
import android.os.BatteryManager;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
@@ -66,6 +68,7 @@ public class SdDataSourceNetworkPassive extends SdDataSource {
|
|||||||
// data after mDataUpdatePeriod
|
// data after mDataUpdatePeriod
|
||||||
private int mFaultTimerPeriod = 30; // Fault Timer Period in sec
|
private int mFaultTimerPeriod = 30; // Fault Timer Period in sec
|
||||||
private int mSettingsPeriod = 60; // period between requesting settings in seconds.
|
private int mSettingsPeriod = 60; // period between requesting settings in seconds.
|
||||||
|
private SdDataBroadcastReceiver mSdDataBroadcastReceiver;
|
||||||
|
|
||||||
|
|
||||||
private String TAG = "SdDataSourceNetPassive";
|
private String TAG = "SdDataSourceNetPassive";
|
||||||
@@ -170,6 +173,11 @@ public class SdDataSourceNetworkPassive extends SdDataSource {
|
|||||||
mUtil.writeToSysLogFile("SdDataSourceNetworkPassive.start() - settings timer already running??");
|
mUtil.writeToSysLogFile("SdDataSourceNetworkPassive.start() - settings timer already running??");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mSdDataBroadcastReceiver = new SdDataBroadcastReceiver();
|
||||||
|
//uk.org.openseizuredetector.SdDataReceived
|
||||||
|
IntentFilter filter = new IntentFilter("uk.org.openseizuredetector.SdDataReceived");
|
||||||
|
mContext.registerReceiver(mSdDataBroadcastReceiver, filter);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -191,6 +199,7 @@ public class SdDataSourceNetworkPassive extends SdDataSource {
|
|||||||
Log.v(TAG, "Error in stop() - " + e.toString());
|
Log.v(TAG, "Error in stop() - " + e.toString());
|
||||||
mUtil.writeToSysLogFile("SdDataSourceNetworkPassive.stop() - error - "+e.toString());
|
mUtil.writeToSysLogFile("SdDataSourceNetworkPassive.stop() - error - "+e.toString());
|
||||||
}
|
}
|
||||||
|
mContext.unregisterReceiver(mSdDataBroadcastReceiver);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -316,7 +325,8 @@ public class SdDataSourceNetworkPassive extends SdDataSource {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
JSONObject mainObject = new JSONObject(jsonStr);
|
JSONObject mainObject = new JSONObject(jsonStr);
|
||||||
JSONObject dataObject = mainObject.getJSONObject("dataObj");
|
//JSONObject dataObject = mainObject.getJSONObject("dataObj");
|
||||||
|
JSONObject dataObject = mainObject;
|
||||||
String dataTypeStr = dataObject.getString("dataType");
|
String dataTypeStr = dataObject.getString("dataType");
|
||||||
Log.v(TAG,"updateFromJSON - dataType="+dataTypeStr);
|
Log.v(TAG,"updateFromJSON - dataType="+dataTypeStr);
|
||||||
if (dataTypeStr.equals("raw")) {
|
if (dataTypeStr.equals("raw")) {
|
||||||
@@ -339,9 +349,12 @@ public class SdDataSourceNetworkPassive extends SdDataSource {
|
|||||||
mSdData.haveSettings = true;
|
mSdData.haveSettings = true;
|
||||||
mSdData.mSampleFreq = mSampleFreq;
|
mSdData.mSampleFreq = mSampleFreq;
|
||||||
mWatchAppRunningCheck = true;
|
mWatchAppRunningCheck = true;
|
||||||
|
} else {
|
||||||
|
Log.v(TAG,"updateFromJSON - unrecognised dataType "+dataTypeStr);
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Log.v(TAG,"Error Parsing JSON String - "+e.toString());
|
Log.v(TAG,"updateFromJSON - Error Parsing JSON String - "+e.toString());
|
||||||
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -551,6 +564,18 @@ public class SdDataSourceNetworkPassive extends SdDataSource {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class SdDataBroadcastReceiver extends BroadcastReceiver {
|
||||||
|
//private String TAG = "SdDataBroadcastReceiver";
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onReceive(Context context, Intent intent) {
|
||||||
|
Log.v(TAG,"SdDataBroadcastReceiver.onReceive()");
|
||||||
|
String jsonStr = intent.getStringExtra("data");
|
||||||
|
Log.v(TAG,"SdDataBroadcastReceiver.onReceive() - data="+jsonStr);
|
||||||
|
updateFromJSON(jsonStr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -37,6 +37,7 @@ import android.app.Notification;
|
|||||||
import android.app.NotificationManager;
|
import android.app.NotificationManager;
|
||||||
import android.app.PendingIntent;
|
import android.app.PendingIntent;
|
||||||
import android.app.Service;
|
import android.app.Service;
|
||||||
|
import android.content.BroadcastReceiver;
|
||||||
import android.content.ComponentName;
|
import android.content.ComponentName;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
@@ -1073,5 +1074,4 @@ public class SdServer extends Service implements SdDataReceiver, SdLocationRecei
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user