Can we invoke a phone call from mosync?

34 posts / 0 new
Last post
hariprasad
hariprasad's picture
Offline
Joined: 9 Aug 2011
Posts:
Can we invoke a phone call from mosync?

My app is on wormhole. i will get some phone number from server. i have to initiate a call when user clicks on that number. Is this possible?

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Sam Pickard
rival's picture
Offline
Mobile Archmage
Joined: 19 Mar 2009
Posts:

Yep, and in three ways. The easiest in HTML5 is to form a URL tel:// + number, but you can use a hard hook and use the MoSync functions maPlatformRequest("tel:// + number"); or include IX_CALL.h and use the function maCallDial(number);

hariprasad
hariprasad's picture
Offline
Joined: 9 Aug 2011
Posts:

else if (message.is("phone")) {
String num = message.getParam("number");
String x = "tel:"+num;
char script[128];
int ret = maPlatformRequest(x.c_str());
if(ret == 0){
getWebView()->callJS("alert('Processed')");
}
else{
sprintf(script, "alert(Error - %d)", ret);
getWebView()->callJS(script);
}
}

i am getting NaN as alert. am i doing correct?

Sam Pickard
rival's picture
Offline
Mobile Archmage
Joined: 19 Mar 2009
Posts:

Hmm - is the NaN alert from JavaScript? I've not seen it as a C++ error. Is it happening on the maPlatformRequest? On Android or iPhone, I would try maCallDial rather than maPlatformRequest.

hariprasad
hariprasad's picture
Offline
Joined: 9 Aug 2011
Posts:

HI Sam..
i made change as you suggested.(I tried all possibilities you suggested)

getWebView()->callJS("alert(Mobile number is - "+num+")");
int ret = maCallDial(num.c_str());
if (ret == 0 ) {
getWebView()->callJS("alert('Processed')");
} else {
sprintf(script, "alert(Error - %d)", ret);
getWebView()->callJS(script);
}

I am attaching adb log..
I/@@@ MoSync( 950): MoSyncWebViewClient.shouldOverrideUrlLoading url: mosync://phone?number=%27855-789-7868%27
I/@@@ MoSync( 950): Hard hook detected: mosync://.*
I/maWriteLog( 950): mobile number - 8557897868
I/@@@ MoSync( 950): MoSyncWebChromeClient.onConsoleMessage: SyntaxError: Parse error
E/Web Console( 950): SyntaxError: Parse error at undefined:1
I/@@@ MoSync( 950): MoSyncWebChromeClient.onJsAlert: NaN

Sam Pickard
rival's picture
Offline
Mobile Archmage
Joined: 19 Mar 2009
Posts:

OK, this just looks like a simple error here:
sprintf(script, "alert(Error - %d)", ret);

where I think that the JS format should have some sort of text delimiter, like you did here "alert('Processed')"

Try
sprintf(script, "alert('Error - %d')", ret);
or
sprintf(script, "alert(\"Error - %d\")", ret);

Did the call start?

hariprasad
hariprasad's picture
Offline
Joined: 9 Aug 2011
Posts:

Hi Sam,
Thanks for JS correction. but my call didn't start and the log says

I/@@@ MoSync( 998): Hard hook detected: mosync://.*
I/maWriteLog( 998): mobile number - 8557897868
I/@@@ MoSync( 998): MoSyncWebChromeClient.onConsoleMessage: SyntaxError: Parse error
E/Web Console( 998): SyntaxError: Parse error at undefined:1
I/@@@ MoSync( 998): MoSyncWebChromeClient.onJsAlert: Error - -1

what it mean the return value is -1?

Sam Pickard
rival's picture
Offline
Mobile Archmage
Joined: 19 Mar 2009
Posts:

I think you've got two different errors here, and its pretty difficult to tell them apart with the code snippets you've sent. You seem to have a JS error in the webview, which is probably nothing other than a malformed functional call, and you've got the call not starting, but apparently no error message for the call being generated. Can you share a bit more code?

hariprasad
hariprasad's picture
Offline
Joined: 9 Aug 2011
Posts:

Hi Sam,

JS function:

function callPhone(n){
	var num = rates[n][7];
	bridge.messagehandler.send( {messageName: "phone", number : "'"+rates[n][7]+"'"} , null);
}

rates[n][7] is an array having phone number : 855-789-7868

in cpp file:

if (message.is("phone")) {
                        //get phone number from JS
			String number = message.getParam("number");

                         //remove quotes at the start and end
			String num = number.substr(1,number.length()-2);

                       // remove "-"s 
			int found;
			found=num.findFirstOf('-');
			  while (found!=String::npos)
			  {
			    num.remove(found,1);
			    found=num.findFirstOf('-',found+1);
			  }

			lprintfln("mobile number -  %s", num.c_str());

			char script[128];
			getWebView()->callJS("alert(Mobile number is - "+num+")");

                        //initiate call.
			int ret = maCallDial(num.c_str());
			if (ret == 0 ) {
				getWebView()->callJS("alert('Processed')");
			} else {
				sprintf(script, "alert('Error - %d')", ret);
				getWebView()->callJS(script);
			}
}
hariprasad
hariprasad's picture
Offline
Joined: 9 Aug 2011
Posts:

HI sam
please ignore my previous comment.. actually... the errors are coming from js are cleared but i am unable to initiate the call....

code on js

function callPhone(n){
//	var num = rates[n][7];
//	num.replace(/-/g,"");
	bridge.messagehandler.send( 
			 {messageName: "phone",
				 number : rates[n][7].replace(/-/g,"")}
			 , null);
}

code in cpp

if (message.is("phone")) {
			String number = message.getParam("number");
			char script[128];
			sprintf(script, "alert('mobile - %s')", number.c_str());
			getWebView()->callJS(script);
			int ret = maCallDial(number.c_str());
			if (ret == 0 ) {
				getWebView()->callJS("alert('Processed')");
			} else {
				sprintf(script, "alert('Error - %d')", ret);
				getWebView()->callJS(script);
			}
		}

log shows as.

I/@@@ MoSync( 1162): MoSyncWebViewClient.shouldOverrideUrlLoading url: mosync://phone?number=8557897868
I/@@@ MoSync( 1162): Hard hook detected: mosync://.*
I/@@@ MoSync( 1162): MoSyncWebChromeClient.onJsAlert: mobile - 8557897868
I/@@@ MoSync( 1162): MoSyncWebChromeClient.onJsAlert: Error - -1
Sam Pickard
rival's picture
Offline
Mobile Archmage
Joined: 19 Mar 2009
Posts:

-1 seems to just mean 'error' and not give me anything else. I'll look into it.

hariprasad
hariprasad's picture
Offline
Joined: 9 Aug 2011
Posts:

Hi Sam,

I tried with 'tel://+number' but struck up with error: The protocol is not supported.

I/@@@ MoSync(  681): MoSyncWebViewClient.onPageFinished url: file:///data/data/com.mosync.app_BBJQApp/files/mobjectifyNew.html#LenderRates
I/@@@ MoSync(  681): MoSyncWebViewClient.shouldOverrideUrlLoading url: tel://855-789-7868
I/@@@ MoSync(  681): MoSyncWebViewClient.onPageStarted url: tel://855-789-7868
I/@@@ MoSync(  681): MoSyncWebViewClient.onReceivedError url: tel://855-789-7868
 error: The protocol is not supported.
I/@@@ MoSync(  681): MoSyncWebViewClient.onPageStarted url: tel://855-789-7868
I/@@@ MoSync(  681): MoSyncWebViewClient.onPageFinished url: tel://855-789-7868
hariprasad
hariprasad's picture
Offline
Joined: 9 Aug 2011
Posts:

Any one ran into this issue? any workarounds? I am only man getting this error?

gullet
gullet's picture
Offline
Joined: 11 Dec 2011
Posts:

Hi,

I'm looking at making a call in the background, so that the user still sees the screen in my app. A HTML href-tag, I think will dispatch the user to the device's native call service. maPlatformRequest() has the sound of doing the same. Is maCallDial() the way forward to achieve this?

Thanks in advance.

Sam Pickard
rival's picture
Offline
Mobile Archmage
Joined: 19 Mar 2009
Posts:

Hi, maCallDial is the best way to do this from an HTML app on smartphones. maPlatformRequest("tel://1234"); is dependent on J2ME platform support. 

tgruse
tgruse's picture
Offline
Joined: 19 Jan 2012
Posts:

Hi, I'm trying to invoke a phone call from a native ui with android. I tried maPlatformRequest with "tel:" and "tel://" prefix without success. maCallDial does also not work. I checked all permissions. What else can I try? I also need this for "mailto:" and send sms.
Thanks and best regards

gullet
gullet's picture
Offline
Joined: 11 Dec 2011
Posts:

I can't figure out how to make maCallDial work. I would like to target Android and iPhone for an app that uses background calling (not invoking the call app of the native OS), but initiate a call from my own app.

Any more hints, before I try some other method/framework?

Iraklis Rossis
Iraklis Rossis's picture
Offline
Mobile Wizard
Joined: 3 Aug 2011
Posts:

With the risk of being completely wrong, I don't think you could initiate a call on iPhone without using the Apple's call interface.

gullet
gullet's picture
Offline
Joined: 11 Dec 2011
Posts:

Iraklis,

Thanks, but currently I'm trying/prototyping with Android. Once it works there, I'll try it on iPhone/WinPhone later.

Are there any updates made to maCallDial in the 3.0 release?

Thanks in advance.

Iraklis Rossis
Iraklis Rossis's picture
Offline
Mobile Wizard
Joined: 3 Aug 2011
Posts:

Not that I know of. Again, might be terribly wrong, but I think that android can only monitor call information, not initiate calls.

Have you tried using document.location = "tel://" + number; in your javascript code? At the very least, it should bring up the dialing interface.

gullet
gullet's picture
Offline
Joined: 11 Dec 2011
Posts:

No, I haven't tried it, because I need to have control over the display (UI) in my app all the time. If I can't initiate a call outside the phone interface, then MoSync is not my choice, but I was under the impression that it might work, hence the question regarding the maCallDial()-method.

pablogomezp
pablogomezp's picture
Offline
Mobile Conjurer
Joined: 26 Nov 2011
Posts:

Hello,

I tried in two different ways:

The following works on Android, it open the dial pad with the number written on it ready to start the phone call. But in iphone doesn't.

 
     window.location="tel:+43XXXXXXXXXXX"

The following one doesnt work in both Android nor Iphone.

 
if(command == "PhoneCall"){
		String phoneNumber = message.getParam("phoneNumber");
		int phoneCallResult=maCallDial	(phoneNumber.c_str());
		lprintfln("%s: Calling phone number: %s  Result: %i",Common::APP_LOG.c_str(),phoneNumber.c_str(),phoneCallResult);
}

This is what I see in the log:

 
 APP-LOG: Calling phone number: +43XXXXXXXXX  Result: -1

The X's are logically numbers.

Am I missing something?

Thanks

Sam Pickard
rival's picture
Offline
Mobile Archmage
Joined: 19 Mar 2009
Posts:

Hi, there is a known issue with maCallDial on Android. You can follow the progess here http://jira.mosync.com/browse/MOSYNC-2022

dtuzikov
dtuzikov's picture
Offline
Joined: 18 Jan 2012
Posts:

Hi, Is there any way to call number from mosync nativeui app on android now?

Ovidiu
ovidiu's picture
Offline
Mobile Wizard
Joined: 27 Jan 2011
Posts:

Hi,

It's on the priority list for 3.1 (I estimate a mid next week fix with a nightly release by the end of the week)

Teddybee
Teddybee's picture
Offline
Mobile Conjurer
Joined: 5 Jan 2012
Posts:

Hi All,

Is that phone dial working too on Maiu moblet? 

We tried  maPlatformRequest("tel://1234") on android, and unfortunately it didn't do anything, also the default browser can't call the dialer with that url. But in Opera it is working.

 

Sam Pickard
rival's picture
Offline
Mobile Archmage
Joined: 19 Mar 2009
Posts:

Hi, there is a known issue with dialling in Android. It will be fixed in MoSync 3.1 (due next month).

Ovidiu
ovidiu's picture
Offline
Mobile Wizard
Joined: 27 Jan 2011
Posts:

What version of MoSync SDK do you use (the problem has been already fixed and released in the nightly builds)

Teddybee
Teddybee's picture
Offline
Mobile Conjurer
Joined: 5 Jan 2012
Posts:

We tried out the 05.02 beta binary also, but we couldn't make it work.

Ovidiu
ovidiu's picture
Offline
Mobile Wizard
Joined: 27 Jan 2011
Posts:

I tried it myself right now and it works but you might have to check to see if you have the "Phone Calls" permission checked (see image)

 

proj_prop.jpg
Teddybee
Teddybee's picture
Offline
Mobile Conjurer
Joined: 5 Jan 2012
Posts:

Thank you, I tried it again and maPlatformRequest("tel://1234")  is working, but maCallDial() is not.

Ovidiu
ovidiu's picture
Offline
Mobile Wizard
Joined: 27 Jan 2011
Posts:

maCallDial indeed does not work because maPlatformRequest is to be used for making calls. Thanks for pointing this out.I'll update the documentation.

santoshvarma33
santoshvarma33's picture
Offline
Joined: 3 May 2012
Posts:

Hi Ovidiu,

Iam not able to see the permission for "Phone Calls" in my Mosync IDE.Iam having Mosync version 3.0.1 and the build date is:120330-1645 which is latest nightly build but iam not able to get that option.I would like to know whether iam missing anything.Iam not able to call through android device and i used maPlatformRequest("tel://" + phoneNo); in main.cpp.

Code snippet:

javascript:

function makeCall() {
          // Send message to C++ to make device call.
        // We use the JSON format. The message will
        // be delivered to C++ in a JSON array.
        mosync.bridge.sendJSON({
            "messageName" : "Custom",
            "command" : "call",
            "phoneNo" : "94XXXXXXXX"
        });
}

main.cpp

else if (command == "call") {
                    int phoneNo = message.getParamInt("phoneNo");
                    maPlatformRequest("tel://" + phoneNo);

}

Its very urgent kindly respond ASAP.

Thanks,

Santosh

 

 

Ovidiu
ovidiu's picture
Offline
Mobile Wizard
Joined: 27 Jan 2011
Posts:

As I mentioned above, the fix will be officialy released only in MoSync 3.1. In case you need it you have to download (mosync link) and install one of our nightly builds (any build from May should contain the fix... your build is from the end of March).