List of usage examples for android.hardware Sensor TYPE_ALL
int TYPE_ALL
To view the source code for android.hardware Sensor TYPE_ALL.
Click Source Link
From source file:com.nextgis.firereporter.SendReportActivity.java
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.report);//from w w w . j a va 2s .com //add fragment FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction(); frCompass = (CompassFragment) getSupportFragmentManager().findFragmentByTag("COMPASS"); if (frCompass == null) { frCompass = new CompassFragment(); fragmentTransaction.add(R.id.compass_fragment_container, frCompass, "COMPASS").commit(); } getSupportFragmentManager().executePendingTransactions(); getSupportActionBar().setHomeButtonEnabled(true); edLatitude = (EditText) findViewById(R.id.edLatitude); edLongitude = (EditText) findViewById(R.id.edLongitude); edAzimuth = (EditText) findViewById(R.id.edAzimuth); edDistance = (EditText) findViewById(R.id.edDistance); edComment = (EditText) findViewById(R.id.edComment); edDistance.setText("100"); mLocationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); if (mLocationManager != null) { for (String aProvider : mLocationManager.getProviders(false)) { if (aProvider.equals(LocationManager.GPS_PROVIDER)) { gpsAvailable = true; } } if (gpsAvailable) { Location location = mLocationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER); if (location != null) { float lat = (float) (location.getLatitude()); float lon = (float) (location.getLongitude()); edLatitude.setText(Float.toString(lat)); edLongitude.setText(Float.toString(lon)); } else { edLatitude.setText(getString(R.string.noLocation)); edLongitude.setText(getString(R.string.noLocation)); } mLocationListener = new LocationListener() { public void onStatusChanged(String provider, int status, Bundle extras) { switch (status) { case LocationProvider.OUT_OF_SERVICE: break; case LocationProvider.TEMPORARILY_UNAVAILABLE: break; case LocationProvider.AVAILABLE: break; } } public void onProviderEnabled(String provider) { } public void onProviderDisabled(String provider) { } public void onLocationChanged(Location location) { float lat = (float) (location.getLatitude()); float lon = (float) (location.getLongitude()); edLatitude.setText(Float.toString(lat)); edLongitude.setText(Float.toString(lon)); // FIXME: also need to calculate declination? } }; // location listener } else { edLatitude.setText(getString(R.string.noGPS)); edLongitude.setText(getString(R.string.noGPS)); edLatitude.setEnabled(false); edLongitude.setEnabled(false); } } mSensorManager = (SensorManager) getSystemService(SENSOR_SERVICE); boolean accelerometerAvailable = false; boolean magnetometerAvailable = false; for (Sensor aSensor : mSensorManager.getSensorList(Sensor.TYPE_ALL)) { if (aSensor.getType() == Sensor.TYPE_ACCELEROMETER) { accelerometerAvailable = true; } else if (aSensor.getType() == Sensor.TYPE_MAGNETIC_FIELD) { magnetometerAvailable = true; } } compassAvailable = accelerometerAvailable && magnetometerAvailable; if (compassAvailable) { //frCompass = (CompassFragment) getSupportFragmentManager().findFragmentByTag("COMPASS"); if (frCompass != null) { frCompass.SetAzimuthCtrl(edAzimuth); } } else { edAzimuth.setText(getString(R.string.noCompass)); edAzimuth.setEnabled(false); } }
From source file:com.wso2.mobile.mdm.api.DeviceInfo.java
/** *Returns all the sensors available on the device as a List *///from w w w. ja va2 s . com public void getAllSensors() { SensorManager sm = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE); List<Sensor> list = sm.getSensorList(Sensor.TYPE_ALL); if (CommonUtilities.DEBUG_MODE_ENABLED) { for (Sensor s : list) { Log.d("SENSORS", s.getName()); } } }
From source file:uk.ac.horizon.ubihelper.service.Service.java
@Override public void onCreate() { // One-time set-up... Log.d(TAG, "onCreate()"); // TODO/*w w w . j ava2s . co 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: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 . j a va 2 s . co m*/ 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.davidmascharka.lips.MainActivity.java
@Override public void onResume() { super.onResume(); // Set building textview to the building the user has selected TextView buildingText = (TextView) findViewById(R.id.text_building); buildingText.setText("Building: " + building); // Set room size textview to the room size the user has selected TextView roomSizeText = (TextView) findViewById(R.id.text_room_size); roomSizeText.setText("Room size: " + roomWidth + " x " + roomLength); // Set grid options GridView grid = (GridView) findViewById(R.id.gridView); grid.setGridSize(roomWidth, roomLength); grid.setDisplayMap(displayMap);//from ww w. j av a2s .c om // Register to get sensor updates from all the available sensors sensorList = sensorManager.getSensorList(Sensor.TYPE_ALL); for (Sensor sensor : sensorList) { sensorManager.registerListener(this, sensor, SensorManager.SENSOR_DELAY_FASTEST); } // Enable wifi if it is not if (!wifiManager.isWifiEnabled()) { Toast.makeText(this, "WiFi not enabled. Enabling...", Toast.LENGTH_SHORT).show(); wifiManager.setWifiEnabled(true); } // Request location updates from gps and the network //@author Mahesh Gaya added permission if-statment if (ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED || ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_WIFI_STATE) != PackageManager.PERMISSION_GRANTED || ActivityCompat.checkSelfPermission(this, android.Manifest.permission.CHANGE_WIFI_STATE) != PackageManager.PERMISSION_GRANTED || ActivityCompat.checkSelfPermission(this, android.Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { Log.i(TAG, "Permissions have NOT been granted. Requesting permissions."); requestMyPermissions(); } else { Log.i(TAG, "Permissions have already been granted. Getting location from GPS and Network"); locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationListener); locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locationListener); } registerReceiver(receiver, new IntentFilter(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION)); }
From source file:de.da_sense.moses.client.abstraction.HardwareAbstraction.java
/** * This method reads the sensors currently chosen by the user * @return the actual Hardwareinfo// w w w. ja v a 2s . c om */ private HardwareInfo retrieveHardwareParameters() { // *** SENDING SET_HARDWARE_PARAMETERS REQUEST TO SERVER ***// LinkedList<Integer> sensors = new LinkedList<Integer>(); SensorManager s = (SensorManager) mContext.getSystemService(Context.SENSOR_SERVICE); for (Sensor sen : s.getSensorList(Sensor.TYPE_ALL)) { sensors.add(sen.getType()); } return new HardwareInfo(extractDeviceIdFromSharedPreferences(), extractDeviceNameFromSharedPreferences(), Build.MANUFACTURER, Build.MODEL, Build.VERSION.SDK_INT, sensors); }
From source file:com.example.android.wearable.runtimepermissions.MainWearActivity.java
@Override public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { String permissionResult = "Request code: " + requestCode + ", Permissions: " + permissions + ", Results: " + grantResults;// w w w .jav a 2s . c o m Log.d(TAG, "onRequestPermissionsResult(): " + permissionResult); if (requestCode == PERMISSION_REQUEST_READ_BODY_SENSORS) { if ((grantResults.length == 1) && (grantResults[0] == PackageManager.PERMISSION_GRANTED)) { mWearBodySensorsPermissionApproved = true; mWearBodySensorsPermissionButton .setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_permission_approved, 0, 0, 0); // To keep the sample simple, we are only displaying the number of sensors. SensorManager sensorManager = (SensorManager) getSystemService(SENSOR_SERVICE); List<Sensor> sensorList = sensorManager.getSensorList(Sensor.TYPE_ALL); int numberOfSensorsOnDevice = sensorList.size(); String sensorSummary = numberOfSensorsOnDevice + " sensors on this device!"; logToUi(sensorSummary); if (mPhoneRequestingWearSensorPermission) { // Resets so this isn't triggered every time permission is changed in app. mPhoneRequestingWearSensorPermission = false; // Send 'approved' message to remote phone since it started Activity. DataMap dataMap = new DataMap(); dataMap.putInt(Constants.KEY_COMM_TYPE, Constants.COMM_TYPE_RESPONSE_USER_APPROVED_PERMISSION); sendMessage(dataMap); } } else { mWearBodySensorsPermissionApproved = false; mWearBodySensorsPermissionButton .setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_permission_denied, 0, 0, 0); if (mPhoneRequestingWearSensorPermission) { // Resets so this isn't triggered every time permission is changed in app. mPhoneRequestingWearSensorPermission = false; // Send 'denied' message to remote phone since it started Activity. DataMap dataMap = new DataMap(); dataMap.putInt(Constants.KEY_COMM_TYPE, Constants.COMM_TYPE_RESPONSE_USER_DENIED_PERMISSION); sendMessage(dataMap); } } } }
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();/*from w ww . java2 s . c o m*/ 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.landenlabs.all_devtool.SystemFragment.java
public void updateList() { // Time today = new Time(Time.getCurrentTimezone()); // today.setToNow(); // today.format(" %H:%M:%S") Date dt = new Date(); m_titleTime.setText(m_timeFormat.format(dt)); boolean expandAll = m_list.isEmpty(); m_list.clear();//from w ww .j a v a 2 s . co m // Swap colors int color = m_rowColor1; m_rowColor1 = m_rowColor2; m_rowColor2 = color; ActivityManager actMgr = (ActivityManager) getActivity().getSystemService(Context.ACTIVITY_SERVICE); try { String androidIDStr = Settings.Secure.getString(getContext().getContentResolver(), Settings.Secure.ANDROID_ID); addBuild("Android ID", androidIDStr); try { AdvertisingIdClient.Info adInfo = AdvertisingIdClient.getAdvertisingIdInfo(getContext()); final String adIdStr = adInfo.getId(); final boolean isLAT = adInfo.isLimitAdTrackingEnabled(); addBuild("Ad ID", adIdStr); } catch (IOException e) { // Unrecoverable error connecting to Google Play services (e.g., // the old version of the service doesn't support getting AdvertisingId). } catch (GooglePlayServicesNotAvailableException e) { // Google Play services is not available entirely. } /* try { InstanceID instanceID = InstanceID.getInstance(getContext()); if (instanceID != null) { // Requires a Google Developer project ID. String authorizedEntity = "<need to make this on google developer site>"; instanceID.getToken(authorizedEntity, GoogleCloudMessaging.INSTANCE_ID_SCOPE, null); addBuild("Instance ID", instanceID.getId()); } } catch (Exception ex) { } */ ConfigurationInfo info = actMgr.getDeviceConfigurationInfo(); addBuild("OpenGL", info.getGlEsVersion()); } catch (Exception ex) { m_log.e(ex.getMessage()); } try { long heapSize = Debug.getNativeHeapSize(); // long maxHeap = Runtime.getRuntime().maxMemory(); // ConfigurationInfo cfgInfo = actMgr.getDeviceConfigurationInfo(); int largHeapMb = actMgr.getLargeMemoryClass(); int heapMb = actMgr.getMemoryClass(); MemoryInfo memInfo = new MemoryInfo(); actMgr.getMemoryInfo(memInfo); final String sFmtMB = "%.2f MB"; Map<String, String> listStr = new TreeMap<String, String>(); listStr.put("Mem Available (now)", String.format(sFmtMB, (double) memInfo.availMem / MB)); listStr.put("Mem LowWhenOnlyAvail", String.format(sFmtMB, (double) memInfo.threshold / MB)); if (Build.VERSION.SDK_INT >= 16) { listStr.put("Mem Installed", String.format(sFmtMB, (double) memInfo.totalMem / MB)); } listStr.put("Heap (this app)", String.format(sFmtMB, (double) heapSize / MB)); listStr.put("HeapMax (default)", String.format(sFmtMB, (double) heapMb)); listStr.put("HeapMax (large)", String.format(sFmtMB, (double) largHeapMb)); addBuild("Memory...", listStr); } catch (Exception ex) { m_log.e(ex.getMessage()); } try { List<ProcessErrorStateInfo> procErrList = actMgr.getProcessesInErrorState(); int errCnt = (procErrList == null ? 0 : procErrList.size()); procErrList = null; // List<RunningAppProcessInfo> procList = actMgr.getRunningAppProcesses(); int procCnt = actMgr.getRunningAppProcesses().size(); int srvCnt = actMgr.getRunningServices(100).size(); Map<String, String> listStr = new TreeMap<String, String>(); listStr.put("#Processes", String.valueOf(procCnt)); listStr.put("#Proc With Err", String.valueOf(errCnt)); listStr.put("#Services", String.valueOf(srvCnt)); // Requires special permission // int taskCnt = actMgr.getRunningTasks(100).size(); // listStr.put("#Tasks", String.valueOf(taskCnt)); addBuild("Processes...", listStr); } catch (Exception ex) { m_log.e("System-Processes %s", ex.getMessage()); } try { Map<String, String> listStr = new LinkedHashMap<String, String>(); listStr.put("LargeIconDensity", String.valueOf(actMgr.getLauncherLargeIconDensity())); listStr.put("LargeIconSize", String.valueOf(actMgr.getLauncherLargeIconSize())); putIf(listStr, "isRunningInTestHarness", "Yes", ActivityManager.isRunningInTestHarness()); putIf(listStr, "isUserAMonkey", "Yes", ActivityManager.isUserAMonkey()); addBuild("Misc...", listStr); } catch (Exception ex) { m_log.e("System-Misc %s", ex.getMessage()); } // --------------- Locale / Timezone ------------- try { Locale ourLocale = Locale.getDefault(); Date m_date = new Date(); TimeZone tz = TimeZone.getDefault(); Map<String, String> localeListStr = new LinkedHashMap<String, String>(); localeListStr.put("Locale Name", ourLocale.getDisplayName()); localeListStr.put(" Variant", ourLocale.getVariant()); localeListStr.put(" Country", ourLocale.getCountry()); localeListStr.put(" Country ISO", ourLocale.getISO3Country()); localeListStr.put(" Language", ourLocale.getLanguage()); localeListStr.put(" Language ISO", ourLocale.getISO3Language()); localeListStr.put(" Language Dsp", ourLocale.getDisplayLanguage()); localeListStr.put("TimeZoneID", tz.getID()); localeListStr.put(" DayLightSavings", tz.useDaylightTime() ? "Yes" : "No"); localeListStr.put(" In DLS", tz.inDaylightTime(m_date) ? "Yes" : "No"); localeListStr.put(" Short Name", tz.getDisplayName(false, TimeZone.SHORT, ourLocale)); localeListStr.put(" Long Name", tz.getDisplayName(false, TimeZone.LONG, ourLocale)); addBuild("Locale TZ...", localeListStr); } catch (Exception ex) { m_log.e("Locale/TZ %s", ex.getMessage()); } // --------------- Location Services ------------- try { Map<String, String> listStr = new LinkedHashMap<String, String>(); final LocationManager locMgr = (LocationManager) getActivity() .getSystemService(Context.LOCATION_SERVICE); GpsStatus gpsStatus = locMgr.getGpsStatus(null); if (gpsStatus != null) { listStr.put("Sec ToGetGPS", String.valueOf(gpsStatus.getTimeToFirstFix())); Iterable<GpsSatellite> satellites = gpsStatus.getSatellites(); Iterator<GpsSatellite> sat = satellites.iterator(); while (sat.hasNext()) { GpsSatellite satellite = sat.next(); putIf(listStr, String.format("Azm:%.0f, Elev:%.0f", satellite.getAzimuth(), satellite.getElevation()), String.format("%.2f Snr", satellite.getSnr()), satellite.usedInFix()); } } Location location = null; if (ActivityCompat.checkSelfPermission(getContext(), Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED || ActivityCompat.checkSelfPermission(getContext(), Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED) { location = locMgr.getLastKnownLocation(LocationManager.GPS_PROVIDER); if (null == location) location = locMgr.getLastKnownLocation(LocationManager.NETWORK_PROVIDER); if (null == location) location = locMgr.getLastKnownLocation(LocationManager.PASSIVE_PROVIDER); } if (null != location) { listStr.put(location.getProvider() + " lat,lng", String.format("%.3f, %.3f", location.getLatitude(), location.getLongitude())); } if (listStr.size() != 0) { List<String> gpsProviders = locMgr.getAllProviders(); int idx = 1; for (String providerName : gpsProviders) { LocationProvider provider = locMgr.getProvider(providerName); if (null != provider) { listStr.put(providerName, (locMgr.isProviderEnabled(providerName) ? "On " : "Off ") + String.format("Accuracy:%d Pwr:%d", provider.getAccuracy(), provider.getPowerRequirement())); } } addBuild("GPS...", listStr); } else addBuild("GPS", "Off"); } catch (Exception ex) { m_log.e(ex.getMessage()); } // --------------- Application Info ------------- ApplicationInfo appInfo = getActivity().getApplicationInfo(); if (null != appInfo) { Map<String, String> appList = new LinkedHashMap<String, String>(); try { appList.put("ProcName", appInfo.processName); appList.put("PkgName", appInfo.packageName); appList.put("DataDir", appInfo.dataDir); appList.put("SrcDir", appInfo.sourceDir); // appList.put("PkgResDir", getActivity().getPackageResourcePath()); // appList.put("PkgCodeDir", getActivity().getPackageCodePath()); String[] dbList = getActivity().databaseList(); if (dbList != null && dbList.length != 0) appList.put("DataBase", dbList[0]); // getActivity().getComponentName(). } catch (Exception ex) { } addBuild("AppInfo...", appList); } // --------------- Account Services ------------- final AccountManager accMgr = (AccountManager) getActivity().getSystemService(Context.ACCOUNT_SERVICE); if (null != accMgr) { Map<String, String> strList = new LinkedHashMap<String, String>(); try { for (Account account : accMgr.getAccounts()) { strList.put(account.name, account.type); } } catch (Exception ex) { m_log.e(ex.getMessage()); } addBuild("Accounts...", strList); } // --------------- Package Features ------------- PackageManager pm = getActivity().getPackageManager(); FeatureInfo[] features = pm.getSystemAvailableFeatures(); if (features != null) { Map<String, String> strList = new LinkedHashMap<String, String>(); for (FeatureInfo featureInfo : features) { strList.put(featureInfo.name, ""); } addBuild("Features...", strList); } // --------------- Sensor Services ------------- final SensorManager senMgr = (SensorManager) getActivity().getSystemService(Context.SENSOR_SERVICE); if (null != senMgr) { Map<String, String> strList = new LinkedHashMap<String, String>(); // Sensor accelerometer = senMgr.getDefaultSensor(Sensor.TYPE_ACCELEROMETER); // senMgr.registerListener(foo, accelerometer, SensorManager.SENSOR_DELAY_NORMAL); List<Sensor> listSensor = senMgr.getSensorList(Sensor.TYPE_ALL); try { for (Sensor sensor : listSensor) { strList.put(sensor.getName(), sensor.getVendor()); } } catch (Exception ex) { m_log.e(ex.getMessage()); } addBuild("Sensors...", strList); } try { if (Build.VERSION.SDK_INT >= 17) { final UserManager userMgr = (UserManager) getActivity().getSystemService(Context.USER_SERVICE); if (null != userMgr) { try { addBuild("UserName", userMgr.getUserName()); } catch (Exception ex) { m_log.e(ex.getMessage()); } } } } catch (Exception ex) { } try { Map<String, String> strList = new LinkedHashMap<String, String>(); int screenTimeout = Settings.System.getInt(getActivity().getContentResolver(), Settings.System.SCREEN_OFF_TIMEOUT); strList.put("ScreenTimeOut", String.valueOf(screenTimeout / 1000)); int rotate = Settings.System.getInt(getActivity().getContentResolver(), Settings.System.ACCELEROMETER_ROTATION); strList.put("RotateEnabled", String.valueOf(rotate)); if (Build.VERSION.SDK_INT >= 17) { // Global added in API 17 int adb = Settings.Global.getInt(getActivity().getContentResolver(), Settings.Global.ADB_ENABLED); strList.put("AdbEnabled", String.valueOf(adb)); } addBuild("Settings...", strList); } catch (Exception ex) { } if (expandAll) { // updateList(); int count = m_list.size(); for (int position = 0; position < count; position++) m_listView.expandGroup(position); } m_adapter.notifyDataSetChanged(); }
From source file:com.cellbots.logger.LoggerActivity.java
private void setupSensors() { // initSensorUi(); mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE); sensors = mSensorManager.getSensorList(Sensor.TYPE_ALL); initSensorLogFiles();/*from w w w .j av a2s. c om*/ // initBattery(); // *Note* This function deals with UI, not actual // readings. registerBattery(); // This is the actual function that deals with // receivers. initGps(); initWifi(); printSensors(); }