Make Phone call from inside Basic4anroid ?

davidmd

Member
Licensed User
Longtime User
Hi
I wish to make a button
inside the App
That click will lead
To call specific number , Open The Phone dialer
with Specific Number
Or Open SMS with specific Number.
How can i do ot ?

Thanks!!!
 

Rui

Member
Licensed User
Longtime User
To open The Phone dialer you can do it this way

B4X:
Dim i As Intent
i.Initialize(i.ACTION_VIEW, "tel:123456789")
StartActivity(i)

SMS

B4X:
 Dim i As Intent
 i.Initialize(i.ACTION_VIEW, "sms:0123456789")
 i.PutExtra("sms_body", "write text here")
 StartActivity(i)
Requires a reference to the Phone library

you can also do it without opening the phone dialer
 
Upvote 0

mcmanu

Active Member
Licensed User
Longtime User
hi

Thanks for this example :)
I am Programming a Siri like app, untill now its working fine, she gives me answers to questions, open apps, open websites ect.
Now i want to programm that when i say, please call ritchie, that "Siri" is calling Ritchie. Is it possible? I dont know how to do that, i tried it with the given examples here, but i dont know how to Programm that "she" calls somebody when i say call "blabla". so "she have to search "blabla" in my contacts and then call that person.

Can somebody help me? ;
 
Last edited:
Upvote 0

vb1992

Well-Known Member
Licensed User
Longtime User
Try using the contacts library with that intent

B4X:
Dim Contacts1 As Contacts
Dim listOfContacts As List
listOfContacts = Contacts1.FindByName("John", False)
For i = 0 To listOfContacts.Size - 1
    Dim Contact As Contact
    Contact = listOfContacts.Get(i)
    Log(Contact) 'will print the fields to the LogCat
    Dim photo As Bitmap
    photo = Contact.GetPhoto
    If photo <> Null Then Activity.SetBackgroundImage(photo)
    Dim emails As Map
    emails = Contact.GetEmails
    If emails.Size > 0 Then Log("Email addresses: " & emails)
    Dim phones As Map
    phones = Contact.GetPhones
    If phones.Size > 0 Then Log("Phone numbers: " & phones)
Next
 
Upvote 0

mcmanu

Active Member
Licensed User
Longtime User
Thanks

Thank you, i tried this example before but it doesnt work, so i updated my Phone Library form 1.60 to 1.70 and now With contacts2 it works fine.
Thank you ;)
Here is my solution ;)

i say Call home, then in edittext.text="call home" with the substring she search for home in my contacts and calls him or her ;)

Sub Button1_Click
Dim Contacts2 As Contacts2
Dim listOfContacts As List
edittext1.Text.SubString(5)
listOfContacts = Contacts2.FindByName(edittext1.text.substring(5), False, True, True)
For i = 0 To listOfContacts.Size - 1
Dim Contact As Contact
Contact = listOfContacts.Get(i)
Log(Contact) 'will print the fields to the LogCat
Dim photo As Bitmap
photo = Contact.GetPhoto
If photo <> Null Then imageview1.bitmap=photo
imageview1.Visible=True
Dim phones As Map
phones = Contact.GetPhones
If phones.Size > 0 Then Log(phones)

Next
Dim p As PhoneCalls
StartActivity(p.Call(Contact.PhoneNumber))
End Sub
 
Last edited:
Upvote 0

mcmanu

Active Member
Licensed User
Longtime User
hi

Yes ;)
Jeah you right ;) it a lot of work ;)
Now i try to programm that "she" can play songs from the stored mp3´s ;)
And then i try to give her a better voice ;)


Thank you for your help ;)
 
Upvote 0

kanaida

Active Member
Licensed User
Longtime User
The voice is determined by the text to speech engine, the default android one is like microsoft sam lol... not very pleasing, not very good for gps directions haha. There's a really good one called SVOX, I like the sexy UK victoria girl voice lol of course other people won't hear it, but it's better for the good ol' dev phone :)
 
Upvote 0

rbsoft

Active Member
Licensed User
Longtime User
I used to have John Cleese for TomTom - was great!

Rolf
 
Upvote 0

RUNO

Active Member
Licensed User
Longtime User
Hi all .
I need help please.
Whenever declare a variable of type phone does not allow me the definition of phonecalls .
 
Upvote 0

rbsoft

Active Member
Licensed User
Longtime User
Did you add the phone library to your project?

Rolf
 
Upvote 0

RUNO

Active Member
Licensed User
Longtime User
Yes i did .
1430290345931.jpg
 
Last edited:
Upvote 0

rbsoft

Active Member
Licensed User
Longtime User
This works for me:

Sub MakeCall(FonNum as String)
Dim p As PhoneCalls
StartActivity(p.Call(FonNum))​
End Sub

I did not dim p in Globals, only in the sub MakeCall.

Rolf
 
Last edited:
Upvote 0

fanfalveto

Active Member
Licensed User
Longtime User
Don´t work :(
B4X:
Sub Label2_Click
numero=Label2.Text
datos (numero)
End Sub

Sub datos (nu As String)
Dim p As PhoneCalls
StartActivity(p.Call(nu))
End Sub
B4X:
B4A version: 5.02 (1)
Parsing code.    Error
Error parsing program.
Error description: La cadena de entrada no tiene el formato correcto.
Occurred on line: 63
StartActivity(p.Call(nu))
Any idea?
Thanks
 
Upvote 0

fanfalveto

Active Member
Licensed User
Longtime User
Apologies for not responding earlier, problem solved , I do not know why but closing and reopening B4A all worked well
Thank you
 
Upvote 0

Matthew Miranda

New Member
To open The Phone dialer you can do it this way

B4X:
Dim i As Intent
i.Initialize(i.ACTION_VIEW, "tel:123456789")
StartActivity(i)

SMS

B4X:
 Dim i As Intent
i.Initialize(i.ACTION_VIEW, "sms:0123456789")
i.PutExtra("sms_body", "write text here")
StartActivity(i)
Requires a reference to the Phone library

you can also do it without opening the phone dialer
hi how can you do it without opening the dialer. but just calling it directly by pressing the button
 
Upvote 0
Top