Networks External Storage "> Networks External Storage ">

Presentation is loading. Please wait.

Presentation is loading. Please wait.

Location Service and Sensors

Similar presentations


Presentation on theme: "Location Service and Sensors"— Presentation transcript:

1 Location Service and Sensors
Permissions Location Service Sensors

2 Permissions (1) AndroidManifest.xml to define permissions
Location Services <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/> <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/> <uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION"/> Networks <uses-permission android:name="android.permission.INTERNET"/> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> External Storage <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE">

3 Permissions (2) Camer and Audio Other permissions
<uses-permission android:name="android.permission.CAMERA" /> <uses-permission android:name="android.permission.RECORD_AUDIO"/> Other permissions ml

4 Location Service(1) Android provides Wifi and GPS Location Service
Location Service is a System Service LocationManager LM; Location lo; LM=(LocationManager) (this.getSystemService(Context.LOCATION_SERVICE)); if (LM.isProviderEnabled(LocationManager.GPS_PROVIDER)) lo = LM.getLastKnownLocation(LocationManager.GPS_PROVIDER); else if ( LM.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) lo = LM.getLastKnownLocation(LocationManager.NETWORK_PROVIDER); else lo=null;

5 Location Service(2) Using Location Object to get Location detail double Latitude=0,Longitude=0,Accuracy=0; if (lo!=null) { Latitude=lo.getLatitude(); Longitude=lo.getLongitude(); Accuracy=lo.getAccuracy(); ptime.setText(" "+Latitude+" "+Longitude+" "+Accuracy); } else ptime.setText(" no location!");

6 Location Service(3) Using Listener to monitor Location data
LocationManger.requestLocationUpdates( LocationManager.GPS_PROVIDER, time, dist, LL); Methods of LocationListener public void onLocationChanged(Location lo){} public void onProviderDisabled(String provider){} public void onProviderEnabled(String provider){} public void onStatusChanged(String provider,int status, Bundle extras){}

7 Sensors(1) Sensor Services are System Services
SensorManager SM = (SensorManager) getSystemService(SENSOR_SERVICE); Register Sensor Event Listener List sensors = SM.getSensorList(Sensor.TYPE_ALL); int i;Sensor sn; for (i=0;i<sensors.size();i++) {sn=(Sensor) sensors.get(i); if (sn.getType()==Sensor.TYPE_ACCELEROMETER) { SM.registerListener(this, (Sensor) sensors.get(i), SensorManager.SENSOR_DELAY_GAME); //SENSOR_DELAY_NORMAL SENSOR_DELAY_GAME SENSOR_DELAY_FASTEST SENSOR_DELAY_UI SENSOR_DELAY_GAME }

8 Sensors(2) Methods of SensorEventListener
public void onAccuracyChanged(Sensor sensor, int accuracy) int mgValues=new int[3]; int acValues=new int[3]; public void onSensorChanged(SensorEvent event) { if (event.sensor.getType() == Sensor.TYPE_MAGNETIC_FIELD) mgValues = event.values; else if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) acValues = event.values; else return; }


Download ppt "Location Service and Sensors"

Similar presentations


Ads by Google