Declaring Features

Your camera implementation works great now. One more task remains: Tell potential users about it. When your app uses a feature like the camera – or near-field communication, or any other feature that may vary from device to device – it is strongly recommended that you tell Android about it. This allows other apps (like the Play Store) to refuse to install your app if it uses a feature the device does not support.

To declare that you use the camera, add a <uses-feature> tag to your AndroidManifest.xml (Listing 16.18).

Listing 16.18  Adding a <uses-feature> tag (manifests/AndroidManifest.xml)

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.bignerdranch.android.criminalintent" >

    <uses-feature android:name="android.hardware.camera"
                  android:required="false"/>
    ...
</manifest>

You include the optional attribute android:required here. Why? By default, declaring that you use a feature means that your app will not work correctly without that feature. This is not the case for CriminalIntent. You call resolveActivity(…) to check for a working camera app, then gracefully disable the camera button if you do not find one.

Passing in android:required="false" handles this situation correctly. You tell Android that your app can work fine without the camera, but that some parts will be disabled as a result.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
54.224.100.102