Android Hacks - Hack27 ~ Hack29

  • Published on
    24-May-2015

  • View
    649

  • Download
    1

Embed Size (px)

DESCRIPTION

Android Hacks & ()http://www.oreilly.co.jp/books/9784873114569/

Transcript

  • 1. ANDROID HACKS #21,27,28,29 tsuruoka 09/19/11

2.

    • Android Hacks
    • http://www.oreilly.co.jp/books/9784873114569/

09/19/11 3.

  • Hack27
  • Hack28
    • /
  • Hack29

09/19/11 4. Hack27.

  • LocationProvider
  • LoctionProvider
    • GPS_PROVIDER
    • NETWORK_PROVIDER
  • GPS NETWORK (Hack28)

09/19/11 5. Hack27.LocationManager

  • implements LocationLisener
  • onCreate
  • // LocationManager
  • mLocationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
  • // LocationListener
  • mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this);
  • public void onLocationChanged(Location location) {
  • // location
  • location.getLatitude()
  • get
  • }

09/19/11 6. Hack27.LocationManager

  • implements LocationListener
  • Public Methods
  • abstract void onLocationChanged(Location location)
  • Called when the location has changed.
  • abstract void onProviderDisabled(String provider)
  • Called when the provider is disabled by the user.
  • abstract void onProviderEnabled(String provider)
  • Called when the provider is enabled by the user.
  • abstract void onStatusChanged(String provider, int status, Bundle extras)
  • Called when the provider status changes.

09/19/11 7. Hack28.

  • LocationManager
    • Criteria LocationProvider
    • or

09/19/11 8. Hack28. LocationManager

  • (Criteria)
    • setPowerRequirement
    • setAccuracy
      • GingerBread
    • setAltitudeRequirement
    • setSpeedRequired
    • setBearingRequired
    • setCostAllowed
      • GPS

09/19/11 9. Hack28. LocationManager

    • Criteria
    • // LocationManager
    • LocationManager lm = (LocationManager) getSystemService(LOCATION_SERVICE);
    • Criteria criteria = new Criteria();
    • criteria.setPowerRequirement(Criteria.POWER_LOW);
    • criteria.setAccuracy(Criteria.ACCURACY_FINE);
    • criteria.setAltitudeRequired(false);
    • criteria.setSpeedRequired(false);
    • criteria.setBearingRequired(false);
    • criteria.setCostAllowed(false);
    • String bestProvider = lm.getBestProvider(criteria, true);
    • ((TextView) findViewById(R.id.main_tv_bestprovider)).setText(" = "
    • + bestProvider);

09/19/11 10. Hack29

  • Android
  • TYPE_GYROSCOPE
  • TYPE_LIGHT
  • TYPE_MAGNETICFIELD
  • TYPE_ORIENTATION
  • TYPE_PRESSURE
  • TYPE_PROXIMITY
  • TYPE_TEMPATURE

11. Hack29

    • ([0],[1],[2])
      • X Y Z

12. Hack29

  • Activity implementsSensorEventListener
  • onCreate
  • //
  • sensorManager = (SensorManager)getSystemService( SENSOR_SERVICE );
  • onResume
  • //
  • List sensors = sensorManager.getSensorList(Sensor. TYPE_ACCELEROMETER );
  • if (sensors.size() > 0) {
  • sensorManager.registerListener(this, sensors. get (0), SensorManager. SENSOR_DELAY_FASTEST );
  • }
  • On Pause
  • //
  • sensorManager.unregisterListener(this);
  • Acitity /