Android Question [Solved] Read Phone State

Discussion in 'Android Questions' started by dibesw, Jul 22, 2019.

  1. dibesw

    dibesw Active Member Licensed User

    I have developed a simple app that send sms with coordinates. This app works well on some phone (android 6,8,9) BUT ON ONE (Asus Zenfone3 with android 8) not works e do not know why.

    [​IMG]
    Code:
    Dim p As PhoneSms
    ...
    ...
    Sub Activity_Create(FirstTime As Boolean)
        rp.CheckAndRequest(rp.PERMISSION_SEND_SMS)
    End Sub
    Code:
    Sub Activity_PermissionResult (Permission As String, Result As Boolean)
       
    If Permission = rp.PERMISSION_SEND_SMS Then
            
    If Result = True Then
                rp.CheckAndRequest(rp.PERMISSION_ACCESS_FINE_LOCATION)
            
    Else
                
    ToastMessageShow("Non puoi utilizzare il programma PERMISSION_SEND_SMS"True)
                
    Activity.finish
            
    End If
       
    End If
       
    If Permission = rp.PERMISSION_ACCESS_FINE_LOCATION Then
            
    If Result = True Then
               
    'rp.CheckAndRequest(rp.PERMISSION_READ_PHONE_STATE)  
               inizializza
            
    Else
                
    ToastMessageShow("Non puoi utilizzare il programma PERMISSION_ACCESS_FINE_LOCATION"True)
                
    Activity.finish
            
    End If
        
    End If
     
    End Sub
    Sub inizializza
        GPS1.Initialize(
    "GPS")
        GPS1.Start(
    00'Listen to GPS with no filters.
        FusedLocationProvider1.Initialize("FusedLocationProvider1")
        FusedLocationProvider1.Connect
    End Sub
    Code:
    Sub timer1_Tick
        conta=conta-
    1
        Label1.Text=conta
        
    If conta=0 Then
           Label1.Text=
    ""
           timer1.Enabled=
    False
           
    If manager.GetString("telefono1")<>"" Then
              p.Send(manager.GetString(
    "telefono1"),manager.GetString("nome") & "    http://maps.google.com/maps?q=N" & LatGPS & ",E" & LonGPS)
           
    End If
           
    If  manager.GetString("telefono2")<>"" Then 
              p.Send(manager.GetString(
    "telefono2"),manager.GetString("nome") & "    http://maps.google.com/maps?q=N" & LatGPS & ",E" & LonGPS)
           
    End If
           
    If manager.GetString("telefono3")<>"" Then 
              p.Send(manager.GetString(
    "telefono3"),manager.GetString("nome") & "    http://maps.google.com/maps?q=N" & LatGPS & ",E" & LonGPS)
           
    End If   
           
    ToastMessageShow("Messaggio inviato...",False)
        
    End If   
    End Sub
    I also tried to do...

    Code:
    If Permission = rp.PERMISSION_READ_PHONE_STATE Then
            
    If Result = True Then
                
    Msgbox("PERMESSO OK","")
                
    'inizializza
            Else
                
    ToastMessageShow("Non puoi utilizzare il programma"True)
                
    Activity.finish
            
    End If
        
    Else
            
    Msgbox(Permission & "   " & Result,"")  
        
    End If
    and this code give "FALSE"

    I have B4A v6.31 and this is manifest:

    Code:
    'This code will be applied to the manifest file during compilation.
    'You do not need to modify it in most cases.
    'See this link for for more information: http://www.basic4ppc.com/forum/showthread.php?p=78136
    AddManifestText(
    <uses-sdk android:minSdkVersion=
    "4" android:targetSdkVersion="14"/>
    <supports-screens android:largeScreens=
    "true"
        android:normalScreens=
    "true"
        android:smallScreens=
    "true"
        android:anyDensity=
    "true"/>)
    SetApplicationAttribute(android:icon, 
    "@drawable/icon")
    SetApplicationAttribute(android:
    label"$LABEL$")
    'End of default text.
    AddApplicationText(<activity android:name="anywheresoftware.b4a.objects.preferenceactivity"/>)
    AddManifestText(<uses-feature android:name=
    "android.hardware.location.gps"/>)
    AddApplicationText(<meta-data
        android:name=
    "com.google.android.gms.version"
        android:value=
    "@integer/google_play_services_version" />)
    I have tried also to modify the manifest:

    <uses-sdk android:minSdkVersion="4" android:targetSdkVersion="26"/>

    but nothing changes
     
    Last edited: Jul 22, 2019
  2. Erel

    Erel Administrator Staff Member Licensed User

    What do you need this permission for?

    I don't see anywhere in your code where you request it.
     
  3. dibesw

    dibesw Active Member Licensed User

    in fact for this I don't understand. I confirm that I do not ask for any authorization for this.
    This problem I have only for Asus zenfone3
     
  4. dibesw

    dibesw Active Member Licensed User

    SOLVED
    add this to manifest

    Code:
    AddPermission(android.permission.READ_PHONE_STATE)
    AddPermission(android.permission.CALL_PHONE)
    AddPermission(android.permission.ACCESS_COARSE_LOCATION)
     
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