Android Send sms when app not running in background - java

Is there any way to send sms using SmsManager without open the App.
I am using FirebaseMessagingService and i got remoteMessage from onMessageReceived method its Contains Mobile No and Message.
Then i am sending SMS using using SmsManager. and also i declared permission.SEND_SMS/RECEIVE_SMS in manifest file.
This is My Code:
public void onMessageReceived(RemoteMessage remoteMessage){
String mobile = remoteMessage.getData().get("mobileno");
String message = remoteMessage.getData().get("message");
SmsManager sms = SmsManager.getDefault();
sms.sendTextMessage(mobile, null, message, null, null);
}
Its Working on when App is Running. but not working on when app is not running in background.
Is there any way to SEND sms when App is not running.??
Please help me.. Thanks...

Finally i got answer from firebase console. i did some mistake in Nodejs Server code after corrected that code its working fine...

Related

Send a spoofed sms on android using sim card

I recently made an app which could send messages using the android smsManager api, and was wondering if there is a way to send a sms message through the an android api where the id of the sender is spoofed.
this is the current state of the code I used which sends the message to my cell:
SmsManager sms = SmsManager.getDefault();
sms.sendTextMessage(recipient, scAdress, msg, null, null);
I've tried to edit the scAddress, but the message doesnt send (I was seeing if that would work, and wasn't sure what scAdress was)
I am also aware that I could use a site like Twilio or Tropo, but I want to send the message through the sim card, not over the internet.
I know you are interested in doing this on your current SIM via other means. Sorry I can't be of more help there. However, this does sound like a fun way to play with Twilio Wireless. You should check out the documentation here.

How to send SMS message to another android device from my app

I declared these two variables in order to send a text message to declared number:
private String text="Hi";
private String emergencyNum="00962789113300";
Then in onCreat() method I wrote this:
SmsManager sender= SmsManager.getDefault();
sender.sendTextMessage(emergencyNum, null, text, null, null);
Unfortunately, the message was not sent and I got not responding status for my app. Could you help me to solve the problem.
Please place the following permission into AndroidManifest.xml file.
<uses-permission android:name="android.permission.SEND_SMS"/>

How to send a sms in Android without it going into the sent box?

I am currently using
SmsManager sms = SmsManager.getDefault();
sms.sendTextMessage(phoneNumber, null, message, null, null);
to send sms messages from an android phone. However it always goes immediately into the phone's sent box ("content://sms/sent") is there away to send sms messsages without it going into the sent box?
P.S. I know how to delete messages from the sent box but that requires waiting for about a second before it is stored in the box.

SmsManager.sendTextMessage from a BroadcastReceiver does nothing on CDMA phones

I've got a BroadcastReceiver that handles the android.provider.Telephony.SMS_RECEIVED action, and sends a text message as a reply in certain cases. My app has the android.permission.SEND_SMS, and works fine on GSM phones. However, it doesn't work on the only CDMA phone I have available to me at the moment, and I suspect it only occurs on CDMA phones. It works on all of the GSM phones I have tried, which are quite a few. logcat shows no errors nor warnings, only D/SMSSMSSMSSMS( 260): TeleService: 4098 each time sendSms is called. Furthermore, I have tried the exact same code in an Activity, and it works perfectly fine.
The code I'm using:
private void sendSms(String destination, String message) {
if(preferencesManager.smsRepliesEnabled()) {
SmsManager smsManager = SmsManager.getDefault();
smsManager.sendTextMessage(destination, null, message, null, null);
}
}
preferencesManager.smsRepliesEnabled() works as expected, and destination and message are set properly. I added a Log.d statement to confirm all three of these. Likewise, PhoneNumberUtils.isWellFormedSmsAddress(destination) returns true.
EDIT: On the advice of #wojci I added a sentIntent and logged the result code. The result code is RESULT_ERROR_GENERIC_FAILURE, with the extra errorCode set to -1. When I try the exact same code from an Activity, however, it works fine with RESULT_OK.
You write that you use the following to send a text:
smsManager.sendTextMessage(destination, null, message, null, null);
Why are you not using the sentIntent parameter which can tell you if your message was accepted by the network?
From the documentation:
sentIntent if not NULL this PendingIntent is broadcast when the message is successfully sent, or failed. The result code will be Activity.RESULT_OK for success, or one of these errors:
RESULT_ERROR_GENERIC_FAILURE
RESULT_ERROR_RADIO_OFF
RESULT_ERROR_NULL_PDU
Maybe it can give you some more clues as to why your SMS sending does not work as you expect it to.

Want to develop an app that can automatically respond to received sms

want to develop an app that can automatically respond to a received text, include my location using gps/google maps in the returned message, and read out the received message using text to speech.
My first concern (what this question relates too!) is figuring out howto automatically reply to sms messages received. I have built a basic GUI and menu option. There is an EditText field that uses shared_preferences to remember the string so far.
How do I go about adding this string to an sms message, and making the messege send to whomever just texted me? I have a decent understanding of java but I havn't been about to find any clear examples and an a bit confused.
Any help would be great!
Thanks
(Basically a java oracle version of the app inventor application "NoTextWhileDriving2")
For an android specific solution you can use the SmsManager class. Here is some example code taken from a similar question that deals with sending an sms message from an android application.
Have a look at SmsMessagingDemo from the android development API demo page. Below is a snippet of the sending code.
// Watch for send button clicks and send text messages.
Button sendButton = (Button) findViewById(R.id.sms_send_message);
sendButton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
if (TextUtils.isEmpty(recipientTextEdit.getText())) {
Toast.makeText(SmsMessagingDemo.this, "Please enter a message recipient.",
Toast.LENGTH_SHORT).show();
return;
}
if (TextUtils.isEmpty(contentTextEdit.getText())) {
Toast.makeText(SmsMessagingDemo.this, "Please enter a message body.",
Toast.LENGTH_SHORT).show();
return;
}
recipientTextEdit.setEnabled(false);
contentTextEdit.setEnabled(false);
SmsManager sms = SmsManager.getDefault();
List<String> messages = sms.divideMessage(contentTextEdit.getText().toString());
String recipient = recipientTextEdit.getText().toString();
for (String message : messages) {
sms.sendTextMessage(recipient, null, message, PendingIntent.getBroadcast(
SmsMessagingDemo.this, 0, new Intent(ACTION_SMS_SENT), 0), null);
}
}
});
You have to setup a BroadcastReceiver for receiving of SMS messages. Very nicely described in Android Developers Blog.
There is also an open source application working with SMS on code.google.com android-smspopup.

Categories

Resources