Showing posts with label API Level 8. Show all posts
Showing posts with label API Level 8. Show all posts

How to Determine if Android Device Supports WiFi

public static final String FEATURE_WIFI was added in API level 8
Feature for getSystemAvailableFeatures() and hasSystemFeature(String).
The device supports WiFi (802.11) networking.
Constant Value: "android.hardware.wifi"


1. Get a PackageManager Instance named myPackageManager.

2. Create a Boolean Variable named bolWifiSupported

3. Set the Minimum and Target SDK version  to or greater. 

4. In the onCreate method, add the below code. This will return the Wifi availability to a boolean named bolWifiSupported. It will then display a toast displaying the Wifi availability of the device to the user.

bolWifiSupported = myPackageManager.hasSystemFeature(PackageManager.FEATURE_WIFI);
if (bolWifiSupported) {
Toast.makeText(this, "Device supports Wifi", Toast.LENGTH_LONG).show();
} else {
Toast.makeText(this, "Device does NOT support Wifi!", Toast.LENGTH_LONG).show();
}

5. Compile and run!

Resources:
http://developer.android.com/reference/android/content/pm/PackageManager.html#FEATURE_WIFI

How to Determine if Android Device has a Magnetometer (Compass)

public static final String FEATURE_SENSOR_COMPASS was added in API level 8
Feature for getSystemAvailableFeatures() and hasSystemFeature(String).
The device includes a magnetometer (compass).
Constant Value: "android.hardware.sensor.compass"


1. Get a PackageManager Instance named myPackageManager.

2. Create a Boolean Variable named bolCompassSupported

3. Set the Minimum and Target SDK version  to or greater. 

4. In the onCreate method, add the below code. This will return the compass feature availability to a boolean named bolCompassSupported. It will then display a toast displaying the compass feature availability of the device to the user.

bolCompassSupported = myPackageManager.hasSystemFeature(PackageManager.FEATURE_SENSOR_COMPASS);
if (bolCompassSupported) {
Toast.makeText(this, "Device has a Compass", Toast.LENGTH_LONG).show();
} else {
Toast.makeText(this, "Device does NOT have a Compass!", Toast.LENGTH_LONG).show();
}

5. Compile and run!

Resources:
http://developer.android.com/reference/android/content/pm/PackageManager.html#FEATURE_SENSOR_COMPASS

How to Determine if Android Device has an Accelerometer

public static final String FEATURE_SENSOR_ACCELEROMETER was added in API level 8
Feature for getSystemAvailableFeatures() and hasSystemFeature(String): The device includes an accelerometer.
Constant Value: "android.hardware.sensor.accelerometer"


1. Get a PackageManager Instance named myPackageManager.

2. Create a Boolean Variable named bolAccelSupported

3. Set the Minimum and Target SDK version  to or greater. 

4. In the onCreate method, add the below code. This will return the accelerometer feature to a boolean named bolAccelSupported. It will then display a toast displaying the accelerometer feature of the device to the user.

bolAccelSupported = myPackageManager.hasSystemFeature(PackageManager.FEATURE_SENSOR_ACCELEROMETER);
if (bolAccelSupported) {
Toast.makeText(this, "Device has an Accelerometer", Toast.LENGTH_LONG).show();
} else {
Toast.makeText(this, "Device does NOT have an Accelerometer!", Toast.LENGTH_LONG).show();
}

5. Compile and run!

Resources:
http://developer.android.com/reference/android/content/pm/PackageManager.html#FEATURE_SENSOR_ACCELEROMETER

How to Determine if Android Device has a Microphone

public static final String FEATURE_MICROPHONE was added in API level 8
Feature for getSystemAvailableFeatures() and hasSystemFeature(String).
The device can record audio via a microphone.
Constant Value: "android.hardware.microphone"

1. Get a PackageManager Instance and save to myPackageManager.

2. Create a Boolean Variable named bolMicrophoneSupported

3. Set the Minimum and Target SDK version  to or greater. 

4. In the onCreate method, add the below code. This will return the microphone support to a boolean named bolMicrophoneSupported. It will then display a toast displaying the microphone support on the device to the user.

bolMicrophoneSupported = myPackageManager.hasSystemFeature(PackageManager.FEATURE_MICROPHONE);
if (bolMicrophoneSupported) {
Toast.makeText(this, "Device has a microphone", Toast.LENGTH_LONG).show();
} else {
Toast.makeText(this, "No microphone!", Toast.LENGTH_LONG).show();
}

5. Compile and run!

Resources:
http://developer.android.com/reference/android/content/pm/PackageManager.html#FEATURE_MICROPHONE

How to Determine if Android Device has Network-based Geolocation

public static final String FEATURE_LOCATION_NETWORK was added in API level 8
Feature for getSystemAvailableFeatures() and hasSystemFeature(String).
The device can report location with coarse accuracy using a network-based geolocation system.
Constant Value: "android.hardware.location.network"

1. Get a PackageManager Instance and save to myPackageManager.

2. Create a Boolean Variable named bolNBSupported

3. Set the Minimum and Target SDK version  to or greater. 

4. In the onCreate method, add the below code. This will return the network-based geolocation ability to a boolean named bolGPSSupported. It will then display a toast displaying the network-based geolocation ability on the device to the user.

bolNBSupported = myPackageManager.hasSystemFeature(PackageManager.FEATURE_LOCATION_NETWORK);
if (bolNBSupported) {
Toast.makeText(this, "Device has network-based geolocation feature", Toast.LENGTH_LONG).show();
} else {
Toast.makeText(this, "No network-based geolocation feature!", Toast.LENGTH_LONG).show();
}

5. Compile and run!

Resources:
http://developer.android.com/reference/android/content/pm/PackageManager.html#FEATURE_LOCATION_NETWORK

How to Determine if Android Device has GPS Support

public static final String FEATURE_LOCATION_GPS was added in API level 8
Feature for getSystemAvailableFeatures() and hasSystemFeature(String).
The device has a Global Positioning System receiver and can report precise location.
Constant Value: "android.hardware.location.gps"

1. Get a PackageManager Instance and save to myPackageManager.

2. Create a Boolean Variable named bolGPSSupported

3. Set the Minimum and Target SDK version  to or greater. 

4. In the onCreate method, add the below code. This will return the GPS ability to a boolean named bolGPSSupported. It will then display a toast displaying the GPS ability on the device to the user.

bolGPSSupported = myPackageManager.hasSystemFeature(PackageManager.FEATURE_LOCATION_GPS);
if (bolGPSSupported) {
Toast.makeText(this, "Device has GPS feature", Toast.LENGTH_LONG).show();
} else {
Toast.makeText(this, "No GPS feature!", Toast.LENGTH_LONG).show();
}

5. Compile and run!

Resources:
http://developer.android.com/reference/android/content/pm/PackageManager.html#FEATURE_LOCATION_GPS

How to Determine if Android Device has Current Location Support

public static final String FEATURE_LOCATION was added in API level 8
Feature for getSystemAvailableFeatures() and hasSystemFeature(String).
The device supports one or more methods of reporting current location.
Constant Value: "android.hardware.location"

1. Get a PackageManager Instance and save to myPackageManager.

2. Create a Boolean Variable named bolLocationSupported

3. Set the Minimum and Target SDK version  to or greater. 

4. In the onCreate method, add the below code. This will return the current location support ability to a boolean named bolLocationSupported. It will then display a toast displaying the current location support ability on the device to the user.

bolLocationSupported = myPackageManager.hasSystemFeature(PackageManager.FEATURE_LOCATION);
if (bolLocationSupported) {
Toast.makeText(this, "Device supports current location", Toast.LENGTH_LONG).show();
} else {
Toast.makeText(this, "No current location support!", Toast.LENGTH_LONG).show();
}

5. Compile and run!

Resources:
http://developer.android.com/reference/android/content/pm/PackageManager.html#FEATURE_LOCATION

How to Determine if Android Device has Bluetooth Capability

public static final String FEATURE_BLUETOOTH was added in API level 8
Feature for getSystemAvailableFeatures() and hasSystemFeature(String).
 The device is capable of communicating with other devices via Bluetooth.
Constant Value: "android.hardware.bluetooth"


1. Get a PackageManager Instance named myPackageManager.

2. Create a Boolean Variable named bolBluetoothSupported

3. Set the Minimum and Target SDK version  to or greater. 

4. In the onCreate method, add the below code. This will return the Bluetooth ability to a boolean named bolBluetoothSupported. It will then display a toast displaying the Bluetooth ability of the device to the user.

bolBluetoothSupported = myPackageManager.hasSystemFeature(PackageManager.FEATURE_BLUETOOTH);
if (bolBluetoothSupported) {
Toast.makeText(this, "Device has Bluetooth capability", Toast.LENGTH_LONG).show();
} else {
Toast.makeText(this, "No Bluetooth capability!", Toast.LENGTH_LONG).show();
}

5. Compile and run!

Resources:
http://developer.android.com/reference/android/content/pm/PackageManager.html#FEATURE_BLUETOOTH

How to Determine if Android Device has Touch Screen Multi-Touch Distinct Feature

public static final String FEATURE_TOUCHSCREEN_MULTITOUCH_DISTINCT was added in API level 8
Feature for getSystemAvailableFeatures() and hasSystemFeature(String).
The device's touch screen is capable of tracking two or more fingers fully independently.
Constant Value: "android.hardware.touchscreen.multitouch.distinct"


1. Get a PackageManager Instance named myPackageManager.

2. Create a Boolean Variable named bolTMDSupported

3. Set the Minimum and Target SDK version  to or greater. 

4. In the onCreate method, add the below code. This will return the touch screen multi-touch distinct ability to a boolean named bolTMDSupported. It will then display a toast displaying the touch screen multi-touch distinct ability of the device to the user.

bolTMDSupported = myPackageManager.hasSystemFeature(PackageManager.FEATURE_TOUCHSCREEN_MULTITOUCH_DISTINCT);
if (bolTMDSupported) {
Toast.makeText(this, "Device has Touch Screen Multi-Touch distinct capability", Toast.LENGTH_LONG).show();
} else {
Toast.makeText(this, "No Touch Screen Multi-Touch distinct capability!", Toast.LENGTH_LONG).show();
}

5. Compile and run!

Resources:
http://developer.android.com/reference/android/content/pm/PackageManager.html#FEATURE_TOUCHSCREEN_MULTITOUCH_DISTINCT

How to Determine if Android Device has Touch Screen Feature

public static final String FEATURE_TOUCHSCREEN was added in API level 8
Feature for getSystemAvailableFeatures() and hasSystemFeature(String)
The device's display has a touch screen.
Constant Value: "android.hardware.touchscreen"


1. Get a PackageManager Instance named myPackageManager.

2. Create a Boolean Variable named bolTouchScreenSupported

3. Set the Minimum and Target SDK version  to 8 or greater. 

4. In the onCreate method, add the below code. This will return the touch screen ability to a boolean named bolTouchScreenSupported. It will then display a toast displaying the touch screen ability of the device to the user.

bolTouchScreenSupported = myPackageManager.hasSystemFeature(PackageManager.FEATURE_TOUCHSCREEN);
if (bolTouchScreenSupported) {
Toast.makeText(this, "Device has Touch Screen capability", Toast.LENGTH_LONG).show();
} else {
Toast.makeText(this, "No Touch Screen capability!", Toast.LENGTH_LONG).show();
}

5. Compile and run!

How to Get the Passive Provider

public static final String PASSIVE_PROVIDER was added in API level 8
A special location provider for receiving locations without actually initiating a location fix.
This provider can be used to passively receive location updates when other applications or services request them without actually requesting the locations yourself. This provider will return locations generated by other providers. You can query the getProvider() method to determine the origin of the location update. Requires the permission ACCESS_FINE_LOCATION, although if the GPS is not enabled this provider might only return coarse fixes.

1. Ensure to change the minSDKVersion to 8, or greater.

2. Set Permission to Allow Location Information

3. Declare a String Variable named myPassiveProvider.

4. Add the LocationManager class to the imports section.

5. Add the below line to the onCreate method. This will save the Passive Provider to the string variable myPassiveProvider.

myPassiveProvider = LocationManager.PASSIVE_PROVIDER;

6. Compile and run!

Resources:
Professional Android 4 Application Development by Reto Meier, pg 525
http://developer.android.com/reference/android/location/LocationManager.html#PASSIVE_PROVIDER

How to Set the Install Location of your App

android:installLocation was added in API Level 8
Allows your app to be installed on external storage. If android:installLocation is not included, your app be installed internally only, and not movable.
1. In the AndroidManifest.xml file, add the below line between the <manifest> tags. This will set the application to automatically install on external storage, if available. 

<manifest
    ...
     android:installLocation="preferExternal"
</manifest>

2. Compile and run!

3. All optional settings:

preferExternal: you request that your application be installed on the external storage, but the system does not guarantee that your application will be installed on the external storage. If the external storage is full, the system will install it on the internal storage. The user can also move your application between the two locations.

auto: you indicate that your application may be installed on the external storage, but you don't have a preference of install location. The system will decide where to install your application based on several factors. The user can also move your application between the two locations.
internalOnly: the application must be installed on the internal device storage only. If this is set, the application will never be installed on the external storage. If the internal storage is full, then the system will not install the application. This is also the default behavior if you do not define android:installLocation.

4. When an application is installed on the external storage:

* The .apk file is saved to the external storage, but any application data (such as databases) is still saved on the internal device memory.
* The container in which the .apk file is saved is encrypted with a key that allows the application to operate only on the device that installed it. (A user cannot transfer the SD card to another device and use applications installed on the card.) Though, multiple SD cards can be used with the same device.
* At the user's request, the application can be moved to the internal storage.

Resources: http://developer.android.com/guide/topics/data/install-location.html
http://developer.android.com/guide/topics/manifest/manifest-element.html


match_parent

match_parent

added in API Level 8

Special value for the height or width requested by a View. match_parent means that the view wants to be as big as its parent, minus the parent's padding, if any.

Resources:
http://developer.android.com/reference/android/view/ViewGroup.LayoutParams.html#MATCH_PARENT