Android Question Security Exception Read_Phone_Satate in Lollipop

Alberto Michelis

Well-Known Member
Licensed User
Longtime User
Hi,
One user upgades Android to Lollipop and my app stop working indicating the atached error.
Many user has Android 5 and 5.1 without problem.
What could cause this?
I use this code:
B4X:
    Dim p As Phone
    Dim overall_data_state As Int
    Dim cellular_data_state As Int
    Dim wifi As Int = p.GetSettings ("wifi_on")
    Dim airplane_mode As Int = p.GetSettings ("airplane_mode_on")
    Dim manuf As String = p.Manufacturer
    Dim model As String = p.Model
    'Test the Cellular State
    Select Case p.GetDataState
        Case "CONNECTED"
            cellular_data_state = 1
        Case Else
            'Captures the other possible states of "SUSPENDED" "DISCONNECTED" "CONNECTING"
            cellular_data_state = 0
    End Select
Thanks
 

Attachments

  • AhB7K6iu3SrleFsaZZ2LwCKKoSZTJVO2b-Nr1GZtTo2R.jpg
    AhB7K6iu3SrleFsaZZ2LwCKKoSZTJVO2b-Nr1GZtTo2R.jpg
    106.2 KB · Views: 228

DonManfred

Expert
Licensed User
Longtime User
maybe add this to your manifest
It is better to use the right command in manifest instead of changing defaults with manual changes.

It is better to add this permission with this command to your manifest (manifesteditor in b4a ide)

B4X:
AddPermission(android.permission.READ_PHONE_STATE)
 
Upvote 0

corwin42

Expert
Licensed User
Longtime User
Hi,
One user upgades Android to Lollipop and my app stop working indicating the atached error.
Many user has Android 5 and 5.1 without problem.
What could cause this?
I use this code:
B4X:
    Select Case p.GetDataState

Let me guess: 100% of the users with this error use Samsung devices with Android 5.x

I had the same issue with p.GetDataState(). See here.

The "official" way that Google recommends to detect a data connection in a B4A implementation is here and it does not need the READ_PHONE_STATE permission, even on Samsung devices.
 
Upvote 0

Alberto Michelis

Well-Known Member
Licensed User
Longtime User
It is better to use the right command in manifest instead of changing defaults with manual changes.

It is better to add this permission with this command to your manifest (manifesteditor in b4a ide)

B4X:
AddPermission(android.permission.READ_PHONE_STATE)

I thought the permissions in the manifest were automatically add by B4A.
 
Upvote 0

Alberto Michelis

Well-Known Member
Licensed User
Longtime User
Let me guess: 100% of the users with this error use Samsung devices with Android 5.x

I had the same issue with p.GetDataState(). See here.

The "official" way that Google recommends to detect a data connection in a B4A implementation is here and it does not need the READ_PHONE_STATE permission, even on Samsung devices.

No, not ALL the samsung with Android 5 fail.
 
Upvote 0

corwin42

Expert
Licensed User
Longtime User
Any way to know which permisses needs to be adde by code? just avoid user complains that are not good for the app.

As Erel said, this is a special case because it is a bug in Samsungs Android 5.0 Firmware. If you look into the Android documentation you will see that READ_PHONE_STATE is not needed for Phone.GetDataState(). Unfortunately Samsung messed something up in their firmwares that requires this right. Only Samsung knows, why.
 
Upvote 0
Top