Android Question Open phone app with number prefilled but not calling?

Sandman

Expert
Licensed User
Longtime User
I know we have code in the forum that show how to instantly call a number via the use of RealtimePermissions.

But I've seen many apps in the Play Store just opening the phone app with a number prefilled. So, not actually doing any calling, that's left for the user to do. I imagine using that solution would not require the user to give a permission?

I think I've seen code in the forum for this, but I can't seem to find it. (I suspect it drowns in the many, many threads about phones and numbers and whatnot.)

Does anyone know anything about this? Perhaps even an url to a solution?
 

teddybear

Well-Known Member
Licensed User
The code will work.
B4X:
Sub Button1_Click
    Dim p As PhoneCalls
    Dim rp As RuntimePermissions
    rp.CheckAndRequest(rp.PERMISSION_CALL_PHONE)
    Wait For Activity_PermissionResult (Permission As String, Result As Boolean)
    If Result = False Then Return
    Dim jo As JavaObject
    jo.InitializeContext
    jo.RunMethod("dialer", Array("12345678901"))
End Sub

#If JAVA
import android.content.Intent;
import android.net.Uri;
public void dialer(String pn) {
    Intent intent = new Intent(Intent.ACTION_DIAL,Uri.parse("tel:" +pn));
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    startActivity(intent);
   }
#End If
 
Upvote 0

Sandman

Expert
Licensed User
Longtime User
Thanks, your code gave me the clue I needed: "ACTION_DIAL". (On a separate note your code seems to be a mix of two different solutions, and using unneeded inline java.)

Here's the solution:
B4X:
Dim i As Intent
i.Initialize("android.intent.action.DIAL", "tel:+1 202 456 1414")
StartActivity(i)

It's worth noting that we can't use a built-in constant for intent action, as the list isn't complete. I found the actual constant value to use on this page.


To summarize what's going on here:

- One can either initiate a call instantly (using Intent.ACTION_CALL). This will require that the user give a permission. This code is an example of this.

... or ...

- One can open the caller app with a number prefilled, requiring the user to actually initiate the call. This does not require a permission. The code above in this post is an example of this.
 
Upvote 1
Cookies are required to use this site. You must accept them to continue using the site. Learn more…