11var application = require ( "application" ) ;
22
3- function dial ( telNum , prompt ) {
3+ function dial ( telNum , prompt ) {
44
5- try {
6- var intentType = android . content . Intent . ACTION_CALL ;
7- if ( prompt ) {
8- intentType = android . content . Intent . ACTION_DIAL
9- }
5+ try {
6+ var intentType = android . content . Intent . ACTION_CALL ;
7+ if ( prompt ) {
8+ intentType = android . content . Intent . ACTION_DIAL
9+ }
1010
11- var intent = new android . content . Intent ( intentType ) ;
11+ var intent = new android . content . Intent ( intentType ) ;
1212
13- //support for ussd numbers with # on android
14- telNum = telNum . replace ( '#' , encodeURIComponent ( '#' ) ) ;
13+ //support for ussd numbers with # on android
14+ telNum = telNum . replace ( '#' , encodeURIComponent ( '#' ) ) ;
1515
16- intent . setData ( android . net . Uri . parse ( "tel:" + telNum ) ) ;
16+ intent . setData ( android . net . Uri . parse ( "tel:" + telNum ) ) ;
1717
18- application . android . foregroundActivity . startActivity ( intent ) ;
19- return true ;
18+ application . android . foregroundActivity . startActivity ( intent ) ;
19+ return true ;
2020
21- } catch ( ex ) {
22- //alert("Unable to dial");
23- //console.log("phone.dial failed: " + ex);
24- return false ;
25- }
21+ } catch ( ex ) {
22+ //alert("Unable to dial");
23+ //console.log("phone.dial failed: " + ex);
24+ return false ;
25+ }
2626}
2727
2828function sms ( smsNum , messageText ) {
29- return new Promise ( function ( resolve , reject ) {
30- if ( ! Array . isArray ( smsNum ) ) {
29+ return new Promise ( function ( resolve , reject ) {
30+ if ( ! Array . isArray ( smsNum ) ) {
3131 smsNum = [ smsNum ] ;
3232 }
33-
34- try {
33+
34+ try {
3535 var SEND_SMS = 1001 ;
36- var intent = new android . content . Intent ( android . content . Intent . ACTION_VIEW ) ;
36+ var intent = new android . content . Intent ( android . content . Intent . ACTION_VIEW ) ;
3737 intent . putExtra ( "address" , smsNum . join ( ";" ) ) ;
38- intent . putExtra ( "sms_body" , messageText ) ;
38+ intent . putExtra ( "sms_body" , messageText ) ;
3939 intent . setType ( "vnd.android-dir/mms-sms" ) ;
40-
40+
4141 var previousResult = application . android . onActivityResult ;
42- application . android . onActivityResult = function ( requestCode , resultCode , data ) {
42+ application . android . onActivityResult = function ( requestCode , resultCode , data ) {
4343 switch ( requestCode ) {
44- case SEND_SMS :
44+ case SEND_SMS :
4545 application . android . onActivityResult = previousResult ;
46- if ( resultCode === android . app . Activity . RESULT_OK ) {
46+ if ( resultCode === android . app . Activity . RESULT_OK ) {
4747 return resolve ( {
48- response :"success"
48+ response : "success"
4949 } ) ;
50- }
51- else if ( resultCode === android . app . Activity . RESULT_CANCELED ) {
50+ } else if ( resultCode === android . app . Activity . RESULT_CANCELED ) {
5251 return resolve ( {
53- response :"cancelled"
52+ response : "cancelled"
5453 } ) ;
55- }
56- else {
54+ } else {
5755 return resolve ( {
58- response :"failed"
56+ response : "failed"
5957 } ) ;
6058 }
6159 break ;
@@ -67,11 +65,11 @@ function sms(smsNum, messageText) {
6765 }
6866 } ;
6967 application . android . foregroundActivity . startActivityForResult ( intent , SEND_SMS ) ;
70- } catch ( ex ) {
68+ } catch ( ex ) {
7169 reject ( ex . toString ( ) ) ;
72- }
70+ }
7371 } ) ;
7472}
7573
7674exports . dial = dial ;
77- exports . sms = sms ;
75+ exports . sms = sms ;
0 commit comments