Android Question Security Exception Read_Phone_Satate in Lollipop

Discussion in 'Android Questions' started by Alberto Michelis, Aug 21, 2015.

  1. Alberto Michelis

    Alberto Michelis Active Member Licensed 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:
    Code:
    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
     

    Attached Files:

  2. Siam

    Siam Active Member Licensed User

    maybe add this to your manifest

    <uses-permission android:name="android.permission.READ_PHONE_STATE" />
     
  3. DonManfred

    DonManfred Expert Licensed 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)

    Code:
    AddPermission(android.permission.READ_PHONE_STATE)
     
  4. corwin42

    corwin42 Expert Licensed 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.
     
  5. Alberto Michelis

    Alberto Michelis Active Member Licensed User

    I thought the permissions in the manifest were automatically add by B4A.
     
  6. Alberto Michelis

    Alberto Michelis Active Member Licensed User

    No, not ALL the samsung with Android 5 fail.
     
  7. Alberto Michelis

    Alberto Michelis Active Member Licensed User

    Adding the permission manually solved the problem... Do I have to add it one by one?
     
  8. Erel

    Erel Administrator Staff Member Licensed User

    Permissions are added automatically when possible. In this specific case the compiler cannot know that this permission is required.
     
  9. Alberto Michelis

    Alberto Michelis Active Member Licensed User

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

    Erel Administrator Staff Member Licensed User

    In 99% of the cases the permissions will be added automatically by the compiler.

    As I wrote in this case the compiler cannot know that the permission is required. You may be able to find this information in Android documentation.
     
    Alberto Michelis likes this.
  11. corwin42

    corwin42 Expert Licensed User

    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.
     
    Erel, DonManfred and Alberto Michelis like this.
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice