Added autostart on boot feature

This commit is contained in:
Graham Jones
2016-12-14 21:18:18 +00:00
parent c9e3f9374b
commit 5c47f95a8f
4 changed files with 59 additions and 4 deletions

View File

@@ -0,0 +1,31 @@
package uk.org.openseizuredetector;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import android.util.Log;
import android.widget.Toast;
/**
* Created by graham on 14/12/16.
*/
public class BootBroadcastReceiver extends BroadcastReceiver {
private String TAG = "BroadcastReceiver";
@Override
public void onReceive(Context context, Intent intent) {
Log.v(TAG, "onReceive()");
SharedPreferences SP = PreferenceManager
.getDefaultSharedPreferences(context);
boolean autoStart = SP.getBoolean("AutoStart",false);
Log.v(TAG,"onReceive() - autoStart = "+autoStart);
if (autoStart && Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction())) {
Intent startUpIntent = new Intent(context, StartupActivity.class);
startUpIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(startUpIntent);
}
}
}