Android Question how to get sdk version without phone library

GraemeW

Member
Licensed User
Longtime User
I'm trying to make my app available for tablets but some tablets are not supported. I suspect they are wifi only versions - with no telephony hardware.

In Manifest I have included
AddManifestText(<uses-feature android:name="android.hardware.telephony" android:required="false"/>)

I have also removed Phone library from app.

However android.hardware.telephony still appears in the Features list for the App Bundle.

I have also found CheckNotificationPermission includes a dim p as Phone and p.SdkVersion. I suspect this is forcing android.hardware.telephony in the Features list.

Is there another way of getting a device sdk version for use with CheckNotificationPermission?
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
You don't need to remove the Phone library. It has no relation to the "features list". The features are derived from the permissions and the Phone type from the Phone library will not add any permission.

The problem is somewhere else and from a different feature that is being added. Check the full list of features.
 
Upvote 0

GraemeW

Member
Licensed User
Longtime User
Thank you. Permissions include android.permission.ACCESS_NETWORK_STATE and android.permission.CALL_PHONE which I presume results in android.hardware.telephony in the features list. I don't know where these permissions are coming from, if not Phone. I can't see how a device could be supported if it doesn't have telephony hardware (such as, I presume, wifi-only tablets).

However I'm also checking android.hardware.screen.portrait in the feature list. I have #SupportedOrientations: portrait in Project Attributes. Apparently some tablets don't like this..
 
Upvote 0

JohnC

Expert
Licensed User
Longtime User
The new ChatGPT model o3-mini-high says...

Reasoned about app compatibility and features for 26 seconds

Investigating app limitations
The user is figuring out how to support tablets, specifically models without telephony hardware, by tweaking the app manifest and removing unnecessary libraries. Progress is being made to ensure full compatibility.
Confirming adjustments
The user has confirmed that adding <uses-feature android:name="android.hardware.telephony" android:required="false"/> and removing the Phone library didn't eliminate android.hardware.telephony from the App Bundle's Features list.
Identifying the cause
The issue originates from the CheckNotificationPermission method, which references a phone object and uses the phone library, unintentionally adding the telephony feature to the manifest.
Crafting alternatives
The user is exploring options to check notification permissions without using the phone library. This might involve Java code with reflection or a variable for the device's Sdk version in B4A.
Leveraging reflection
To get the device's Sdk version in B4A without using the Phone library, the Reflector library can be used to access the android.os.Build.VERSION.SDK_INT value.
Evaluating options
Considering the "Utils" library in B4A, which might offer a function like "GetDeviceSDK" to retrieve the device's Sdk version without implicating the Phone library, avoiding the telephony feature.
Mapping out the solution
The B4X team acknowledges the issue and suggests using a Java library method to retrieve the Sdk version without adding telephony features, possibly through a wrapper method that excludes telephony class references.
Exploring options
The user is thinking about creating a Java wrapper method to retrieve the SDK version without invoking the Phone library, thereby avoiding telephony feature inclusion.
Crafting a Java wrapper
I'm focusing on a Java wrapper method to fetch the SDK version directly from android.os.Build.VERSION.SDK_INT, avoiding telephony references to sidestep including the Phone library.
Mapping out the strategy
I'm thinking about a Java wrapper method to retrieve the SDK version from android.os.Build.VERSION.SDK_INT, which avoids telephony references and sidesteps including the Phone library.
Piecing together a solution
Using Android's Build.VERSION.SDK_INT is the current approach, avoiding the deprecated android.os.Build.VERSION.SDK method. B4A might enable accessing this through the "Reflector" object.
Assessing B4A methods
I’m evaluating B4A's "getDeviceSdk" function and Java's Reflector object for accessing "android.os.Build$VERSION.SDK_INT", ensuring the correct usage to avoid adding the Phone library inadvertently.
Piecing together options
I'm evaluating B4A's "getDeviceSdk" and Java's Reflector object to access "android.os.Build$VERSION.SDK_INT", aiming to prevent inadvertent Phone library references.
Avoiding telephony details
I'm working on a Java wrapper that pulls the SDK version from android.os.Build.VERSION.SDK_INT, steering clear of any telephony references by sidestepping the Phone library inclusion fortuitously.
Mapping out the solution
I'm working on a Java wrapper to pull the SDK version from android.os.Build.VERSION.SDK_INT, steering clear of the Phone library inclusion's unintended telephony feature and using the Reflect library in B4A for access.
Retrieving SDK version
I’m accessing the SDK version using the Java static variable Build.VERSION.SDK_INT through the B4A Reflector library, ensuring no telephony references are unintentionally included.
Confirming object type
I’m working through the B4A Reflector library to ensure r.GetStaticField returns an integer for Build.VERSION.SDK_INT, aiming to eliminate the unintended inclusion of the Phone library in CheckNotificationPermission.
Addressing dependency
I'm thinking through eliminating the Phone library dependency by substituting Phone.SdkVersion with a direct reference to Build.VERSION.SDK_INT using the B4A Reflector library.
Navigating dependencies
I’m exploring using the Reflector library to bypass indirect Little-c Allow dependency on the Phone object instead of directly depending on the Phone library.
Refining the reflection code
I’m refining the code for Android SDK version access using the Reflector library, noting that r.GetStaticField("android.os.Build$VERSION", "SDK_INT") directly returns an integer.
Mapping the approach
I’m piecing together that r.GetStaticField("android.os.Build$VERSION", "SDK_INT") reliably returns an integer, leveraging automatic casting to simplify accessing the Android SDK version via the Reflector object.

The answer turned out to be that nothing “magic” was required – you just must not use Phone.SdkVersion at all. That property is forcing a dependency on the Phone library (and thus on telephony) even if you mark it as not required in the manifest. Instead, you can get the device’s SDK version directly from the Android API without pulling in the Phone library.

How to Do It​

In Android the current way to get the SDK version is via the static field Build.VERSION.SDK_INT. In B4A you can access that using the Reflector object. For example, you could do something like this:
B4X:
Dim r As Reflector
' This call returns the value of Build.VERSION.SDK_INT (an Integer).
Dim sdkVersion As Int = r.GetStaticField("android.os.Build$VERSION", "SDK_INT")
Log("SDK Version: " & sdkVersion)
This way you avoid referencing the Phone library entirely and the manifest will no longer include the telephony feature. You can then update your CheckNotificationPermission code (or create your own version) to use this value rather than Phone.SdkVersion.

Summary​

  • Do not use Phone.SdkVersion.
  • Use the Android API’s Build.VERSION.SDK_INT (accessed via Reflector in B4A) to get the device’s SDK version.
  • This change prevents the automatic inclusion of the telephony feature in your App Bundle manifest.
By making this change, your app should correctly support wifi-only tablets without inadvertently declaring a dependency on telephony hardware.
 
Last edited:
Upvote 0

GraemeW

Member
Licensed User
Longtime User
Thank you JohnC for your effort - an approach I had not considered. If I can get sdkVersion without the Phone library (which is not used for anything else) then that will improve app size. I will look into using the Reflector - which is already in my app.

However, by changing #SupportedOrientations: portrait in Project Attributes to #SupportedOrientations: unspecified another 1,500 devices are now supported by my app - including my wifi-only tablet.

Why some tablets require landscape, yet show portrait perfectly well, is a mystery to me.

I've re-included the Phone library, kept dim p as Phone and android.hardware.telephony is still in the features list - however, as Erel says, it was not the cause of the problem.
 
Upvote 0
Top