Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check specific features through code?

Here is the <uses-feature> and <uses-permission> specified in manifest file for my Android application

<uses-feature
        android:name="android.hardware.telephony"
        android:required="false" />
    <uses-feature
        android:name="android.hardware.location"
        android:required="false" />
    <uses-permission android:name="android.permission.CALL_PHONE" />
    <uses-permission android:name="android.permission.READ_CONTACTS" />
    <uses-permission android:name="android.permission.READ_PHONE_STATE" />
    <uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS" />
    <uses-permission android:name="android.permission.MODIFY_PHONE_STATE" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
    <uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />

I know that are used for specifying required hardware/software features for the application.Also this tag filters our application in Google Play.My application did not show for some devices including tablets too. I have some doubts.

  1. Does anything happen if we specify <uses-permission> without using <uses-feature>?For eg: Use the permissions CALL_PHONE,MODIFY_PHONE_STATE etc... without specifying hardware feature android.hardware.telephony

  2. My application fired the following receivers when click o two buttons. How can i check for these features from code?

    android:name="android.intent.action.NEW_OUTGOING_CALL" action android:name="android.intent.action.PHONE_STATE"

Thanks in Advance

like image 559
Asha Soman Avatar asked Aug 28 '13 10:08

Asha Soman


1 Answers

(1) You need to define the both <uses-permission /> and <uses-feature /> and then set android:required="false" for that feature. For instance

    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
    <uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
    <uses-feature android:name="android.hardware.wifi" android:required="false" />

In this case you get permissions but the feature is not required and you can check whether it is available in your code. For that

(2) you should use PackageManager.hasSystemFeature() method. For instance

    PackageManager mgr = context.getPackageManager();
    boolean hasTelephony = mgr.hasSystemFeature(PackageManager.FEATURE_TELEPHONY);
like image 60
sergej shafarenka Avatar answered Oct 08 '22 20:10

sergej shafarenka