Sending SMS from DroidScript

736 views
Skip to first unread message

Steve Garman

unread,
Jan 29, 2019, 8:56:15 PM1/29/19
to androi...@googlegroups.com
If you have apps that are designed to send or receive SMS text messages, you will probably have noticed that they do not work with the latest version of DroidScript.

This is a result of rule changes at Google Play that are designed to ensure that SMS is only dealt with by one single app that is registered as the device's text main message handler.
The rationale behind this seems to be an attempt to ensure that texts are not sent by the device without interaction with the user.

In order to still be able to send texts from my phone in a semi-automated fashion, I have cobbled together the sendSms function below.

This should allow you to pass the number and message to your main messaging app, so that the user has only to press send.

function sendSms(msg, number)
{
 
var packageName = null, className = null;
 
var action = "android.intent.action.VIEW";
 
var category = null, uri = null;
 
var type = "vnd.android-dir/mms-sms";
 
var extras = JSON.stringify(
 
[
 
{name: "address", type: "string", value: number},
 
{name: "android.intent.extra.TEXT",
      type
: "string", value: msg}
 
]);


  app
.SendIntent( packageName, className,
    action
, category, uri, type, extras );
}

For those who do not find it obvious how to use this function, I have attached an spk with some minimal code to call the function.

I'd be interested to hear from anyone who tries it whether it worked for you.

If it does not work, I would be grateful to hear details of the device where it gives you problems, along with the version of Android and a brief description of what goes wrong. If appropriate, this could be accompanied by a screenshot.

Edit: removed .spk file.  See spk that works better later in this thread

Chris

unread,
Jan 29, 2019, 9:48:16 PM1/29/19
to DroidScript
Steve,

Sorry to report that neither of my devices do anything at all.

Bean 4.1.2 and LineageOS 15.1 (8.1)

However, I am rooted on both devices and habe the default sms app frozen and use a secure sms (silence). Not sure if that is why... but wanted to let you know.

I'm seeing no error, nothing. DS doesn't do a thing.

Steve Garman

unread,
Jan 29, 2019, 9:59:42 PM1/29/19
to DroidScript
Yes Chris, that's why.

All it does is to send an intent which should be picked up by the default sms app whick includes extras for text and number.

If you have no contactable app that is capable of sending sms, I would expect it to fail silently. I'm not looking for a return value. I'm not even sure if there would be one.

Chris

unread,
Jan 29, 2019, 10:02:45 PM1/29/19
to DroidScript
I have a 'default' sms app on both devices, its called 'Silence'. It's in the playstore. :-)

Just doesn't get opened by that intent.

Hmmm.

Message has been deleted

Steve Garman

unread,
Jan 29, 2019, 10:25:54 PM1/29/19
to DroidScript
It's quite possible it doesn't work everywhere. It's only the product of searching stackoverflow, followed by quite a lot of trial and error.

It seemed easiest to ask for input (as it was 3am) rather than just suggest Dave added app.SendSms()

Incidentally, Icode-GO was a tremendous help in producing the shortened code I suggested to him.

app.SendSms=function(msg,number){app.SendIntent(null,null,"android.intent.action.VIEW",null,null,"vnd.android-dir/mms-sms",JSON.stringify([{name:"address",type:"string",value:number},{name:"android.intent.extra.TEXT",type:"string",value:msg}]));}

Steve Garman

unread,
Jan 29, 2019, 10:32:24 PM1/29/19
to DroidScript
Interesting.

An apk definitely doesn't request any permissions on my phone and the app works fine.

Having said that, it looks like the rules changed once or twice, most notably with the release of KitKat. There's a surprise!

Chris

unread,
Jan 29, 2019, 11:04:03 PM1/29/19
to DroidScript
This works on both my devices.

function sendSms(msg, number)
{
var packageName = null,
className = null;

var action = "android.intent.action.SENDTO";
var category = null,
uri = 'smsto:'+number;
var type = null;
var extras = JSON.stringify(
[
{name: "sms_body", type: "string", value: msg}

Steve Garman

unread,
Jan 29, 2019, 11:45:49 PM1/29/19
to DroidScript
Yes, that looks a lot better Chris.

If it works for other people, I should probably have suggested:

function OnStart()
{
 
var lay = app.CreateLayout("linear", "VCenter,FillXY");
  edtNum
= app.CreateTextEdit("555-0100", -1, -1, "Number,SingleLine");
  edtNum
.SetHint( "Number" );
  lay
.AddChild(edtNum);
  edtMsg
= app.CreateTextEdit("Hello World!\nLove from Steve", -1, -1, "");
  edtMsg
.SetHint( "Message" );
  lay
.AddChild(edtMsg);
 
var btn = app.CreateButton("Send");
  btn
.SetOnTouch(btn_OnTouch);
  lay
.AddChild(btn);
  app
.AddLayout(lay);
}


function btn_OnTouch()
{
 
var m = edtMsg.GetText(),
    n
= edtNum.GetText();
  app
.SendSms(m, n);
}


app
.SendSms=function(msg,number){app.SendIntent(null,null,"android.intent.action.SENDTO",null,'smsto:'+number,null,JSON.stringify([{name:"sms_body",type:"string",value:msg}]));}


//


BareK

unread,
Jan 30, 2019, 4:05:12 AM1/30/19
to DroidScript
Works great on my device (using ChompSMS).

Steve Garman

unread,
Jan 30, 2019, 5:27:23 AM1/30/19
to androi...@googlegroups.com
I removed the .spk file from the top of this thread and would now like people to check this version based on the intent suggested by Chris.
sendSMS2.spk

Dave

unread,
Jan 30, 2019, 10:19:18 AM1/30/19
to DroidScript
Thanks Steve., I've added that to the app.js file :)

Jon Bray

unread,
Jan 13, 2020, 3:53:52 PM1/13/20
to DroidScript
So, if I understand things, the reason that DroidScript (or at least the play store version) can't send text messages is that it isn't the default handler?

Does that mean that, if I manage to write bug-free code and create an apk with it and don't upload it to Google (or go through the rigmarole of getting an exception, as I want the program to send an SMS in emergencies which is allowed) it will then work?

(As an add-on to this; as DroidScript itself is free, would it worthwhile you creating a link to a SMS-permissions-enabled version outside google play?  Or would that break other things?)

Jon Bray

unread,
Jan 13, 2020, 3:58:44 PM1/13/20
to DroidScript
So I had the SMS code in the sendAlert() function ready but commented out:

  /*
  //Create SMS object and set callbacks.
  sms = app.CreateSMS();
  sms.SetOnStatus( sms_OnStatus );
  sms.Send("myphonenumber",sAlertMessage);
  */

Just leaving that comment in causes the script to hang with no explanation in the debug menu (from reading elsewhere, I suspect the code is trying to create an app with sms permissions because it can see it and doesn't distinguish between code and comments, and Android is getting uppity about that).

Steve Garman

unread,
Jan 13, 2020, 4:19:35 PM1/13/20
to androi...@googlegroups.com
Mostly right Jon, except that DS can't even have skeletons to allow it to request SMS permissions, so if you downloaded DS from Google Play, it won't work.

There is an X version of DroidScript 1.78 which you can install at http://androidscript.org/apk/DroidScript_178/X/

But beware, do not attempt to upload any APK built with the X Version to Google Play, they will have forbidden permission skeletons in their manifest, whether or not your app is using SMS.

Jon Bray

unread,
Jan 13, 2020, 5:11:28 PM1/13/20
to DroidScript
OK, thanks
Message has been deleted

Jon Bray

unread,
Jan 15, 2020, 3:37:45 PM1/15/20
to DroidScript
Sorry, could you just clarify how I'm supposed to install the x version of apkbuilder please?  

I've downloaded the zip file, removed the _Xxxx bit so its just apkbuilder.zip and copied it to the /sdcard/DroidScript/Plugins but I suspect its in the wrong place (not least because it isn't overwriting anything else, and when I try to build the apk its still asking me for my API key password).

Steve Garman

unread,
Jan 15, 2020, 3:58:13 PM1/15/20
to DroidScript
It would be unprofessional of me to recommend how you go about getting permission to use sms because I have not communicated with anyone who has done it successfully.

However, I would start looking at https://support.google.com/googleplay/android-developer/answer/9047303?hl=en-GB

It sounds like you have installed the apkbuilder plugin correctly.
The simplest way to check is to build an APK with minimal SMS functionality in it (just copy the SMS sample) and see if it works.

Jon Bray

unread,
Jan 16, 2020, 9:42:20 AM1/16/20
to DroidScript
The SMS functionality is working OK when run from inside DroidScript, but when I try to create an build an APK with X versions of DroidScript it either fails with "Bad Password/API Key" (if I'm using the API key left over from the play version of DroidScript, or (if I delete the API file) tries to make a new one but then crashes without doing so.  The same thing occurs if I try to build with just the SMS sample.

I tried completely uninstalling DroidScript and the APK builder and reinstalling just the X versions but the same thing happens.

Syed Munawer Hassan

unread,
Jan 17, 2020, 12:46:10 AM1/17/20
to DroidScript
Send your code I will build apk for you

Jon Bray

unread,
Jan 21, 2020, 5:11:46 AM1/21/20
to DroidScript
Just read this; thanks very much for the offer.  There is currently some stuff that's hardcoded which I should probably move to an INI file but then I'll definitely take you up on it.

Dave

unread,
Jan 21, 2020, 7:37:08 AM1/21/20
to DroidScript
Try the latest release first Jon  



Jon Bray

unread,
Jan 29, 2020, 9:28:48 AM1/29/20
to DroidScript
That certainly builds OK, thanks.

Steve Garman

unread,
Jan 29, 2020, 1:57:10 PM1/29/20
to DroidScript
When the version of DroidScript I am using has an X version, I normally use that unless I want to build an APK for distribution but can I just add a warning.

The skeletons for SMS are not the only difference between the standard and X versions.
The other thing that springs to mind is the COSU stuff for true kiosk apps on Company Owned Single Use devices.

Personally, I would never take the risk of uploading any app built with the X version of DroidScript to Google Play, even if I believed I could make a good case for needing SMS.

By all means build APKs for your own use. I used one until recently to reply to SMS messages while I'm driving saying basically "I'm driving right now. I will read and respond to your message when it is safe and legal to do so"

It is fine to share those APKs with your friends. I put the APKs on Google Drive and send my friends a link but you could upload them wherever you think appropriate.

But I sincerely believe that if I uploaded apps built with the X version to Google Play I would risk my account being suspended or worse, no matter how pure my intentions.

Md Sazzad Husain

unread,
Nov 17, 2020, 5:26:46 AM11/17/20
to DroidScript
Hello,

i have downloaded DroidScript_180X.apkapkbuilder_180X.zip. i have created a sms sending app for my self. Now how can i create apk using " apkbuilder_180X.zip " ???

with regards 

Dave

unread,
Nov 18, 2020, 2:54:32 PM11/18/20
to DroidScript
remove the '_180X' part of the apkbuilder file name (so it's just apkbuilder.zip), then drop it into your /DroidScript/Plugins folder on your phone and restart DroidScript

*** DO NOT UPLOAD 'X' VERSIONS TO GOOGLE PLAY OR YOUR ACCOUNT MAY BE TERMINATED! ***
Reply all
Reply to author
Forward
0 new messages