Android Question [Solved] Read Phone State

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.


B4X:
Dim p As PhoneSms
...
...
Sub Activity_Create(FirstTime As Boolean)
    rp.CheckAndRequest(rp.PERMISSION_SEND_SMS)
End Sub
B4X:
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(0, 0) 'Listen to GPS with no filters.
    FusedLocationProvider1.Initialize("FusedLocationProvider1")
    FusedLocationProvider1.Connect
End Sub
B4X:
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...

B4X:
   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:

B4X:
'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:

dibesw

Active Member
Licensed User
What do you need this permission for?

I don't see anywhere in your code where you request it.
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
 

dibesw

Active Member
Licensed User
SOLVED
add this to manifest

B4X:
AddPermission(android.permission.READ_PHONE_STATE)
AddPermission(android.permission.CALL_PHONE)
AddPermission(android.permission.ACCESS_COARSE_LOCATION)
 
Top