How to check specific functions using code?

Here are the <uses-feature> and <uses-permission> specified in the 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 they are used to indicate the necessary hardware / software functions for an application. This tag also filters our application in the Google Play.My application, which is not displayed for some devices, including tablets. I have some doubts.

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

  • My application fired the following receivers when two buttons are selected. How can I test these functions from code?

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

Thanks at Advance

+4
source share
1 answer

(1) You need to define both <uses-permission /> and <uses-feature /> , and then set android:required="false" for this function. 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 function is not required, and you can check if it is available in your code. For this

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

  PackageManager mgr = context.getPackageManager(); boolean hasTelephony = mgr.hasSystemFeature(PackageManager.FEATURE_TELEPHONY); 
+8
source

Source: https://habr.com/ru/post/1499349/


All Articles