Reputation: 181
I am trying to get an Android phone connected to a Linux server running Nagios to send out SMS when a system it is monitoring goes down.
The Android version on the phone is 7(not rooted). I have adb installed on the Linux computer and the phone is connected over a USB cable.
I have tried with the following code:
adb shell am start -a android.intent.action.SENDTO -d sms:$mobile_number --es sms_body $sms_text --ez exit_on_sent true
adb shell input keyevent 22
adb shell input keyevent 66
It works fine for a while and somewhere along the way it stops working. It types the message, which I can see on the phone's screen but fails to send.
When I run the commands manually from the command line I get an error similar to:
"Warning: Activity not started, its current task has been brought to the front"
I was wondering if there is a better way to send SMS from a Linux computer? I could install a suitable application on the phone if needed, I just need a reliable way.
Upvotes: 1
Views: 3121
Reputation: 2962
There is a solution but you will have to create your own app (very very simple one).
Create an new app and copy-paste this code into the onCreate()
method of the MainActivity:
if(getIntent()!=null && getIntent().getExtras()!=null){
String number = getIntent().getStringExtra("number");
String message = getIntent().getStringExtra("message");
SmsManager manager = SmsManager.getDefault();
manager.sendTextMessage(number, null, message, null, null);
}
Build and install the app on your phone. Then you would simply do this :
adb shell am start -n "com.example.your_app/.MainActivity" -e number XXXXXXXXXX -e message "Hello World !"
Upvotes: 1