List of usage examples for android.content Context TELEPHONY_SERVICE
String TELEPHONY_SERVICE
To view the source code for android.content Context TELEPHONY_SERVICE.
Click Source Link
From source file:system.info.reader.java
public void refreshOnce() {//something not change, then put here Properties.sdkversion = android.os.Build.VERSION.SDK; cameraSizes = Properties.camera(); Properties.dr();// w ww . ja va2 s . c om processors = Properties.processor(); Properties.memtotal(); sensorMgr = (SensorManager) getSystemService(Context.SENSOR_SERVICE); Properties.sensors = sensorMgr.getSensorList(Sensor.TYPE_ALL).size() + ""; TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); teles = Properties.telephonies(tm); try { serverWeb.loadUrl(getString(R.string.url)); } catch (Exception e) { } }
From source file:com.andybotting.tubechaser.activity.StationDetail.java
/** * Upload stats/*from ww w . j a v a2 s .c om*/ */ private void uploadStats() { if (LOGV) Log.v(TAG, "Sending Station/Line statistics"); // gather all of the device info try { TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); String device_uuid = tm.getDeviceId(); String device_id = "00000000000000000000000000000000"; if (device_uuid != null) { device_id = GenericUtil.MD5(device_uuid); } LocationManager mLocationManager = (LocationManager) getSystemService(LOCATION_SERVICE); Location location = mLocationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER); // post the data HttpClient client = new DefaultHttpClient(); HttpPost post = new HttpPost("http://tubechaser.andybotting.com/stats/depart/send"); post.setHeader("Content-Type", "application/x-www-form-urlencoded"); List<NameValuePair> pairs = new ArrayList<NameValuePair>(); pairs.add(new BasicNameValuePair("device_id", device_id)); pairs.add(new BasicNameValuePair("station_id", String.valueOf(mStation.getId()))); pairs.add(new BasicNameValuePair("line_id", String.valueOf(mLine.getId()))); if (location != null) { pairs.add(new BasicNameValuePair("latitude", String.valueOf(location.getLatitude()))); pairs.add(new BasicNameValuePair("longitude", String.valueOf(location.getLongitude()))); pairs.add(new BasicNameValuePair("accuracy", String.valueOf(location.getAccuracy()))); } try { post.setEntity(new UrlEncodedFormEntity(pairs)); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } try { HttpResponse response = client.execute(post); response.getStatusLine().getStatusCode(); } catch (Exception e) { e.printStackTrace(); } } catch (Exception e) { e.printStackTrace(); } }
From source file:com.andybotting.tramhunter.activity.StopDetailsActivity.java
/** * Upload statistics to our web server/*from w w w .ja v a 2 s.c o m*/ */ private void uploadStats() { if (LOGV) Log.i(TAG, "Sending stop request statistics"); // gather all of the device info try { TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); String device_uuid = tm.getDeviceId(); String device_id = "00000000000000000000000000000000"; if (device_uuid != null) { device_id = GenericUtil.MD5(device_uuid); } LocationManager mLocationManager = (LocationManager) getSystemService(LOCATION_SERVICE); Location location = mLocationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER); // post the data HttpClient client = new DefaultHttpClient(); HttpPost post = new HttpPost("http://tramhunter.andybotting.com/stats/stop/send"); post.setHeader("Content-Type", "application/x-www-form-urlencoded"); List<NameValuePair> pairs = new ArrayList<NameValuePair>(); pairs.add(new BasicNameValuePair("device_id", device_id)); pairs.add(new BasicNameValuePair("guid", ttService.getGUID())); pairs.add(new BasicNameValuePair("ttid", String.valueOf(mStop.getTramTrackerID()))); if (location != null) { pairs.add(new BasicNameValuePair("latitude", String.valueOf(location.getLatitude()))); pairs.add(new BasicNameValuePair("longitude", String.valueOf(location.getLongitude()))); pairs.add(new BasicNameValuePair("accuracy", String.valueOf(location.getAccuracy()))); } try { post.setEntity(new UrlEncodedFormEntity(pairs)); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } try { HttpResponse response = client.execute(post); response.getStatusLine().getStatusCode(); } catch (Exception e) { e.printStackTrace(); } } catch (Exception e) { e.printStackTrace(); } }
From source file:net.kidlogger.kidlogger.KLService.java
public void setupLogging() { // Set up GPS / Network logging if (Settings.loggingGps(this)) { startGpsUpdates();// ww w. j av a 2 s .c o m gpsOn = true; } // Set up WiFi logging if (Settings.loggingWifi(this)) { wifiReceiver = new WifiReceiver(this); registerReceiver(wifiReceiver, new IntentFilter(WifiManager.NETWORK_STATE_CHANGED_ACTION)); wifiOn = true; } // Set up SMS logging if (Settings.loggingSms(this)) { smsObserver = new SmsObserver(this, handlering); IntentFilter smsFilter = new IntentFilter(SMS_RECEIVED); registerReceiver(smsObserver.inSms, smsFilter); smsOn = true; } // Set up Calls logging if (Settings.loggingCalls(this)) { IntentFilter callsFilter = new IntentFilter(TelephonyManager.ACTION_PHONE_STATE_CHANGED); callsReceiver = new CallsReceiver(this); registerReceiver(callsReceiver, callsFilter); callOn = true; } // Set up Idle logging IntentFilter idleFilter = new IntentFilter(Intent.ACTION_SCREEN_OFF); idleFilter.addAction(Intent.ACTION_USER_PRESENT); idleReceiver = new IdleReceiver(this); registerReceiver(idleReceiver, idleFilter); idleOn = true; /*if(Settings.loggingIdle(this)){ IntentFilter idleFilter = new IntentFilter(Intent.ACTION_SCREEN_OFF); idleFilter.addAction(Intent.ACTION_USER_PRESENT); idleReceiver = new IdleReceiver(this); registerReceiver(idleReceiver, idleFilter); idleOn = true; }*/ // Set up URL logging if (Settings.loggingUrl(this)) { urlObserver = new HistoryObserver(this, handlering); urlOn = true; } // Set up USB logging if (Settings.loggingUsb(this)) { IntentFilter usbFilter = new IntentFilter(Intent.ACTION_UMS_CONNECTED); usbFilter.addAction(Intent.ACTION_UMS_DISCONNECTED); usbReceiver = new UsbReceiver(this); registerReceiver(usbReceiver, usbFilter); usbOn = true; } // Set up Tasks logging if (logTask) { // Check if a new Application was started taskScan = new Runnable() { public void run() { new Thread(new Runnable() { public void run() { doScanTask(); } }).start(); if (userPresent) { handleTask.postDelayed(this, SCAN_TASK_TIME); scanningTask = true; } else { scanningTask = false; } } }; handleTask.postDelayed(taskScan, SCAN_TASK_TIME); taskOn = true; } // Set up Clipboard logging if (logClip) { // Scan clipboard content, only first 30 characters clipboardScan = new Runnable() { public void run() { new Thread(new Runnable() { public void run() { doScanClipboard(); } }).start(); if (userPresent) { handleClipb.postDelayed(this, SCAN_CLIP_TIME); scanningClip = true; } else { scanningClip = false; } } }; handleClipb.postDelayed(clipboardScan, SCAN_CLIP_TIME); clipOn = true; } // Set up Power logging if (Settings.loggingPower(this)) { IntentFilter powerFilter = new IntentFilter(Intent.ACTION_SHUTDOWN); powerReceiver = new ShutdownReceiver(this); registerReceiver(powerReceiver, powerFilter); powerOn = true; } // Set up Memory Card logging if (Settings.loggingMedia(this)) { IntentFilter mediaFilter = new IntentFilter(Intent.ACTION_MEDIA_REMOVED); mediaFilter.addAction(Intent.ACTION_MEDIA_BAD_REMOVAL); mediaFilter.addAction(Intent.ACTION_MEDIA_MOUNTED); mediaFilter.addAction(Intent.ACTION_MEDIA_UNMOUNTED); mediaFilter.addAction(Intent.ACTION_MEDIA_SHARED); mediaFilter.addDataScheme("file"); mediaReceiver = new MediaReceiver(this); registerReceiver(mediaReceiver, mediaFilter); mediaOn = true; } // Set up GSM logging if (Settings.loggingGsm(this)) { gsmObserver = new GsmObserver(this); telManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); telManager.listen(gsmObserver, PhoneStateListener.LISTEN_SERVICE_STATE | PhoneStateListener.LISTEN_CELL_LOCATION); gsmOn = true; } // Set up Airplane mode receiver if (Settings.loggingAir(this)) { IntentFilter airFilter = new IntentFilter(Intent.ACTION_AIRPLANE_MODE_CHANGED); airReceiver = new AirplaneReceiver(this); registerReceiver(airReceiver, airFilter); airOn = true; } // Set up Photos logging if (Settings.loggingPhotos(this)) { photoObserver = new PhotoObserver(this, this, handlering); photoOn = true; } // Set up SliceMultimediaFile if (Settings.uploadPhotos(this) || Settings.uploadRecords(this)) { mediaSlicer = new SliceMultimediaFile(this); } // Set up ConnectivityReceiver mConReceiver = new ConnectivityReceiver(this); registerReceiver(mConReceiver, new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION)); // Ser up CallIntentReceiver //outCallReceiver = new CallIntentReceiver(); //registerReceiver(outCallReceiver, new IntentFilter(KLService.OUTGOING_CALL)); }
From source file:com.wbtech.ums.UmsAgent.java
private static JSONObject getClientDataJSONObject(Context context) { TelephonyManager tm = (TelephonyManager) (context.getSystemService(Context.TELEPHONY_SERVICE)); WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); WindowManager manager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); DisplayMetrics displaysMetrics = new DisplayMetrics(); manager.getDefaultDisplay().getMetrics(displaysMetrics); LocationManager locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE); BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter(); JSONObject clientData = new JSONObject(); try {// w ww. ja v a2 s. c o m clientData.put("os_version", CommonUtil.getOsVersion(context)); clientData.put("platform", "android"); clientData.put("language", Locale.getDefault().getLanguage()); clientData.put("deviceid", tm.getDeviceId() == null ? "" : tm.getDeviceId());// clientData.put("appkey", CommonUtil.getAppKey(context)); clientData.put("resolution", displaysMetrics.widthPixels + "x" + displaysMetrics.heightPixels); clientData.put("ismobiledevice", true); clientData.put("phonetype", tm.getPhoneType());// clientData.put("imsi", tm.getSubscriberId()); clientData.put("network", CommonUtil.getNetworkTypeWIFI2G3G(context)); clientData.put("time", CommonUtil.getTime()); clientData.put("version", CommonUtil.getVersion(context)); clientData.put(UserIdentifier, CommonUtil.getUserIdentifier(context)); SCell sCell = CommonUtil.getCellInfo(context); clientData.put("mccmnc", sCell != null ? "" + sCell.MCCMNC : ""); clientData.put("cellid", sCell != null ? sCell.CID + "" : ""); clientData.put("lac", sCell != null ? sCell.LAC + "" : ""); clientData.put("modulename", Build.PRODUCT); clientData.put("devicename", CommonUtil.getDeviceName()); clientData.put("wifimac", wifiManager.getConnectionInfo().getMacAddress()); clientData.put("havebt", adapter == null ? false : true); clientData.put("havewifi", CommonUtil.isWiFiActive(context)); clientData.put("havegps", locationManager == null ? false : true); clientData.put("havegravity", CommonUtil.isHaveGravity(context));// LatitudeAndLongitude coordinates = CommonUtil.getLatitudeAndLongitude(context, UmsAgent.mUseLocationService); clientData.put("latitude", coordinates.latitude); clientData.put("longitude", coordinates.longitude); CommonUtil.printLog("clientData---------->", clientData.toString()); } catch (JSONException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } return clientData; }
From source file:xj.property.ums.UmsAgent.java
public static JSONObject getClientDataJSONObject(Context context) { TelephonyManager tm = (TelephonyManager) (context.getSystemService(Context.TELEPHONY_SERVICE)); WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); WindowManager manager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); DisplayMetrics displaysMetrics = new DisplayMetrics(); manager.getDefaultDisplay().getMetrics(displaysMetrics); LocationManager locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE); BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter(); JSONObject clientData = new JSONObject(); try {//from w ww. j a va 2 s .c om clientData.put("os_version", CommonUtil.getOsVersion(context)); clientData.put("platform", "android"); clientData.put("language", Locale.getDefault().getLanguage()); clientData.put("deviceid", tm.getDeviceId() == null ? "" : tm.getDeviceId());// clientData.put("appkey", CommonUtil.getAppKey(context)); clientData.put("resolution", displaysMetrics.widthPixels + "x" + displaysMetrics.heightPixels); clientData.put("ismobiledevice", true); clientData.put("phonetype", tm.getPhoneType());// clientData.put("imsi", tm.getSubscriberId()); clientData.put("network", CommonUtil.getNetworkTypeWIFI2G3G(context)); clientData.put("time", CommonUtil.getTime()); clientData.put("version", CommonUtil.getVersion(context)); clientData.put(UserIdentifier, CommonUtil.getUserIdentifier(context)); SCell sCell = CommonUtil.getCellInfo(context); clientData.put("mccmnc", sCell != null ? "" + sCell.MCCMNC : ""); clientData.put("cellid", sCell != null ? sCell.CID + "" : ""); clientData.put("lac", sCell != null ? sCell.LAC + "" : ""); clientData.put("modulename", Build.PRODUCT); clientData.put("devicename", CommonUtil.getDeviceName()); clientData.put("wifimac", wifiManager.getConnectionInfo().getMacAddress()); clientData.put("havebt", adapter == null ? false : true); clientData.put("havewifi", CommonUtil.isWiFiActive(context)); clientData.put("havegps", locationManager == null ? false : true); clientData.put("havegravity", CommonUtil.isHaveGravity(context));// LatitudeAndLongitude coordinates = CommonUtil.getLatitudeAndLongitude(context, UmsAgent.mUseLocationService); clientData.put("latitude", coordinates.latitude); clientData.put("longitude", coordinates.longitude); CommonUtil.printLog("clientData---------->", clientData.toString()); } catch (JSONException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } return clientData; }
From source file:ca.psiphon.PsiphonTunnel.java
private static String getDeviceRegion(Context context) { String region = ""; TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); if (telephonyManager != null) { region = telephonyManager.getSimCountryIso(); if (region == null) { region = ""; }/*from w ww .ja v a 2s .com*/ if (region.length() == 0 && telephonyManager.getPhoneType() != TelephonyManager.PHONE_TYPE_CDMA) { region = telephonyManager.getNetworkCountryIso(); if (region == null) { region = ""; } } } if (region.length() == 0) { Locale defaultLocale = Locale.getDefault(); if (defaultLocale != null) { region = defaultLocale.getCountry(); } } return region.toUpperCase(Locale.US); }
From source file:com.google.android.gms.location.sample.geofencing.MainActivity.java
public void GetID() { List<NeighboringCellInfo> neighCell = null; TelephonyManager telManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); neighCell = telManager.getNeighboringCellInfo(); for (int i = 0; i < neighCell.size(); i++) { try {//w ww . java 2s . c o m NeighboringCellInfo thisCell = neighCell.get(i); int thisNeighCID = thisCell.getCid(); int thisNeighRSSI = thisCell.getRssi(); Log.i("Info:", " cid:" + thisNeighCID + " - " + thisNeighRSSI); } catch (NumberFormatException e) { e.printStackTrace(); NeighboringCellInfo thisCell = neighCell.get(i); Log.i("exception", neighCell.toString()); } } String networkOperator = telManager.getNetworkOperator(); String mcc = "not avl", mnc = "not avl"; if (networkOperator != null) { mcc = networkOperator.substring(0, 3); mnc = networkOperator.substring(3); } Log.i("", "mcc:" + mcc); Log.i("", "mnc:" + mnc); }
From source file:org.hfoss.posit.android.sync.Communicator.java
/** * Returns a list of guIds for server finds that need syncing. * /*from www . j av a 2 s.c om*/ * @return */ public static String getServerFindsNeedingSync(Context context, String authKey) { String response = ""; String url = ""; SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); String server = prefs.getString(SERVER_PREF, ""); int projectId = prefs.getInt(PROJECT_PREF, 0); TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); String imei = telephonyManager.getDeviceId(); url = server + "/api/getDeltaFindsIds?authKey=" + authKey + "&imei=" + imei + "&projectId=" + projectId; Log.i(TAG, "getDeltaFindsIds URL=" + url); try { response = doHTTPGET(url); } catch (Exception e) { Log.i(TAG, e.getMessage()); } Log.i(TAG, "serverFindsNeedingSync = " + response); return response; }
From source file:com.t2.compassionMeditation.MeditationActivity.java
/** Called when the activity is first created. */ @Override//from www . java 2 s . c o m public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Log.i(TAG, this.getClass().getSimpleName() + ".onCreate()"); mInstance = this; mRateOfChange = new RateOfChange(mRateOfChangeSize); mIntroFade = 255; // We don't want the screen to timeout in this activity getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN); this.requestWindowFeature(Window.FEATURE_NO_TITLE); // This needs to happen BEFORE setContentView setContentView(R.layout.buddah_activity_layout); sharedPref = PreferenceManager.getDefaultSharedPreferences(getBaseContext()); currentMindsetData = new MindsetData(this); mSaveRawWave = SharedPref.getBoolean(this, BioZenConstants.PREF_SAVE_RAW_WAVE, BioZenConstants.PREF_SAVE_RAW_WAVE_DEFAULT); mShowAGain = SharedPref.getBoolean(this, BioZenConstants.PREF_SHOW_A_GAIN, BioZenConstants.PREF_SHOW_A_GAIN_DEFAULT); mAllowComments = SharedPref.getBoolean(this, BioZenConstants.PREF_COMMENTS, BioZenConstants.PREF_COMMENTS_DEFAULT); mShowForeground = SharedPref.getBoolean(this, "show_lotus", true); mShowToast = SharedPref.getBoolean(this, "show_toast", true); mAudioTrackResourceName = SharedPref.getString(this, "audio_track", "None"); mBaseImageResourceName = SharedPref.getString(this, "background_images", "Sunset"); mBioHarnessParameters = getResources().getStringArray(R.array.bioharness_parameters_array); setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); String s = SharedPref.getString(this, BioZenConstants.PREF_SESSION_LENGTH, "10"); mSecondsRemaining = Integer.parseInt(s) * 60; mSecondsTotal = mSecondsRemaining; s = SharedPref.getString(this, BioZenConstants.PREF_ALPHA_GAIN, "5"); mAlphaGain = Float.parseFloat(s); mMovingAverage = new TMovingAverageFilter(mMovingAverageSize); mMovingAverageROC = new TMovingAverageFilter(mMovingAverageSizeROC); View v1 = findViewById(R.id.buddahView); v1.setOnTouchListener(this); Resources resources = this.getResources(); AssetManager assetManager = resources.getAssets(); // Set up member variables to UI Elements mTextInfoView = (TextView) findViewById(R.id.textViewInfo); mTextBioHarnessView = (TextView) findViewById(R.id.textViewBioHarness); mCountdownTextView = (TextView) findViewById(R.id.countdownTextView); mCountdownImageView = (ImageView) findViewById(R.id.imageViewCountdown); mPauseButton = (ImageButton) findViewById(R.id.buttonPause); mSignalImage = (ImageView) findViewById(R.id.imageView1); mTextViewInstructions = (TextView) findViewById(R.id.textViewInstructions); // Note that the seek bar is a debug thing - used only to set the // alpha of the buddah image manually for visual testing mSeekBar = (SeekBar) findViewById(R.id.seekBar1); mSeekBar.setOnSeekBarChangeListener(this); // Scale such that values to the right of center are scaled 1 - 10 // and values to the left of center are scaled 0 = .99999 if (mAlphaGain > 1.0) { mSeekBar.setProgress(50 + (int) (mAlphaGain * 5)); } else { int i = (int) (mAlphaGain * 50); mSeekBar.setProgress(i); } // mSeekBar.setProgress((int) mAlphaGain * 10); // Controls start as invisible, need to touch screen to activate them mCountdownTextView.setVisibility(View.INVISIBLE); mCountdownImageView.setVisibility(View.INVISIBLE); mTextInfoView.setVisibility(View.INVISIBLE); mTextBioHarnessView.setVisibility(View.INVISIBLE); mPauseButton.setVisibility(View.INVISIBLE); mPauseButton.setVisibility(View.VISIBLE); mSeekBar.setVisibility(View.INVISIBLE); mBackgroundImage = (ImageView) findViewById(R.id.buddahView); mForegroundImage = (ImageView) findViewById(R.id.lotusView); mBaseImage = (ImageView) findViewById(R.id.backgroundView); if (!mShowForeground) { mForegroundImage.setVisibility(View.INVISIBLE); } int resource = 0; if (mBaseImageResourceName.equalsIgnoreCase("Buddah")) { mBackgroundImage.setImageResource(R.drawable.buddha); mForegroundImage.setImageResource(R.drawable.lotus_flower); mBaseImage.setImageResource(R.drawable.none_bg); } else if (mBaseImageResourceName.equalsIgnoreCase("Bob")) { mBackgroundImage.setImageResource(R.drawable.bigbob); mForegroundImage.setImageResource(R.drawable.red_nose); mBaseImage.setImageResource(R.drawable.none_bg); } else if (mBaseImageResourceName.equalsIgnoreCase("Sunset")) { mBackgroundImage.setImageResource(R.drawable.eeg_layer); mForegroundImage.setImageResource(R.drawable.breathing_rate); mBaseImage.setImageResource(R.drawable.meditation_bg); } // Initialize SPINE by passing the fileName with the configuration properties try { mManager = SPINEFactory.createSPINEManager("SPINETestApp.properties", resources); } catch (InstantiationException e) { Log.e(TAG, "Exception creating SPINE manager: " + e.toString()); e.printStackTrace(); } // Since Mindset is a static node we have to manually put it in the active node list // Note that the sensor id 0xfff1 (-15) is a reserved id for this particular sensor Node mindsetNode = null; mindsetNode = new Node(new Address("" + Constants.RESERVED_ADDRESS_MINDSET)); mManager.getActiveNodes().add(mindsetNode); Node zepherNode = null; zepherNode = new Node(new Address("" + Constants.RESERVED_ADDRESS_ZEPHYR)); mManager.getActiveNodes().add(zepherNode); // The arduino node is programmed to look like a static Spine node // Note that currently we don't have to turn it on or off - it's always streaming // Since Spine (in this case) is a static node we have to manually put it in the active node list // Since the final int RESERVED_ADDRESS_ARDUINO_SPINE = 1; // 0x0001 mSpineNode = new Node(new Address("" + RESERVED_ADDRESS_ARDUINO_SPINE)); mManager.getActiveNodes().add(mSpineNode); // Create a broadcast receiver. Note that this is used ONLY for command messages from the service // All data from the service goes through the mail SPINE mechanism (received(Data data)). // See public void received(Data data) this.mCommandReceiver = new SpineReceiver(this); try { PackageManager packageManager = this.getPackageManager(); PackageInfo info = packageManager.getPackageInfo(this.getPackageName(), 0); mApplicationVersion = info.versionName; Log.i(TAG, "BioZen Application Version: " + mApplicationVersion + ", Activity Version: " + mActivityVersion); } catch (NameNotFoundException e) { Log.e(TAG, e.toString()); } // First create GraphBioParameters for each of the ECG static params (ie mindset) int itemId = 0; eegPos = itemId; // eeg always comes first mBioParameters.clear(); for (itemId = 0; itemId < MindsetData.NUM_BANDS + 2; itemId++) { // 2 extra, for attention and meditation GraphBioParameter param = new GraphBioParameter(itemId, MindsetData.spectralNames[itemId], "", true); param.isShimmer = false; mBioParameters.add(param); } // Now create all of the potential dynamic GBraphBioParameters (GSR, EMG, ECG, HR, Skin Temp, Resp Rate String[] paramNamesStringArray = getResources().getStringArray(R.array.parameter_names); for (String paramName : paramNamesStringArray) { if (paramName.equalsIgnoreCase("not assigned")) continue; if (paramName.equalsIgnoreCase("EEG")) continue; GraphBioParameter param = new GraphBioParameter(itemId, paramName, "", true); if (paramName.equalsIgnoreCase("gsr")) { gsrPos = itemId; param.isShimmer = true; param.shimmerSensorConstant = SPINESensorConstants.SHIMMER_GSR_SENSOR; param.shimmerNode = getShimmerNode(); } if (paramName.equalsIgnoreCase("emg")) { emgPos = itemId; param.isShimmer = true; param.shimmerSensorConstant = SPINESensorConstants.SHIMMER_EMG_SENSOR; param.shimmerNode = getShimmerNode(); } if (paramName.equalsIgnoreCase("ecg")) { ecgPos = itemId; param.isShimmer = true; param.shimmerSensorConstant = SPINESensorConstants.SHIMMER_ECG_SENSOR; param.shimmerNode = getShimmerNode(); } if (paramName.equalsIgnoreCase("heart rate")) { heartRatePos = itemId; param.isShimmer = false; } if (paramName.equalsIgnoreCase("resp rate")) { respRatePos = itemId; param.isShimmer = false; } if (paramName.equalsIgnoreCase("skin temp")) { skinTempPos = itemId; param.isShimmer = false; } if (paramName.equalsIgnoreCase("EHealth Airflow")) { eHealthAirFlowPos = itemId; param.isShimmer = false; } if (paramName.equalsIgnoreCase("EHealth Temp")) { eHealthTempPos = itemId; param.isShimmer = false; } if (paramName.equalsIgnoreCase("EHealth SpO2")) { eHealthSpO2Pos = itemId; param.isShimmer = false; } if (paramName.equalsIgnoreCase("EHealth Heartrate")) { eHealthHeartRatePos = itemId; param.isShimmer = false; } if (paramName.equalsIgnoreCase("EHealth GSR")) { eHealthGSRPos = itemId; param.isShimmer = false; } itemId++; mBioParameters.add(param); } // The session start time will be used as session id // Note this also sets session start time // **** This session ID will be prepended to all JSON data stored // in the external database until it's changed (by the start // of a new session. Calendar cal = Calendar.getInstance(); SharedPref.setBioSessionId(sharedPref, cal.getTimeInMillis()); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd_HH-mm-ss", Locale.US); String sessionDate = sdf.format(new Date()); long sessionId = SharedPref.getLong(this, "bio_session_start_time", 0); mUserId = SharedPref.getString(this, "SelectedUser", ""); // Now get the database object associated with this user try { mBioUserDao = getHelper().getBioUserDao(); mBioSessionDao = getHelper().getBioSessionDao(); QueryBuilder<BioUser, Integer> builder = mBioUserDao.queryBuilder(); builder.where().eq(BioUser.NAME_FIELD_NAME, mUserId); builder.limit(1); // builder.orderBy(ClickCount.DATE_FIELD_NAME, false).limit(30); List<BioUser> list = mBioUserDao.query(builder.prepare()); if (list.size() == 1) { mCurrentBioUser = list.get(0); } else if (list.size() == 0) { try { mCurrentBioUser = new BioUser(mUserId, System.currentTimeMillis()); mBioUserDao.create(mCurrentBioUser); } catch (SQLException e1) { Log.e(TAG, "Error creating user " + mUserId, e1); } } else { Log.e(TAG, "General Database error" + mUserId); } } catch (SQLException e) { Log.e(TAG, "Can't find user: " + mUserId, e); } mSignalImage.setImageResource(R.drawable.signal_bars0); // Check to see of there a device configured for EEG, if so then show the skin conductance meter String tmp = SharedPref.getString(this, "EEG", null); if (tmp != null) { mSignalImage.setVisibility(View.VISIBLE); mTextViewInstructions.setVisibility(View.VISIBLE); } else { mSignalImage.setVisibility(View.INVISIBLE); mTextViewInstructions.setVisibility(View.INVISIBLE); } mDataOutHandler = new DataOutHandler(this, mUserId, sessionDate, mAppId, DataOutHandler.DATA_TYPE_EXTERNAL_SENSOR, sessionId); if (mDatabaseEnabled) { TelephonyManager telephonyManager = (TelephonyManager) this.getSystemService(Context.TELEPHONY_SERVICE); String myNumber = telephonyManager.getLine1Number(); String remoteDatabaseUri = SharedPref.getString(this, "database_sync_name", getString(R.string.database_uri)); // remoteDatabaseUri += myNumber; Log.d(TAG, "Initializing database at " + remoteDatabaseUri); // TODO: remove try { mDataOutHandler.initializeDatabase(dDatabaseName, dDesignDocName, dDesignDocId, byDateViewName, remoteDatabaseUri); } catch (DataOutHandlerException e) { Log.e(TAG, e.toString()); e.printStackTrace(); } mDataOutHandler.setRequiresAuthentication(false); } mBioDataProcessor.initialize(mDataOutHandler); mLoggingEnabled = SharedPref.getBoolean(this, "enable_logging", true); mDatabaseEnabled = SharedPref.getBoolean(this, "database_enabled", false); mAntHrmEnabled = SharedPref.getBoolean(this, "enable_ant_hrm", false); mInternalSensorMonitoring = SharedPref.getBoolean(this, "inernal_sensor_monitoring_enabled", false); if (mAntHrmEnabled) { mHeartRateSource = HEARTRATE_ANT; } else { mHeartRateSource = HEARTRATE_ZEPHYR; } if (mLoggingEnabled) { mDataOutHandler.enableLogging(this); } if (mLogCatEnabled) { mDataOutHandler.enableLogCat(); } // Log the version try { PackageManager packageManager = getPackageManager(); PackageInfo info = packageManager.getPackageInfo(getPackageName(), 0); mApplicationVersion = info.versionName; String versionString = mAppId + " application version: " + mApplicationVersion; DataOutPacket packet = new DataOutPacket(); packet.add(DataOutHandlerTags.version, versionString); try { mDataOutHandler.handleDataOut(packet); } catch (DataOutHandlerException e) { Log.e(TAG, e.toString()); e.printStackTrace(); } } catch (NameNotFoundException e) { Log.e(TAG, e.toString()); } if (mInternalSensorMonitoring) { // IntentSender Launches our service scheduled with with the alarm manager mBigBrotherService = PendingIntent.getService(MeditationActivity.this, 0, new Intent(MeditationActivity.this, BigBrotherService.class), 0); long firstTime = SystemClock.elapsedRealtime(); // Schedule the alarm! AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE); am.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, firstTime, mPollingPeriod * 1000, mBigBrotherService); // Tell the user about what we did. Toast.makeText(MeditationActivity.this, R.string.service_scheduled, Toast.LENGTH_LONG).show(); } }