Networks Download presentation Presentation is loading. Please wait.
1
Location Service and Sensors
2
Permissions (1) AndroidManifest.xml to define permissions
3
Permissions (2) Camer and Audio Other permissions
4
Location Service(1) Android provides Wifi and GPS Location Service
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
7
Sensors(1) Sensor Services are System Services
8
Sensors(2) Methods of SensorEventListener
Similar presentations © 2025 SlidePlayer.com. Inc. Log in
Similar presentations
Presentation on theme: "Location Service and Sensors"— Presentation transcript:
Permissions Location Service Sensors
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">
<uses-permission android:name="android.permission.CAMERA" /> <uses-permission android:name="android.permission.RECORD_AUDIO"/> Other permissions ml
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;
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){}
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 }
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; }
Similar presentations
All rights reserved.