Android Application Components, Sensors Mobile Computing Design and Implementation Peter Börjesson
Application Sandbox Android System & Device Data Contacts, Messages, SD Card, Camera, Bluetooth, etc. Android Manifest Android Manifest Application A Application B Application ID Dalvik VM Process Application ID Dalvik VM Process
Application Components Activities Services Activated by Intents Broadcast Receivers Content Providers
Intents - Anatomy ComponentName Action Data Category Type Extras
Intents - ComponentName Class Name com.example.project.details.myactivitiy. Package Name (from Android Manifest) com.example.project Do not set this attribute unless you are absolutely sure about which component that should handle the intent. The system will decide for you. If this attribute is set, all other intent attributes become optional
Intents - Action and Data Action ACTION_VIEW, ACTION_DIAL, ACTION_EDIT Data (expressed as Uri) content://contacts/people/1 tel:123 Action and Data are the primary pieces of information in an intent.
Intents Category and Type Category CATEGORY_LAUNCHER CATEGORY_DEFAULT CATEGORY_BROWSABLE Type (MIME, usually inferred by the data itself) image/jpeg audio/mpeg text/html
Intents Extras Bundle intent.putextras(bundle); Bundle bundle = intent.getextras(); putextra & getextra intent.putextra( mytag1, 12); Intent.putExtra( mytag2, Peter ); int i = intent.getintextra( mytag1, -1); String s = intent.getstringextra( mytag );
Implicit intents Android System & Device Data Contacts, Messages, SD Card, Camera, Bluetooth, etc. Intent An application can have many entry points Camera Application Email Application Inbox Activity Read Mail Actitivity Compose Mail Activity
Implicit intents - Example Send SMS Send E-mail
Services Android System & Device Data Contacts, Messages, SD Card, Camera, Bluetooth, etc. Intent Play Music Service Music Player A service can run in the background, independent of activities
Services - Lifecycle
Services - Example Start Service Stop Service Android Manifest
Broadcast Receivers Android System & Device Data Contacts, Messages, SD Card, Camera, Bluetooth, etc. Intent Many Broadcasts originate from the system but can also be initiated by an application Application A Application A Application A
Broadcast Receivers - Example
Content Providers Android System & Device Data Contacts, Messages, SD Card, Camera, Bluetooth, etc. Contacts Browser CallLog MediaStore Settings Query content://contacts/people/2 Email Application Both the Android System and other applications can provide content.
Sensors
Sensors SensorManager Create an instance of the sensor service. Manage sensors sensor eventlisteners. Sensor Create an instance of a specific Senor SensorEvent Used by the system to provide information about a sensorevent SensorEventListener Interface to receive notification of sensor value and sensor accuracy changes
Sensors - SensorEventListener OnAccuracyChanged(Sensor sensor, int accuracy) Low, Medium, High, Unreliable OnSensorChanged(SensorEvent event) accuracy, sensor, timestamp, values
Sensors
Sensors Tips Don t test on the emulator Don't block the onsensorchanged() method Filter or reduce data outside of this method Avoid using deprecated methods or sensor types Verify sensors before you use them Choose sensor delays carefully Unregister sensor when not needed anymore