System.openURL - anonymous call

Good evening

I’m building an app that will have to control a GSM module via sms and calls, I need to make a call also as an anonymous number.

I’m using system.openURL (url), but when I enter the #31# in front of the phone number to call (necessary for an anonymous call in Italy) the app does not generate the call.

I enclose the photo of the error that gives me when I try to call anonymous.

Thanks to those who want to help me

Good job everyone

Hi,

I think you need to share the code part which does not trigger, or there is nothing to go on.

Forgive me

I attach the code of the button that makes me start a call.

Precise that by raising the #31# the call part, but in Italy to make an anonymous call must be entered in front of the number #31#.

Thanks for your help

button6 = widget.newButton{

left = 282,

top = 24,

width = 20,                                   

height = 20,

defaultFile = “grafiche/androidcall_white.png”,

onEvent = function(e)

if e.phase == “began” then

elseif e.phase == “ended” then

      if result.numero_telefono == nil or result.numero_telefono == “” then

  native.showAlert( “FOX ALARM”, “Inserire il numero del Whisper nel campo impostazioni”, { “OK”} )

 else

       system.openURL (“tel:”…"#31#"…result.numero_telefono)

      end

end

end

}   

Hi again,

Can be string formatting and that # is causing issues and you need to escape it.

Can you try this?

local url=“tel:’”…"’#31#’"…result.numero_telefono

system.openURL (url)

sorry, it should be:

local url=“tel:’”…"’#31#’"…result.numero_telefono…"’"

EDIT or local url=“tel:#31#’”…result.numero_telefono…"’"

no reason to separate the first 2 parameters, or so it seems to me.

It does not work anyway

Seems to be the # that bothers me, if I put the + works, but with # the call does not start.

Putting the string you suggested to me, the situation shown in the picture shows up

thank you very much

Hmm

Usually when a string dont work (needs escaping) you’ll get an error message, so i’m not really sure here.

I’ve not working with phone functions yet, so you know more than me about it.

Perhaps someone else can help.

Cheers!

Try url encoding the number and # symbols, I know that iOS prevents any tel: calls with # in them:

https://developer.apple.com/library/content/featuredarticles/iPhoneURLScheme_Reference/PhoneLinks/PhoneLinks.html

Specifically, if a URL contains the * or # characters, the Phone app does not attempt to dial the corresponding phone number. 

I’m not sure if turning the # into %23 will help or not, but it’s worth a try:

local url = require("socket.url") local function urlencode(str) if str then str = string.gsub(str, "%s", "+") str = url.escape(str) end return str or "" end local user\_tel = "123456789" local finalTelephoneNumber = string.urlencode("#31#"..user\_tel) system.openURL ("tel:'"..finalTelephoneNumber)

Thanks for your help

I tried to paste your code but it returns an error

unfortunately I am not an expert in encode.

I attach error photos

oops, change 

local finalTelephoneNumber = string.urlencode("#31#"..user\_tel)

to

local finalTelephoneNumber = urlencode("#31#"..user\_tel)

It works!!!

Thanks so much!

You really raised a problem!

Thanks again to everyone for the help

Best regards and good work

It might be worth checking what happens with telephone numbers that contain * or - . If those characters are not valid in Italian telephone numbers or you know for certain that your app will never use them then don’t worry about it.

Also, be aware that if Apple decide they don’t like you directing to a number with the # symbol, then they may reject the app. Hopefully they are ok with this though.

Yes, my App will make a call with # by typing a special button, because I have a GSM module that if it receives a call with an anonymous number makes a particular command.

For apple I will explain why # and see what happens

As soon as I get home I try to compile the app also on ios let’s see if it works there too

If something does not work I will write

Thank you so much again

Hi,

I think you need to share the code part which does not trigger, or there is nothing to go on.

Forgive me

I attach the code of the button that makes me start a call.

Precise that by raising the #31# the call part, but in Italy to make an anonymous call must be entered in front of the number #31#.

Thanks for your help

button6 = widget.newButton{

left = 282,

top = 24,

width = 20,                                   

height = 20,

defaultFile = “grafiche/androidcall_white.png”,

onEvent = function(e)

if e.phase == “began” then

elseif e.phase == “ended” then

      if result.numero_telefono == nil or result.numero_telefono == “” then

  native.showAlert( “FOX ALARM”, “Inserire il numero del Whisper nel campo impostazioni”, { “OK”} )

 else

       system.openURL (“tel:”…"#31#"…result.numero_telefono)

      end

end

end

}   

Hi again,

Can be string formatting and that # is causing issues and you need to escape it.

Can you try this?

local url=“tel:’”…"’#31#’"…result.numero_telefono

system.openURL (url)

sorry, it should be:

local url=“tel:’”…"’#31#’"…result.numero_telefono…"’"

EDIT or local url=“tel:#31#’”…result.numero_telefono…"’"

no reason to separate the first 2 parameters, or so it seems to me.

It does not work anyway

Seems to be the # that bothers me, if I put the + works, but with # the call does not start.

Putting the string you suggested to me, the situation shown in the picture shows up

thank you very much

Hmm

Usually when a string dont work (needs escaping) you’ll get an error message, so i’m not really sure here.

I’ve not working with phone functions yet, so you know more than me about it.

Perhaps someone else can help.

Cheers!

Try url encoding the number and # symbols, I know that iOS prevents any tel: calls with # in them:

https://developer.apple.com/library/content/featuredarticles/iPhoneURLScheme_Reference/PhoneLinks/PhoneLinks.html

Specifically, if a URL contains the * or # characters, the Phone app does not attempt to dial the corresponding phone number. 

I’m not sure if turning the # into %23 will help or not, but it’s worth a try:

local url = require("socket.url") local function urlencode(str) if str then str = string.gsub(str, "%s", "+") str = url.escape(str) end return str or "" end local user\_tel = "123456789" local finalTelephoneNumber = string.urlencode("#31#"..user\_tel) system.openURL ("tel:'"..finalTelephoneNumber)