Italian [B4A] eseguire una telefonata [RISOLTO]

Aldo's

Active Member
Licensed User
Come da titolo devo eseguire una chiamata telefonica.
Ho aggiunto in manifest:
B4X:
AddPermission(android.permission.CALL_PRIVILIGED)
e nel programma eseguo questo codice:
B4X:
    Dim Tel As String
    SQL1.Initialize(DBDir,DBArk,True)
    RS1=SQL1.ExecQuery("SELECT * FROM telefoni WHERE id = " & iIDTelefono & ";")
    Do While RS1.NextRow
        Tel = RS1.GetString("telefono")
    Loop
    SQL1.close
    Dim result As Int
    result=Msgbox2("Vuoi telefonare al numero " & Tel & "?","Telefonata","SI","","NO",Null)
    If result=DialogResponse.Positive Then
        Dim i As Intent
        i.Initialize(i.ACTION_CALL, "+39" & Tel)
        StartActivity(i)
    End If
Alla riga relativa allo StartActivity(i) mi regala un errore.
Cosa c'è di sbagliato in questa procedura?
 

Star-Dust

Expert
Licensed User
Longtime User
Quale errore? Non sarà la mancanza di qualche permesso?

(Io suggerisco di digitare il numero dalla tastiera, la telefonata parte lo stesso)
 

Aldo's

Active Member
Licensed User
(Io suggerisco di digitare il numero dalla tastiera, la telefonata parte lo stesso)
Il metodo è sicuramente ineccepibile, però che ci staremmo a fare noi?🤣
Quale errore? Non sarà la mancanza di qualche permesso?
Sarà sicuro la mancanza di qualche permesso, ma non ho trovato niente in linea che mi possa aiutare a mettere qualche idea più chiara nella mia testa.
Secondo te quali permessi è necessario invocare?
 

Star-Dust

Expert
Licensed User
Longtime User
Il metodo è sicuramente ineccepibile, però che ci staremmo a fare noi?🤣

Sarà sicuro la mancanza di qualche permesso, ma non ho trovato niente in linea che mi possa aiutare a mettere qualche idea più chiara nella mia testa.
Secondo te quali permessi è necessario invocare?
Fammi vedere l'errore che ti segnala
 

Aldo's

Active Member
Licensed User
Fammi vedere l'errore che ti segnala
Ecco:

Error occurred on line: 359 (Contatto)
java.lang.SecurityException: Permission Denial: starting Intent { act=android.intent.action.CALL dat=tel:xxxxxxxxxx flg=0x20000 cmp=com.android.server.telecom/.components.UserCallActivity } from ProcessRecord{9fc146a 13352:b4a.personaltools/u0a250} (pid=13352, uid=10250) with revoked permission android.permission.CALL_PHONE
at android.os.Parcel.createExceptionOrNull(Parcel.java:2385)
at android.os.Parcel.createException(Parcel.java:2369)
at android.os.Parcel.readException(Parcel.java:2352)
at android.os.Parcel.readException(Parcel.java:2294)
at android.app.IActivityTaskManager$Stub$Proxy.startActivity(IActivityTaskManager.java:4276)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1723)
at android.app.Activity.startActivityForResult(Activity.java:5377)
at android.app.Activity.startActivityForResult(Activity.java:5335)
at android.app.Activity.startActivity(Activity.java:5721)
at android.app.Activity.startActivity(Activity.java:5674)
at anywheresoftware.b4a.keywords.Common.StartActivity(Common.java:857)
at b4a.personaltools.contatto._ltel_longclick(contatto.java:1314)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:351)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:193)
at anywheresoftware.b4a.objects.ViewWrapper$2.onLongClick(ViewWrapper.java:90)
at android.view.View.performLongClickInternal(View.java:8240)
 

Xfood

Expert
Licensed User
Ecco:

Error occurred on line: 359 (Contatto)
java.lang.SecurityException: Permission Denial: starting Intent { act=android.intent.action.CALL dat=tel:xxxxxxxxxx flg=0x20000 cmp=com.android.server.telecom/.components.UserCallActivity } from ProcessRecord{9fc146a 13352:b4a.personaltools/u0a250} (pid=13352, uid=10250) with revoked permission android.permission.CALL_PHONE
at android.os.Parcel.createExceptionOrNull(Parcel.java:2385)
at android.os.Parcel.createException(Parcel.java:2369)
at android.os.Parcel.readException(Parcel.java:2352)
at android.os.Parcel.readException(Parcel.java:2294)
at android.app.IActivityTaskManager$Stub$Proxy.startActivity(IActivityTaskManager.java:4276)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1723)
at android.app.Activity.startActivityForResult(Activity.java:5377)
at android.app.Activity.startActivityForResult(Activity.java:5335)
at android.app.Activity.startActivity(Activity.java:5721)
at android.app.Activity.startActivity(Activity.java:5674)
at anywheresoftware.b4a.keywords.Common.StartActivity(Common.java:857)
at b4a.personaltools.contatto._ltel_longclick(contatto.java:1314)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:351)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:193)
at anywheresoftware.b4a.objects.ViewWrapper$2.onLongClick(ViewWrapper.java:90)
at android.view.View.performLongClickInternal(View.java:8240)
Non sono un esperto ma questo permesso ?

with revoked permission android.permission.CALL_PHONE
 

Aldo's

Active Member
Licensed User
Sono arrivato qui:
B4X:
Private Sub lTel_LongClick
    iIDTelefono=iIDTel(clvTelefoni.GetItemFromView(Sender))
    SQL1.Initialize(DBDir,DBArk,True)
    RS1=SQL1.ExecQuery("SELECT * FROM telefoni WHERE id = " & iIDTelefono & ";")
    Do While RS1.NextRow
        Tel = RS1.GetString("telefono")
    Loop
    SQL1.close
    Dim ro As Object = Msgbox2Async("Vuoi telefonare al numero " & Tel & "?","Telefona al contatto","SI","","NO",Null,False)
    Wait For (ro) Msgbox_Result (res As Int)
    If res=DialogResponse.POSITIVE Then
        Telefona
    End If
End Sub

Private Sub Telefona
    rp.CheckAndRequest(rp.PERMISSION_CALL_PHONE)
    Wait For Activity_PermissionResult(Permission As String, Result As Boolean)
    Log(Permission)
    Log(Result)
    If Result=True Then
        Log(Tel)
        Tel="+39" & Tel
        Dim ph As PhoneCalls
        StartActivity(ph.Call(Tel))
    Else
        Log("No permesso")
    End If
End Sub

Il risultato che ottengo è che non mi esegue nessun Log() nella Sub Telefona.
Il permesso, nella gestione applicazione, risulta correttamente concesso (ha correttamente eseguito la richiesta).
Sembra quasi che alle righe:
B4X:
    rp.CheckAndRequest(rp.PERMISSION_CALL_PHONE)
    Wait For Activity_PermissionResult(Permission As String, Result As Boolean)
non esegua più nulla.
Come mi consigliate di andare avanti?
 

Aldo's

Active Member
Licensed User
Grandissimo Xfood, ho risolto in questo modo:
B4X:
Private Sub lTel_LongClick
    iIDTelefono=iIDTel(clvTelefoni.GetItemFromView(Sender))
    SQL1.Initialize(DBDir,DBArk,True)
    RS1=SQL1.ExecQuery("SELECT * FROM telefoni WHERE id = " & iIDTelefono & ";")
    Do While RS1.NextRow
        Tel = RS1.GetString("telefono")
    Loop
    SQL1.close
    Dim ro As Object = Msgbox2Async("Vuoi telefonare al numero " & Tel & "?","Telefona al contatto","SI","","NO",Null,False)
    Wait For (ro) Msgbox_Result (res As Int)
    If res=DialogResponse.POSITIVE Then
        rp.CheckAndRequest(rp.PERMISSION_CALL_PHONE)
        Wait For Activity_PermissionResult(Permission As String, Result As Boolean)
    End If
End Sub

Private Sub B4XPage_Permissionresult(Permission As String,Result As Boolean)
    If Result=True Then
        Tel="+39" & Tel
        Dim ph As PhoneCalls
        StartActivity(ph.Call(Tel))
    End If
End Sub
Grazie a tutti
 

Xfood

Expert
Licensed User
Non credo che sia corretto quello che hai fatto,
Purtroppo non posso usare il pc, appena posso ti faccio un piccolo esempio.
 

Xfood

Expert
Licensed User
Grandissimo Xfood, ho risolto in questo modo:
B4X:
Private Sub lTel_LongClick
    iIDTelefono=iIDTel(clvTelefoni.GetItemFromView(Sender))
    SQL1.Initialize(DBDir,DBArk,True)
    RS1=SQL1.ExecQuery("SELECT * FROM telefoni WHERE id = " & iIDTelefono & ";")
    Do While RS1.NextRow
        Tel = RS1.GetString("telefono")
    Loop
    SQL1.close
    Dim ro As Object = Msgbox2Async("Vuoi telefonare al numero " & Tel & "?","Telefona al contatto","SI","","NO",Null,False)
    Wait For (ro) Msgbox_Result (res As Int)
    If res=DialogResponse.POSITIVE Then
        rp.CheckAndRequest(rp.PERMISSION_CALL_PHONE)
        Wait For Activity_PermissionResult(Permission As String, Result As Boolean)
    End If
End Sub

Private Sub B4XPage_Permissionresult(Permission As String,Result As Boolean)
    If Result=True Then
        Tel="+39" & Tel
        Dim ph As PhoneCalls
        StartActivity(ph.Call(Tel))
    End If
End Sub
Grazie a tutti


Piu o meno e cosi,
B4X:
rp.CheckAndRequest(rp.PERMISSION_CALL_PHONE)
	Wait For B4XPage_PermissionResult (Permission As String, Result As Boolean)
	If Result = False Then
		toast.Show("No permission!")
		Return
	End If
        Tel="+39" & Tel
        Dim ph As PhoneCalls
        StartActivity(ph.Call(Tel))
        'Startactyvity in b4xpage non dovrebbe ssere usato cosi
	B4XPages.ShowPageAndRemovePreviousPages("calltel")
 
Last edited:

Xfood

Expert
Licensed User
Scusami, ma con solo il telefono faccio fatica a darti un esempio completo, pero ti ho dato l'idea di come fare
 

Aldo's

Active Member
Licensed User
Piu o meno e cosi,
B4X:
rp.CheckAndRequest(rp.PERMISSION_CALL_PHONE)
    Wait For B4XPage_PermissionResult (Permission As String, Result As Boolean)
    If Result = False Then
        toast.Show("No permission!")
        Return
    End If
        Tel="+39" & Tel
        Dim ph As PhoneCalls
        StartActivity(ph.Call(Tel))
        'Startactyvity in b4xpage non dovrebbe ssere usato cosi
    B4XPages.ShowPageAndRemovePreviousPages("calltel")
Tutto questo lo metti in B4XPage_Permissionresult?
 

Aldo's

Active Member
Licensed User
Se post il progettino appena ho un pc lo controllo, ma se na parla sabato
Creo progettino semplice e condivido... quando puoi va bene
 

Aldo's

Active Member
Licensed User
Come promesso ho creato un progettino semplice (e senza tanti controlli) che è funzionante... nel senso che effettua la chiamata telefonica al numero selezionato.

Se è migliorabile la procedura di avvio della telefonata... meglio.
Grazie a tutti
 

Attachments

  • SimplePhone.rar
    7.9 KB · Views: 110

Xfood

Expert
Licensed User
Non posso guardare neanche oggi il tuo progetto, domani avro finalmente accesso ad un pc,
Posso gia consigliarti una cosa,
Se fai uso di b4xpage, non DEVI usare piu le activity, ma le page, ed usare questo metodo indicato nel post di @LucaMs per richiamare una funzione contenuta in una certa pagina.
 
Top