Showing posts with label PackageManager. Show all posts
Showing posts with label PackageManager. Show all posts

How to Determine if Android Device Supports WiFi Direct

public static final String FEATURE_WIFI_DIRECT was added in API level 14
Feature for getSystemAvailableFeatures() and hasSystemFeature(String).
The device supports Wi-Fi Direct networking.
Constant Value: "android.hardware.wifi.direct"
Here are some examples of Android Phones with Wi-Fi Direct.


1. Get a PackageManager Instance named myPackageManager.

2. Create a Boolean Variable named bolWifiDirectSupported

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

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

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

5. Compile and run!

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

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 Supports USB host connections

public static final String FEATURE_USB_HOST was added in API level 12
Feature for getSystemAvailableFeatures() and hasSystemFeature(String).
The device supports connecting to USB devices as the USB host.
Constant Value: "android.hardware.usb.host"


1. Get a PackageManager Instance named myPackageManager.

2. Create a Boolean Variable named bolUSBHostSupported

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

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

bolUSBHostSupported = myPackageManager.hasSystemFeature(PackageManager.FEATURE_USB_HOST);
if (bolUSBHostSupported) {
Toast.makeText(this, "Device supports USB host", Toast.LENGTH_LONG).show();
} else {
Toast.makeText(this, "Device does NOT support USB host!", Toast.LENGTH_LONG).show();
}

5. Compile and run!

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


How to Determine if Android Device Supports Connecting to USB Accessories

public static final String FEATURE_USB_ACCESSORY added in API level 12
Feature for getSystemAvailableFeatures() and hasSystemFeature(String).
The device supports connecting to USB accessories.
Constant Value: "android.hardware.usb.accessory"


1. Get a PackageManager Instance named myPackageManager.

2. Create a Boolean Variable named bolUSBSupported

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

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

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

5. Compile and run!

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

How to Determine if Android Device Supports SIP-based VOIP

public static final String FEATURE_SIP_VOIP was added in API level 9
Feature for getSystemAvailableFeatures() and hasSystemFeature(String).
The device supports SIP-based VOIP.
Constant Value: "android.software.sip.voip"


1. Get a PackageManager Instance named myPackageManager.

2. Create a Boolean Variable named bolVOIPSupported

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

4. In the onCreate method, add the below code. This will return the SIP-based VOIP availability to a boolean named bolSIPSupported. It will then display a toast displaying the SIP-based VOIP availability of the device to the user.

bolVOIPSupported = myPackageManager.hasSystemFeature(PackageManager.FEATURE_SIP_VOIP);
if (bolVOIPSupported) {
Toast.makeText(this, "Device supports SIP-based VOIP", Toast.LENGTH_LONG).show();
} else {
Toast.makeText(this, "Device does NOT support SIP-based VOIP!", Toast.LENGTH_LONG).show();
}

5. Compile and run!

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

How to Determine if Android Device has SIP API Enabled

public static final String FEATURE_SIP was Added in API level 9
Feature for getSystemAvailableFeatures() and hasSystemFeature(String).
The SIP API is enabled on the device.
Constant Value: "android.software.sip"


1. Get a PackageManager Instance named myPackageManager.

2. Create a Boolean Variable named bolSIPSupported

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

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

bolSIPSupported = myPackageManager.hasSystemFeature(PackageManager.FEATURE_SIP);
if (bolSIPSupported) {
Toast.makeText(this, "Device has a SIP API enabled", Toast.LENGTH_LONG).show();
} else {
Toast.makeText(this, "Device does NOT have SIP API enabled!", Toast.LENGTH_LONG).show();
}

5. Compile and run!

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

How to Determine if Android Device has a Step Detector

public static final String FEATURE_SENSOR_STEP_DETECTOR was added in API level 19
Feature for getSystemAvailableFeatures() and hasSystemFeature(String).
The device includes a hardware step detector.
Constant Value: "android.hardware.sensor.stepdetector"


1. Get a PackageManager Instance named myPackageManager.

2. Create a Boolean Variable named bolStepDetectorSupported

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

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

bolStepDetectorSupported = myPackageManager.hasSystemFeature(PackageManager.FEATURE_SENSOR_STEP_DETECTOR);
if (bolStepDetectorSupported) {
Toast.makeText(this, "Device has a Step Detector Sensor", Toast.LENGTH_LONG).show();
} else {
Toast.makeText(this, "Device does NOT have a Step Detector Sensor!", Toast.LENGTH_LONG).show();
}

5. Compile and run!

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

How to Determine if Android Device has a Step Counter

public static final String FEATURE_SENSOR_STEP_COUNTER was added in API level 19
Feature for getSystemAvailableFeatures() and hasSystemFeature(String).
The device includes a hardware step counter.
Constant Value: "android.hardware.sensor.stepcounter"


1. Get a PackageManager Instance named myPackageManager.

2. Create a Boolean Variable named bolStepCounterSupported

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

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

bolStepCounterSupported = myPackageManager.hasSystemFeature(PackageManager.FEATURE_SENSOR_STEP_COUNTER);
if (bolStepCounterSupported) {
Toast.makeText(this, "Device has a Step Counter Sensor", Toast.LENGTH_LONG).show();
} else {
Toast.makeText(this, "Device does NOT have a Step Counter Sensor!", Toast.LENGTH_LONG).show();
}

5. Compile and run!

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

How to Determine if Android Device has Proximity Sensor

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


1. Get a PackageManager Instance named myPackageManager.

2. Create a Boolean Variable named bolProximitySupported

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

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

bolProximitySupported = myPackageManager.hasSystemFeature(PackageManager.FEATURE_SENSOR_PROXIMITY);
if (bolProximitySupported) {
Toast.makeText(this, "Device has a Proximity Sensor", Toast.LENGTH_LONG).show();
} else {
Toast.makeText(this, "Device does NOT have a Proximity Sensor!", Toast.LENGTH_LONG).show();
}

5. Compile and run!

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

How to Determine if Android Device has a Light Sensor, using PackageManager

public static final String FEATURE_SENSOR_LIGHT was added in API level 7
Feature for getSystemAvailableFeatures() and hasSystemFeature(String).
The device includes a light sensor.
Constant Value: "android.hardware.sensor.light"
* For API Level 3 and above, you may also use How to Determine if Android Device has Light Sensor, using SensorManager


1. Get a PackageManager Instance named myPackageManager.

2. Create a Boolean Variable named bolLightSupported

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

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

bolLightSupported = myPackageManager.hasSystemFeature(PackageManager.FEATURE_SENSOR_LIGHT);
if (bolLightSupported) {
Toast.makeText(this, "Device has a Light Sensor", Toast.LENGTH_LONG).show();
} else {
Toast.makeText(this, "Device does NOT have a Light Sensor!", Toast.LENGTH_LONG).show();
}

5. Compile and run!

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

How to Determine if Android Device has a Gyroscope

public static final String FEATURE_SENSOR_GYROSCOPE was added in API level 9
Feature for getSystemAvailableFeatures() and hasSystemFeature(String).
The device includes a gyroscope.
Constant Value: "android.hardware.sensor.gyroscope"
Here are some examples of Android Cell phones with a Gyroscope.


1. Get a PackageManager Instance named myPackageManager.

2. Create a Boolean Variable named bolGyroSupported

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

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

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

5. Compile and run!

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

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 Support Portrait Orientation Screens

public static final String FEATURE_SCREEN_PORTRAIT was added in API level 13
Feature for getSystemAvailableFeatures() and hasSystemFeature(String).
The device supports portrait orientation screens. For backwards compatibility, you can assume that if neither this nor FEATURE_SCREEN_LANDSCAPE is set then the device supports both portrait and landscape.
Constant Value: "android.hardware.screen.portrait"


1. Get a PackageManager Instance named myPackageManager.

2. Create a Boolean Variable named bolPortraitSupported

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

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

bolPortraitSupported = myPackageManager.hasSystemFeature(PackageManager.FEATURE_SCREEN_PORTRAIT);
if (bolPortraitSupported) {
Toast.makeText(this, "Device supports portrait orientation screens", Toast.LENGTH_LONG).show();
} else {
Toast.makeText(this, "Device does NOT support portrait orientation screens!", Toast.LENGTH_LONG).show();
}

5. Compile and run!

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

How to Determine if Android Device Supports Landscape Orientation

public static final String FEATURE_SCREEN_LANDSCAPE was added in API level 13
Feature for getSystemAvailableFeatures() and hasSystemFeature(String).
The device supports landscape orientation screens. For backwards compatibility, you can assume that if neither this norFEATURE_SCREEN_PORTRAIT is set then the device supports both portrait and landscape.
Constant Value: "android.hardware.screen.landscape"


1. Get a PackageManager Instance named myPackageManager.

2. Create a Boolean Variable named bolLandscapeSupported

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

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

bolLandscapeSupported = myPackageManager.hasSystemFeature(PackageManager.FEATURE_SCREEN_LANDSCAPE);
if (bolLandscapeSupported) {
Toast.makeText(this, "Device supports landscape orientation screens", Toast.LENGTH_LONG).show();
} else {
Toast.makeText(this, "Device does NOT support landscape orientation screens!", Toast.LENGTH_LONG).show();
}

5. Compile and run!

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

How to Determine if Android Device Supports Host-Based NFC Card Emulation

public static final String FEATURE_NFC_HOST_CARD_EMULATION was added in API level 19
Feature for getSystemAvailableFeatures() and hasSystemFeature(String).
The device supports host- based NFC card emulation.
Constant Value: "android.hardware.nfc.hce"


1. Get a PackageManager Instance named myPackageManager.

2. Create a Boolean Variable named bolHCNFCSupported

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

4. In the onCreate method, add the below code. This will return the host-based NFC ability to a boolean named bolHCNFCSupported. It will then display a toast displaying the host-based NFC ability of the device to the user.

bolHCNFCSupported = myPackageManager.hasSystemFeature(PackageManager.FEATURE_NFC_HOST_CARD_EMULATION);
if (bolHCNFCSupported) {
Toast.makeText(this, "Device has host-based NFC capability", Toast.LENGTH_LONG).show();
} else {
Toast.makeText(this, "No host-based NFC capability!", Toast.LENGTH_LONG).show();
}

5. Compile and run!

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

Other Resources:
Professional NFC Application Development for Android by Vedat Coskun

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