At the top of the diagram, manager services are started at boot time, always running, and available for access by apps inside the blue box: Location, Sensor, WiFi, Alarm, Telephony, Bluetooth, etc..
Apps inside the blue box are arranged by related functionality (file system and storage).
??? All service implementations inherit from class IntentService.
To get a system service, a getSystemService() is called to return a Manager object which is then used to access the service. These are pictured in white at the top of the figure.
Most system services work on some sort of publish/subscribe mechanism. In other words, you generally register your app for notifications from that service and provide your own callbacks methods that the service will invoke when an event happens. To do this in Java, create a Listener that implements an interface so that the service can call the callback methods.
Feature | Phone Gap? | Permission |
---|---|---|
Accelerometer | Y | - |
Camera | Y | CAMERA |
Capture a/v/i | Y | - |
Compass | Y | ACCESS_COARSE_LOCATION ACCESS_FINE_LOCATION ACCESS_LOCATION_EXTRA_COMMANDS |
Connection | Y | INTERNET |
Contacts | Y | GET_ACCOUNTS READ_CONTACTS WRITE_CONTACTS |
Device | Y | READ_PHONE_STATE |
Events | Y | ACCESS_NETWORK_STATE |
File | Y | - |
Geolocation | Y | - |
Media (Audio) | Y | RECORD_AUDIO MODIFY_AUDIO_SETTINGS |
Notification (Sound) | Y | RECEIVE_SMS BROADCAST_STICKY |
Notification (Vibration) | Y | VIBRATE |
Storage | Y | WRITE_EXTERNAL_STORAGE |
Bluetooth | N | - |
Wi-Fi | ? | - |
A service runs in the background, without a UI.
to play music or update a weather icon.
Networking tutorial by Lars Vogel
Barnes and Noble Nook
Developer Program
Qualcomm Snapdragon chip
Developer Program
Structural Testing is based on an analysis of the internal structure of the component or system.
Structural Testing is based on an analysis of the internal structure of the component or system.
To call phone number 8005551212:
Intent callNumber = new Intent(); callNumber.setAction(android.content.Intent.ACTION_CALL); callNumber.setData(Uri.parse("tel:8005551212")); startActivity(callNumber);
To open the Wi-Fi Settings dialog:
final Intent intent = new Intent(Intent.ACTION_MAIN, null); intent.addCategory(Intent.CATEGORY_LAUNCHER); final ComponentName cn = new ComponentName( "com.android.settings" ,"com.android.settings.wifi.WifiSettings"); intent.setComponent(cn); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(intent);
To switch device Wi-Fi on and off programmatically:
WifiManager wifiManager = (WifiManager) this.getSystemService(Context.WIFI_SERVICE); if(wifiManager.isWifiEnabled()){ if(wifiManager.setWifiEnabled(false)) return true; }else{ if(wifiManager.setWifiEnabled(true)) return true; } return false;
This requires the Manifest to request permission ...
Profiles supported on iOS
Hands-Free Profile (HFP 1.5)
Phone Book Access Profile (PBAP)
A2DP for Advanced Audio Distribution Profile
AVRCP for Audio/Video Remote Control Profile
Personal Area Network Profile (PAN)
Human Interface Device Profile (HID)
TIP: To avoid blocking (system waiting) until a new line is received, use in.ready() to check if a new line is available before calling in.readline().
LIB: Eyes-free for Text-To-Speech in your app.
APP: Music player by Davanum Srinivas, with source.
Files (such as video, audio, text) in both the res/raw folder and assets folder for an activity are obtained as a string, read one byte at a time using this utility method:
String convertStreamToString(InputStream is) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); int i = is.read(); while (i != -1){ baos.write(i); i = baos.read(); } return baos.toString(); }
Raw resource files in the res/raw folder for an activity are read from a R. reference:
String getStringFromRawFile(Activity activity) Resources r = activity.getResources(); InputStream is = r.openRawResource(R.raw.test); String myText = convertStreamToString(is); is.close(); return myText; }
Assets (such as a database file) in the assets folder for an activity are read from a named file path.
String getStringFromAsset( Activity activity){ AssetManager am = activity.getAssets(); InputStream is = am.open(“test.txt”); String s = convertStreamToString(is); Is.close(); return s; }
Cameras use the PTP (Picture Transfer Protocol) subset of the MTP (Media Transfer Protocol).
How to Get an Image via an Intent
LIB: CommonsWare quick-and-dirty sample app showing how to use the ZXing (Zebra Crossing) IntentIntegrator class for multi-format 1D/2D barcode image processing library with clients for Android, Java
LIB: Sample of sending mock ACTION_MEDIA_BUTTON broadcasts
Flashlight apps activate the camera's flash repeatedly during a short period of time. The phone may need to be rooted to enable such programmatic access.
CODE LIB: Ketai is designed for motion-aware 4th generation Android devices. It allows to capture device sensors, analyze movement, and interact with the device camera.
To find which sensor is available, use
SensorManager.getSensorList(Sensor.TYPE_ALL);
Sensor.TYPE_... | - | Motorola Droid | HTC EVO 4G | Samsung Galaxy Tab 10.1 |
---|---|---|---|---|
ROTATION_VECTOR | (3D rotation) | - | - | - |
ACCELEROMETER | m/s2 | LIS331DLH 3-axis Accelerometer (ST Micro, 12-bit) | BMA150 3-axis Accelerometer (Bosch Sensortec, 10-bit) | MPL accelerometer (??), MPL linear accel |
MAGNETIC_FIELD | Magnenometer | AK8973 3-axis Magnetic field sensor (AKM) | AK8973 3-axis Magnetic field sensor AK8973 Orientation sensor | MPL Calibrated Magnetic Field (AKM?) |
GYROSCOPE | - | - | - | MPL gyro (Invensense), MPL gravity, MPL Orientation, MPL rotation vector |
GRAVITY | - | - | - | - |
Temperature | - | AK8973 Temperature sensor (AKM) | - | MPL Temperature |
PROXIMITY | - | SFH7743 Proximity sensor (Opto Semiconductor's short-range proximity detector) | CM3602 Proximity sensor (Capella Microsystems short distance proximity sensor) | - |
LIGHT | - | LM3530 Light sensor (National Semiconductor, ambient light detector) | CM3602 Light sensor | BH1721FVC Light sensor |
PRESSURE | - | - | - | - |
NOTE: AKM refers to Asahi Kasei Microdevices, Japanese creator of mixed-signal integrate circuits, such as magnetic sensors.
APP:
4D Compass uses Gyro
APP:
Tilt 3D Labyrinth game makes use of
3-axis sensing signals from Accelerometer, Gyroscope, Magnetic Field (Magnetometer)
NativeActivity using NDK r5 or later) uses Native Access does not go thru JVM overhead (using 50% CPU at 50Hz), so takes 10% CPU usage in separate thread can provide more control over 100Hz sensor sampling rate from a separate thread.
Sensors are not supported by the emulator, so to really test your application, you’ll need a physical device with support for orientation sensor. Devices report sensor data erratically, at uneven intervals, apart from configured rates.
mylifewithandroid blogs about sensor battery drain. jsteele@sensorplatforms.com
Write a loop to:
SensorManager.registerListener()
.
http://www.w3schools.com/html5/html5_geolocation.asp <script> var x=document.getElementById("demo"); function getLocation() { if (navigator.geolocation) { navigator.geolocation.getCurrentPosition(showPosition); } else{x.innerHTML="Geolocation is not supported by this browser.";} } function showPosition(position) { x.innerHTML="Latitude: " + position.coords.latitude + "<br />Longitude: " + position.coords.longitude; } </script>