List of usage examples for android.hardware Sensor getName
public String getName()
From source file:io.github.data4all.service.OrientationListener.java
@Override public void onAccuracyChanged(Sensor sensor, int accuracy) { if (sensor.getType() == Sensor.TYPE_ACCELEROMETER) { if (accuracy < SensorManager.SENSOR_STATUS_ACCURACY_HIGH) { Log.d(TAG, "The sensor: " + sensor.getName() + " has now the accuracy of " + accuracy + " it needs recalibration!"); accOk = accuracy;// ww w . j a v a2s. co m } else { Log.d(TAG, "The sensor: " + sensor.getName() + " has now the accuracy of " + accuracy + " App ready to use!"); accOk = accuracy; } } if (sensor.getType() == Sensor.TYPE_MAGNETIC_FIELD) { if (accuracy < SensorManager.SENSOR_STATUS_ACCURACY_HIGH) { Log.d(TAG, "The sensor: " + sensor.getName() + " has now the accuracy of " + accuracy + " it needs recalibration!"); magOk = accuracy; } else { Log.d(TAG, "The sensor: " + sensor.getName() + " has now the accuracy of " + accuracy + " App ready to use!"); magOk = accuracy; } } this.checkAccuracy(); /* * Creates a new Intent containing a Uri object BROADCAST_ACTION is a * custom Intent action */ final Intent localIntent = new Intent(BROADCAST_CAMERA) // Puts the status into the Intent .putExtra(INTENT_CAMERA_UPDATE, true); // Broadcasts the Intent to receivers in this app. LocalBroadcastManager.getInstance(this).sendBroadcast(localIntent); }
From source file:com.mrchandler.disableprox.ui.SensorSettingsActivity.java
@Override protected void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.sensor_setting_activity_layout); SensorManager manager = (SensorManager) getSystemService(SENSOR_SERVICE); //getSensorList returns an unmodifiable list fullSensorList = new ArrayList<>(manager.getSensorList(Sensor.TYPE_ALL)); Collections.sort(fullSensorList, new Comparator<Sensor>() { @Override//w ww .java 2 s.c om public int compare(Sensor lhs, Sensor rhs) { String lhsName = SensorUtil.getHumanStringType(lhs); String rhsName = SensorUtil.getHumanStringType(rhs); if (lhsName == null) { lhsName = lhs.getName(); } if (rhsName == null) { rhsName = rhs.getName(); } return lhsName.compareTo(rhsName); } }); //Set sorted sensor list for the SensorListFragment ((SensorListFragment) getSupportFragmentManager().findFragmentById(R.id.sensor_list_fragment)) .setSensors(fullSensorList); if (findViewById(R.id.drawer_layout) != null) { drawer = (DrawerLayout) findViewById(R.id.drawer_layout); toggle = new ActionBarDrawerToggle(this, (DrawerLayout) findViewById(R.id.drawer_layout), android.R.string.yes, android.R.string.no); drawer.setDrawerListener(toggle); drawer.setScrimColor(getResources().getColor(android.R.color.background_dark)); if (getActionBar() != null) { getActionBar().setDisplayHomeAsUpEnabled(true); getActionBar().setHomeButtonEnabled(true); getActionBar().setDisplayShowHomeEnabled(false); } toggle.syncState(); } fab = (FloatingActionButton) findViewById(R.id.fab); fab.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (currentFragment != null) { currentFragment.saveSettings(); } } }); ObservableScrollView scrollView = (ObservableScrollView) findViewById(R.id.scrollView); fab.attachToScrollView(scrollView); fab.hide(false); if (savedInstanceState != null) { SensorSettingsFragment fragment = (SensorSettingsFragment) getSupportFragmentManager() .getFragment(savedInstanceState, CURRENT_FRAGMENT); if (fragment != null) { getSupportFragmentManager().beginTransaction() .replace(R.id.fragment_container, fragment, CURRENT_FRAGMENT).commit(); String sensorTitle = SensorUtil.getHumanStringType(fragment.sensor); if (sensorTitle == null) { sensorTitle = fragment.sensor.getName(); } setTitle(sensorTitle); } } //Has to be done to access with XSharedPreferences. prefs = getSharedPreferences(Constants.PREFS_FILE_NAME, MODE_WORLD_READABLE); helper = new IabHelper(this, getString(R.string.google_billing_public_key)); //Has the user purchased the Pro IAP? if (!ProUtil.isPro(this)) { helper.startSetup(new IabHelper.OnIabSetupFinishedListener() { @Override public void onIabSetupFinished(IabResult result) { if (!result.isSuccess()) { Log.d(TAG, "Unable to get up In-App Billing. Oh well."); ProUtil.setFreeloadStatus(SensorSettingsActivity.this, true); return; } helper.queryInventoryAsync(new IabHelper.QueryInventoryFinishedListener() { @Override public void onQueryInventoryFinished(IabResult result, Inventory inv) { if (result.isFailure()) { ProUtil.setProStatus(SensorSettingsActivity.this, false); return; } if (inv.hasPurchase(Constants.SKU_TASKER)) { ProUtil.setProStatus(SensorSettingsActivity.this, true); } else { ProUtil.setProStatus(SensorSettingsActivity.this, false); } } }); } }); } }
From source file:com.mrchandler.disableprox.ui.TaskerSensorSettingsActivity.java
@Override public void onSensorClicked(Sensor sensor) { TaskerSensorSettingsFragment fragment = TaskerSensorSettingsFragment.newInstance(sensor); getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, fragment, CURRENT_FRAGMENT) .commit();/* w w w .j a v a 2s . c o m*/ String sensorTitle = SensorUtil.getHumanStringType(sensor); if (sensorTitle == null) { sensorTitle = sensor.getName(); } setTitle(sensorTitle); currentFragment = fragment; if (drawer != null) { drawer.closeDrawer(GravityCompat.START); } if (currentFragment == null) { fab.hide(); } else { fab.show(); } }
From source file:com.mrchandler.disableprox.ui.SensorSettingsActivity.java
@Override public void onSensorClicked(Sensor sensor) { SensorSettingsFragment fragment = SensorSettingsFragment.newInstance(sensor); getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, fragment, CURRENT_FRAGMENT) .commit();//from w w w . j av a 2 s. co m String sensorTitle = SensorUtil.getHumanStringType(sensor); if (sensorTitle == null) { sensorTitle = sensor.getName(); } setTitle(sensorTitle); currentFragment = fragment; if (drawer != null) { drawer.closeDrawer(GravityCompat.START); } if (currentFragment == null) { fab.hide(); } else { fab.show(); } }
From source file:uk.ac.horizon.ubihelper.service.Service.java
@Override public void onCreate() { // One-time set-up... Log.d(TAG, "onCreate()"); // TODO/* ww w. ja v a 2 s . c o m*/ super.onCreate(); // handler for requests mHandler = new Handler(); // create taskbar notification int icon = R.drawable.service_notification_icon; CharSequence tickerText = getText(R.string.notification_start_message); long when = System.currentTimeMillis(); Notification notification = new Notification(icon, tickerText, when); Context context = this; CharSequence contentTitle = getText(R.string.notification_title); CharSequence contentText = getText(R.string.notification_description); Intent notificationIntent = new Intent(this, MainPreferences.class); PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0); notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent); startForeground(RUNNING_ID, notification); channelManager = new ChannelManager(peerChannelFactory); // sensors if (!isEmulator()) { Log.d(TAG, "Create sensor channels..."); SensorChannel magnetic = new SensorChannel("magnetic", this, Sensor.TYPE_MAGNETIC_FIELD); channelManager.addChannel(magnetic); SensorChannel accelerometer = new SensorChannel("accelerometer", this, Sensor.TYPE_ACCELEROMETER); channelManager.addChannel(accelerometer); SensorChannel gyro = new SensorChannel("gyro", this, Sensor.TYPE_GYROSCOPE); channelManager.addChannel(gyro); SensorChannel light = new SensorChannel("light", this, Sensor.TYPE_LIGHT); channelManager.addChannel(light); SensorChannel pressure = new SensorChannel("pressure", this, Sensor.TYPE_PRESSURE); channelManager.addChannel(pressure); SensorChannel proximity = new SensorChannel("proximity", this, Sensor.TYPE_PROXIMITY); channelManager.addChannel(proximity); SensorChannel temperature = new SensorChannel("temperature", this, Sensor.TYPE_TEMPERATURE); channelManager.addChannel(temperature); try { Field f = Sensor.class.getField("TYPE_AMBIENT_TEMPERATURE"); SensorChannel sc = new SensorChannel("ambientTemperature", this, f.getInt(null)); channelManager.addChannel(sc); } catch (Exception e) { Log.d(TAG, "Could not get field Sensor.TYPE_AMBIENT_TEMPERATURE"); } try { Field f = Sensor.class.getField("TYPE_RELATIVE_HUMIDITY"); SensorChannel sc = new SensorChannel("relativeHumidity", this, f.getInt(null)); channelManager.addChannel(sc); } catch (Exception e) { Log.d(TAG, "Could not get field Sensor.TYPE_AMBIENT_TEMPERATURE"); } // all sensors by full name SensorManager sensorManager = (SensorManager) getSystemService(SENSOR_SERVICE); if (sensorManager != null) { List<Sensor> sensors = sensorManager.getSensorList(Sensor.TYPE_ALL); for (Sensor sensor : sensors) { SensorChannel sc = new SensorChannel("sensor." + sensor.getName(), this, sensor); channelManager.addChannel(sc); } } BluetoothDiscoveryChannel btchannel = new BluetoothDiscoveryChannel(this, mHandler, "bluetooth"); channelManager.addChannel(btchannel); WifiScannerChannel wifichannel = new WifiScannerChannel(this, mHandler, "wifi"); channelManager.addChannel(wifichannel); GpsStatusChannel gpsstatus = new GpsStatusChannel("gpsstatus", this); channelManager.addChannel(gpsstatus); CellLocationChannel cellchannel = new CellLocationChannel(mHandler, this, "cell.location", false); channelManager.addChannel(cellchannel); CellLocationChannel cellchannel2 = new CellLocationChannel(mHandler, this, "cell.neighbors", true); channelManager.addChannel(cellchannel2); CellStrengthChannel cellchannel3 = new CellStrengthChannel(this, "cell.strength"); channelManager.addChannel(cellchannel3); } channelManager.addChannel(new TimeChannel(mHandler, "time")); List<String> locationProviders = LocationChannel.getAllProviders(this); for (String provider : locationProviders) { LocationChannel locchannel = new LocationChannel("location." + provider, this, provider); channelManager.addChannel(locchannel); } channelManager.addChannel(new MicChannel(mHandler, "mic")); Log.d(TAG, "Create http server..."); // http server httpPort = getPort(); httpListener = new HttpListener(this, httpPort); httpListener.start(); // peer communication peerManager = new PeerManager(this); int serverPort = peerManager.getServerPort(); channelManager.addChannel(new EnabledPeersChannel(this, peerManager, "peers")); // wifi discovery wifiDiscoveryManager = new WifiDiscoveryManager(this); wifiDiscoverable = getWifiDiscoverable(); wifiDiscoveryManager.setServerPort(serverPort); wifiDiscoveryManager.setEnabled(wifiDiscoverable); bluetooth = BluetoothAdapter.getDefaultAdapter(); if (bluetooth != null) btmac = bluetooth.getAddress(); telephony = (TelephonyManager) getSystemService(TELEPHONY_SERVICE); if (telephony != null) imei = telephony.getDeviceId(); logManager = new LogManager(this, channelManager); logManager.checkPreferences(); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); prefs.registerOnSharedPreferenceChangeListener(onRunChangeListener); Log.d(TAG, "onCreate() finished"); }
From source file:it.durip_app.SensorPlot.java
/** Called when the activity is first created. */ @Override/*ww w . ja v a 2 s .c o m*/ public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_sensors); managerSensor = (SensorManager) getApplicationContext().getSystemService(Context.SENSOR_SERVICE); textCharge = (TextView) findViewById(R.id.textvalueConsumption); // Create the adapter that will return a fragment for each of the three primary sections // of the app. mAppSectionsPagerAdapter = new AppSectionsPagerAdapter(getSupportFragmentManager()); // Set up the action bar. final ActionBar actionBar = getActionBar(); // Specify that the Home/Up button should not be enabled, since there is no hierarchical // parent. actionBar.setHomeButtonEnabled(true); // Specify that we will be displaying tabs in the action bar. actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); // Set up the ViewPager, attaching the adapter and setting up a listener for when the // user swipes between sections. mViewPager = (ViewPager) findViewById(R.id.pager); mViewPager.setAdapter(mAppSectionsPagerAdapter); mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() { @Override public void onPageSelected(int position) { // When swiping between different app sections, select the corresponding tab. // We can also use ActionBar.Tab#select() to do this if we have a reference to the // Tab. actionBar.setSelectedNavigationItem(position); } }); managerSensor = (SensorManager) this.getSystemService(SENSOR_SERVICE); List<Sensor> list = managerSensor.getSensorList(Sensor.TYPE_ALL); for (Sensor sensor : list) { System.out.println("NAME " + sensor.getName()); } // For each of the sections in the app, add a tab to the action bar. for (int ii = 1; ii <= mAppSectionsPagerAdapter.getCount(); ii++) { // Create a tab with text corresponding to the page title defined by the adapter. // Also specify this Activity object, which implements the TabListener interface, as the // listener for when this tab is selected. actionBar.addTab( actionBar.newTab().setText(mAppSectionsPagerAdapter.getPageTitle(ii)).setTabListener(this)); } // Show the Up button in the action bar. // System.out.println("OnCreate \n"); }
From source file:com.mrchandler.disableprox.ui.TaskerSensorSettingsActivity.java
@Override protected void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); BundleScrubber.scrub(getIntent());/*from w w w .ja va2 s . com*/ final Bundle localeBundle = getIntent().getBundleExtra(com.twofortyfouram.locale.Intent.EXTRA_BUNDLE); BundleScrubber.scrub(localeBundle); if (null == savedInstanceState) { if (PluginBundleManager.isBundleValid(localeBundle)) { String sensorStatusKey = localeBundle.getString(PluginBundleManager.BUNDLE_EXTRA_SENSOR_STATUS_KEY); int sensorStatusValue = localeBundle.getInt(PluginBundleManager.BUNDLE_EXTRA_SENSOR_STATUS_VALUE); float[] sensorMockValues = localeBundle .getFloatArray(PluginBundleManager.BUNDLE_EXTRA_SENSOR_MOCK_VALUES_VALUES); Sensor sensor = SensorUtil.getSensorFromUniqueSensorKey(this, sensorStatusKey); TaskerSensorSettingsFragment fragment = TaskerSensorSettingsFragment.newInstance(sensorStatusKey, sensorStatusValue, sensorMockValues); getSupportFragmentManager().beginTransaction() .replace(R.id.fragment_container, fragment, CURRENT_FRAGMENT).commit(); String sensorTitle = SensorUtil.getHumanStringType(sensor); if (sensorTitle == null) { sensorTitle = sensor.getName(); //Probably won't really return null but who knows... if (sensorTitle == null) { sensorTitle = "Unknown Sensor"; } } setTitle(sensorTitle); currentFragment = fragment; if (drawer != null) { drawer.closeDrawer(GravityCompat.START); } if (currentFragment == null) { fab.hide(); } else { fab.show(); } } } initInAppBilling(); fab.setImageResource(R.drawable.ic_check_white_24dp); }
From source file:org.openchaos.android.fooping.service.PingService.java
@Override protected void onHandleIntent(Intent intent) { String clientID = prefs.getString("ClientID", "unknown"); long ts = System.currentTimeMillis(); Log.d(tag, "onHandleIntent()"); // always send ping if (true) {/*from w w w . ja va2 s . c om*/ try { JSONObject json = new JSONObject(); json.put("client", clientID); json.put("type", "ping"); json.put("ts", ts); sendMessage(json); } catch (Exception e) { Log.e(tag, e.toString()); e.printStackTrace(); } } // http://developer.android.com/training/monitoring-device-state/battery-monitoring.html // http://developer.android.com/reference/android/os/BatteryManager.html if (prefs.getBoolean("UseBattery", false)) { try { JSONObject json = new JSONObject(); json.put("client", clientID); json.put("type", "battery"); json.put("ts", ts); Intent batteryStatus = registerReceiver(null, new IntentFilter(Intent.ACTION_BATTERY_CHANGED)); if (batteryStatus != null) { JSONObject bat_data = new JSONObject(); int level = batteryStatus.getIntExtra(BatteryManager.EXTRA_LEVEL, -1); int scale = batteryStatus.getIntExtra(BatteryManager.EXTRA_SCALE, -1); if (level >= 0 && scale > 0) { bat_data.put("pct", roundValue(((double) level / (double) scale) * 100, 2)); } else { Log.w(tag, "Battery level unknown"); bat_data.put("pct", -1); } bat_data.put("health", batteryStatus.getIntExtra(BatteryManager.EXTRA_HEALTH, -1)); bat_data.put("status", batteryStatus.getIntExtra(BatteryManager.EXTRA_STATUS, -1)); bat_data.put("plug", batteryStatus.getIntExtra(BatteryManager.EXTRA_PLUGGED, -1)); bat_data.put("volt", batteryStatus.getIntExtra(BatteryManager.EXTRA_VOLTAGE, -1)); bat_data.put("temp", batteryStatus.getIntExtra(BatteryManager.EXTRA_TEMPERATURE, -1)); bat_data.put("tech", batteryStatus.getStringExtra(BatteryManager.EXTRA_TECHNOLOGY)); // bat_data.put("present", batteryStatus.getBooleanExtra(BatteryManager.EXTRA_PRESENT, false)); json.put("battery", bat_data); } sendMessage(json); } catch (Exception e) { Log.e(tag, e.toString()); e.printStackTrace(); } } // http://developer.android.com/guide/topics/location/strategies.html // http://developer.android.com/reference/android/location/LocationManager.html if (prefs.getBoolean("UseGPS", false)) { try { JSONObject json = new JSONObject(); json.put("client", clientID); json.put("type", "loc_gps"); json.put("ts", ts); if (lm == null) { lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE); } Location last_loc = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER); if (last_loc != null) { JSONObject loc_data = new JSONObject(); loc_data.put("ts", last_loc.getTime()); loc_data.put("lat", last_loc.getLatitude()); loc_data.put("lon", last_loc.getLongitude()); if (last_loc.hasAltitude()) loc_data.put("alt", roundValue(last_loc.getAltitude(), 4)); if (last_loc.hasAccuracy()) loc_data.put("acc", roundValue(last_loc.getAccuracy(), 4)); if (last_loc.hasSpeed()) loc_data.put("speed", roundValue(last_loc.getSpeed(), 4)); if (last_loc.hasBearing()) loc_data.put("bearing", roundValue(last_loc.getBearing(), 4)); json.put("loc_gps", loc_data); } sendMessage(json); } catch (Exception e) { Log.e(tag, e.toString()); e.printStackTrace(); } } if (prefs.getBoolean("UseNetwork", false)) { try { JSONObject json = new JSONObject(); json.put("client", clientID); json.put("type", "loc_net"); json.put("ts", ts); if (lm == null) { lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE); } Location last_loc = lm.getLastKnownLocation(LocationManager.NETWORK_PROVIDER); if (last_loc != null) { JSONObject loc_data = new JSONObject(); loc_data.put("ts", last_loc.getTime()); loc_data.put("lat", last_loc.getLatitude()); loc_data.put("lon", last_loc.getLongitude()); if (last_loc.hasAltitude()) loc_data.put("alt", roundValue(last_loc.getAltitude(), 4)); if (last_loc.hasAccuracy()) loc_data.put("acc", roundValue(last_loc.getAccuracy(), 4)); if (last_loc.hasSpeed()) loc_data.put("speed", roundValue(last_loc.getSpeed(), 4)); if (last_loc.hasBearing()) loc_data.put("bearing", roundValue(last_loc.getBearing(), 4)); json.put("loc_net", loc_data); } sendMessage(json); } catch (Exception e) { Log.e(tag, e.toString()); e.printStackTrace(); } } // http://developer.android.com/reference/android/net/wifi/WifiManager.html if (prefs.getBoolean("UseWIFI", false)) { try { JSONObject json = new JSONObject(); json.put("client", clientID); json.put("type", "wifi"); json.put("ts", ts); if (wm == null) { wm = (WifiManager) getSystemService(Context.WIFI_SERVICE); } List<ScanResult> wifiScan = wm.getScanResults(); if (wifiScan != null) { JSONArray wifi_list = new JSONArray(); for (ScanResult wifi : wifiScan) { JSONObject wifi_data = new JSONObject(); wifi_data.put("BSSID", wifi.BSSID); wifi_data.put("SSID", wifi.SSID); wifi_data.put("freq", wifi.frequency); wifi_data.put("level", wifi.level); // wifi_data.put("cap", wifi.capabilities); // wifi_data.put("ts", wifi.timestamp); wifi_list.put(wifi_data); } json.put("wifi", wifi_list); } sendMessage(json); } catch (Exception e) { Log.e(tag, e.toString()); e.printStackTrace(); } } // TODO: cannot poll sensors. register receiver to cache sensor data // http://developer.android.com/guide/topics/sensors/sensors_overview.html // http://developer.android.com/reference/android/hardware/SensorManager.html if (prefs.getBoolean("UseSensors", false)) { try { JSONObject json = new JSONObject(); json.put("client", clientID); json.put("type", "sensors"); json.put("ts", ts); if (sm == null) { sm = (SensorManager) getSystemService(Context.SENSOR_SERVICE); } List<Sensor> sensors = sm.getSensorList(Sensor.TYPE_ALL); if (sensors != null) { JSONArray sensor_list = new JSONArray(); for (Sensor sensor : sensors) { JSONObject sensor_info = new JSONObject(); sensor_info.put("name", sensor.getName()); sensor_info.put("type", sensor.getType()); sensor_info.put("vendor", sensor.getVendor()); sensor_info.put("version", sensor.getVersion()); sensor_info.put("power", roundValue(sensor.getPower(), 4)); sensor_info.put("resolution", roundValue(sensor.getResolution(), 4)); sensor_info.put("range", roundValue(sensor.getMaximumRange(), 4)); sensor_list.put(sensor_info); } json.put("sensors", sensor_list); } sendMessage(json); } catch (Exception e) { Log.e(tag, e.toString()); e.printStackTrace(); } } // http://developer.android.com/training/monitoring-device-state/connectivity-monitoring.html // http://developer.android.com/reference/android/net/ConnectivityManager.html if (prefs.getBoolean("UseConn", false)) { try { JSONObject json = new JSONObject(); json.put("client", clientID); json.put("type", "conn"); json.put("ts", ts); if (cm == null) { cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); } // TODO: add active/all preferences below UseConn if (prefs.getBoolean("UseConnActive", true)) { NetworkInfo net = cm.getActiveNetworkInfo(); if (net != null) { JSONObject net_data = new JSONObject(); net_data.put("type", net.getTypeName()); net_data.put("subtype", net.getSubtypeName()); net_data.put("connected", net.isConnected()); net_data.put("available", net.isAvailable()); net_data.put("roaming", net.isRoaming()); net_data.put("failover", net.isFailover()); if (net.getReason() != null) net_data.put("reason", net.getReason()); if (net.getExtraInfo() != null) net_data.put("extra", net.getExtraInfo()); json.put("conn_active", net_data); } } if (prefs.getBoolean("UseConnAll", false)) { NetworkInfo[] nets = cm.getAllNetworkInfo(); if (nets != null) { JSONArray net_list = new JSONArray(); for (NetworkInfo net : nets) { JSONObject net_data = new JSONObject(); net_data.put("type", net.getTypeName()); net_data.put("subtype", net.getSubtypeName()); net_data.put("connected", net.isConnected()); net_data.put("available", net.isAvailable()); net_data.put("roaming", net.isRoaming()); net_data.put("failover", net.isFailover()); if (net.getReason() != null) net_data.put("reason", net.getReason()); if (net.getExtraInfo() != null) net_data.put("extra", net.getExtraInfo()); net_list.put(net_data); } json.put("conn_all", net_list); } } sendMessage(json); } catch (Exception e) { Log.e(tag, e.toString()); e.printStackTrace(); } } if (!PingServiceReceiver.completeWakefulIntent(intent)) { Log.w(tag, "completeWakefulIntent() failed. no active wake lock?"); } }
From source file:com.cellbots.logger.LoggerActivity.java
/** * Prints all the sensors to LogCat.//from w w w .j av a 2 s . c o m */ private void printSensors() { List<Sensor> sensors = mSensorManager.getSensorList(Sensor.TYPE_ALL); for (int i = 0; i < sensors.size(); i++) { Sensor s = sensors.get(i); Log.d("DEBUG", s.getName()); } Log.d("DEBUG", "Also logging wifi. You're welcome."); }
From source file:com.cellbots.logger.LoggerActivity.java
private void initSensorLogFiles() { sensorLogFileWriters = new HashMap<String, BufferedWriter>(); String directoryName = application.getDataLoggerPath(); File directory = new File(directoryName); if (!directory.exists() && !directory.mkdirs()) { try {//from www .ja v a 2s . c o m throw new IOException("Path to file could not be created. " + directory.getAbsolutePath()); } catch (IOException e) { Log.e(TAG, "Directory could not be created. " + e.toString()); } } for (int i = 0; i < sensors.size(); i++) { Sensor s = sensors.get(i); String sensorFilename = directoryName + s.getName().replaceAll(" ", "_") + "_" + application.getFilePathUniqueIdentifier() + ".txt"; File file = new File(sensorFilename); try { BufferedWriter writer = new BufferedWriter(new FileWriter(file)); sensorLogFileWriters.put(s.getName(), writer); } catch (IOException e) { e.printStackTrace(); } mSensorManager.registerListener(mSensorEventListener, s, SensorManager.SENSOR_DELAY_GAME); } // The battery is a special case since it is not a real sensor mBatteryTempWriter = createBufferedWriter("/BatteryTemp_", directoryName); mBatteryLevelWriter = createBufferedWriter("/BatteryLevel_", directoryName); mBatteryVoltageWriter = createBufferedWriter("/BatteryVoltage_", directoryName); // GPS is another special case since it is not a real sensor mGpsLocationWriter = createBufferedWriter("/GpsLocation_", directoryName); mGpsStatusWriter = createBufferedWriter("/GpsStatus_", directoryName); mGpsNmeaWriter = createBufferedWriter("/GpsNmea_", directoryName); // Wifi is another special case mWifiWriter = createBufferedWriter("/Wifi_", directoryName); }