Fixed problem with Android 8 permissions. Needed to implement a new unhandled Exception Handler because mine kept giving Permission Denied errors.
This commit is contained in:
@@ -61,6 +61,7 @@ import com.github.mikephil.charting.data.BarData;
|
||||
import com.github.mikephil.charting.data.BarDataSet;
|
||||
import com.github.mikephil.charting.data.BarEntry;
|
||||
import com.github.mikephil.charting.utils.ValueFormatter;
|
||||
import com.rohitss.uceh.UCEHandler;
|
||||
|
||||
public class MainActivity extends AppCompatActivity {
|
||||
static final String TAG = "MainActivity";
|
||||
@@ -89,7 +90,11 @@ public class MainActivity extends AppCompatActivity {
|
||||
Log.i(TAG,"onCreate()");
|
||||
|
||||
// Set our custom uncaught exception handler to report issues.
|
||||
Thread.setDefaultUncaughtExceptionHandler(new OsdUncaughtExceptionHandler(MainActivity.this));
|
||||
//Thread.setDefaultUncaughtExceptionHandler(new OsdUncaughtExceptionHandler(MainActivity.this));
|
||||
new UCEHandler.Builder(this)
|
||||
.addCommaSeparatedEmailAddresses("crashreports@openseizuredetector.org.uk,")
|
||||
.build();
|
||||
|
||||
//int i = 5/0; // Force exception to test handler.
|
||||
mUtil = new OsdUtil(this,serverStatusHandler);
|
||||
mConnection = new SdServiceConnection(this);
|
||||
|
||||
@@ -163,8 +163,8 @@ public class OsdUncaughtExceptionHandler implements Thread.UncaughtExceptionHand
|
||||
"You can review the information being sent in the next screen:"+
|
||||
"\n"+errorContent.toString());
|
||||
Dialog dialog = builder.create();
|
||||
dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
|
||||
//dialog.show();
|
||||
//dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
|
||||
dialog.show();
|
||||
Looper.loop();
|
||||
}
|
||||
}.start();
|
||||
|
||||
@@ -91,6 +91,9 @@ public class OsdUtil implements ActivityCompat.OnRequestPermissionsResultCallbac
|
||||
private final String[] REQUIRED_PERMISSIONS = {
|
||||
Manifest.permission.SEND_SMS,
|
||||
Manifest.permission.WRITE_EXTERNAL_STORAGE,
|
||||
//Manifest.permission.SYSTEM_ALERT_WINDOW,
|
||||
Manifest.permission.ACCESS_FINE_LOCATION,
|
||||
Manifest.permission.WAKE_LOCK,
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -342,24 +345,30 @@ public class OsdUtil implements ActivityCompat.OnRequestPermissionsResultCallbac
|
||||
|
||||
fname = fname + "_" + dateStr + ".txt";
|
||||
// Open output directory on SD Card.
|
||||
if (isExternalStorageWritable()) {
|
||||
try {
|
||||
FileWriter of = new FileWriter(getDataStorageDir().toString()
|
||||
+ "/" + fname, true);
|
||||
if (msgStr != null) {
|
||||
String dateTimeStr = tnow.format("%Y-%m-%d %H:%M:%S");
|
||||
Log.v(TAG, "writing msgStr");
|
||||
of.append(dateTimeStr+", "
|
||||
+tnow.toMillis(true)+", "
|
||||
+msgStr+"<br/>\n");
|
||||
}
|
||||
of.close();
|
||||
} catch (Exception ex) {
|
||||
Log.e(TAG, "writeToLogFile - error " + ex.toString());
|
||||
showToast("ERROR Writing to Log File");
|
||||
}
|
||||
if (ContextCompat.checkSelfPermission(mContext,
|
||||
Manifest.permission.WRITE_EXTERNAL_STORAGE)
|
||||
!= PackageManager.PERMISSION_GRANTED) {
|
||||
Log.e(TAG,"ERROR: We do not have permission to write to external storage");
|
||||
} else {
|
||||
Log.e(TAG, "ERROR - Can not Write to External Folder");
|
||||
if (isExternalStorageWritable()) {
|
||||
try {
|
||||
FileWriter of = new FileWriter(getDataStorageDir().toString()
|
||||
+ "/" + fname, true);
|
||||
if (msgStr != null) {
|
||||
String dateTimeStr = tnow.format("%Y-%m-%d %H:%M:%S");
|
||||
Log.v(TAG, "writing msgStr");
|
||||
of.append(dateTimeStr + ", "
|
||||
+ tnow.toMillis(true) + ", "
|
||||
+ msgStr + "<br/>\n");
|
||||
}
|
||||
of.close();
|
||||
} catch (Exception ex) {
|
||||
Log.e(TAG, "writeToLogFile - error " + ex.toString());
|
||||
showToast("ERROR Writing to Log File");
|
||||
}
|
||||
} else {
|
||||
Log.e(TAG, "ERROR - Can not Write to External Folder");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -40,6 +40,7 @@ import com.getpebble.android.kit.PebbleKit;
|
||||
import com.getpebble.android.kit.util.PebbleDictionary;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import org.jtransforms.fft.DoubleFFT_1D;
|
||||
|
||||
@@ -373,7 +374,12 @@ public class SdDataSourceGarmin extends SdDataSource {
|
||||
Log.v(TAG,"updateFromJSON - dataType="+dataTypeStr);
|
||||
if (dataTypeStr.equals("raw")) {
|
||||
Log.v(TAG,"updateFromJSON - processing raw data");
|
||||
mSdData.mHR = dataObject.getDouble("HR");
|
||||
try {
|
||||
mSdData.mHR = dataObject.getDouble("HR");
|
||||
} catch (JSONException e) {
|
||||
// if we get 'null' HR (For example if the heart rate is not working)
|
||||
mSdData.mHR = -1;
|
||||
}
|
||||
JSONArray accelVals = dataObject.getJSONArray("data");
|
||||
Log.v(TAG, "Received " + accelVals.length() + " acceleration values");
|
||||
int i;
|
||||
|
||||
@@ -68,6 +68,8 @@ import java.util.*;
|
||||
|
||||
import android.text.format.Time;
|
||||
|
||||
import com.rohitss.uceh.UCEHandler;
|
||||
|
||||
|
||||
/**
|
||||
* Based on example at:
|
||||
@@ -169,15 +171,18 @@ public class SdServer extends Service implements SdDataReceiver, SdLocationRecei
|
||||
mUtil.writeToSysLogFile("SdServer.onCreate()");
|
||||
|
||||
// Set our custom uncaught exception handler to report issues.
|
||||
Thread.setDefaultUncaughtExceptionHandler(
|
||||
new OsdUncaughtExceptionHandler(SdServer.this));
|
||||
//Thread.setDefaultUncaughtExceptionHandler(
|
||||
// new OsdUncaughtExceptionHandler(SdServer.this));
|
||||
new UCEHandler.Builder(this)
|
||||
.addCommaSeparatedEmailAddresses("crashreports@openseizuredetector.org.uk,")
|
||||
.build();
|
||||
//int i = 5/0; // Force exception to test handler.
|
||||
|
||||
|
||||
// Create a wake lock, but don't use it until the service is started.
|
||||
PowerManager powerManager = (PowerManager) getSystemService(POWER_SERVICE);
|
||||
mWakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
|
||||
"MyWakelockTag");
|
||||
"OSD:WakeLock");
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -49,6 +49,8 @@ import android.widget.Button;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.rohitss.uceh.UCEHandler;
|
||||
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
|
||||
@@ -82,7 +84,11 @@ public class StartupActivity extends Activity {
|
||||
Log.i(TAG,"onCreate()");
|
||||
|
||||
// Set our custom uncaught exception handler to report issues.
|
||||
Thread.setDefaultUncaughtExceptionHandler(new OsdUncaughtExceptionHandler(StartupActivity.this));
|
||||
//Thread.setDefaultUncaughtExceptionHandler(new OsdUncaughtExceptionHandler(StartupActivity.this));
|
||||
new UCEHandler.Builder(this)
|
||||
.addCommaSeparatedEmailAddresses("crashreports@openseizuredetector.org.uk,")
|
||||
.build();
|
||||
|
||||
|
||||
mHandler = new Handler();
|
||||
mUtil = new OsdUtil(this, mHandler);
|
||||
@@ -103,6 +109,10 @@ public class StartupActivity extends Activity {
|
||||
PreferenceManager.setDefaultValues(this, R.xml.camera_prefs, true);
|
||||
PreferenceManager.setDefaultValues(this, R.xml.general_prefs, true);
|
||||
PreferenceManager.setDefaultValues(this, R.xml.network_datasource_prefs, true);
|
||||
PreferenceManager.setDefaultValues(this, R.xml.pebble_datasource_prefs, true);
|
||||
PreferenceManager.setDefaultValues(this, R.xml.garmin_datasource_prefs, true);
|
||||
PreferenceManager.setDefaultValues(this, R.xml.seizure_detector_prefs, true);
|
||||
PreferenceManager.setDefaultValues(this, R.xml.network_passive_datasource_prefs, true);
|
||||
|
||||
|
||||
Button b;
|
||||
@@ -174,6 +184,14 @@ public class StartupActivity extends Activity {
|
||||
mUtil.writeToSysLogFile("StartupActivity.onStart()");
|
||||
TextView tv;
|
||||
|
||||
if (mUtil.arePermissionsOK()) {
|
||||
Log.i(TAG,"onStart() - Permissions OK");
|
||||
} else {
|
||||
Log.i(TAG,"onStart() - Permissions Not OK - requesting them");
|
||||
mUtil.requestPermissions(this);
|
||||
}
|
||||
|
||||
|
||||
String versionName = mUtil.getAppVersionName();
|
||||
tv = (TextView) findViewById(R.id.appNameTv);
|
||||
tv.setText("OpenSeizureDetector V" + versionName);
|
||||
@@ -198,6 +216,8 @@ public class StartupActivity extends Activity {
|
||||
mUsingPebbleDataSource = true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (mUtil.isServerRunning()) {
|
||||
Log.i(TAG, "onStart() - server running - stopping it");
|
||||
mUtil.writeToSysLogFile("StartupActivity.onStart() - server already running - stopping it.");
|
||||
|
||||
Reference in New Issue
Block a user