SmsManager not working in Android 4.4.x - android

I am developing an Android app, which needs to send a message to multiple recipients.
I used this code to send an SMS to a phone:
SmsManager smsManager = SmsManager.getDefault();
smsManager.sendTextMessage("9030500259", null, "sms message", null, null);
I have read many questions in this site which said the above is correct.
On Googling I found this:
http://android-developers.blogspot.in/2013/10/getting-your-sms-apps-ready-for-kitkat.html
According to the article in the above link, some changes happened in messaging.
I am unable to send SMS in my application.
What is the correct code to send an SMS in Android version 4.4.x?

i was facing same problem .but finally got solution . if u are testing this code in dual sim phone then sim slot 1 always keep active otherwise it " no service" error inn pendingsentintent.

Related

Android: Attempting to send an SMS via SmsManager redirects the message to the default app with no address

As per the tile, I use the following code:
SmsManager smsManager = SmsManager.getDefault();
smsManager.sendTextMessage(sms_receiver, null, sms_content, null, null);
No errors and no exceptions.
While the above seems to work fine in android studio's emulator that I use, when I install my app on my device, again no errors or crashes, but the message goes to my default SMS app as a draft with no recipient.
After searching I, was lead to believe that the fact my mobile phone is dual sim (although I have only one inserted in my device) is the problem and can be addressed by using the "scAddress" argument.
I'm still not sure if the above is right and I couldn't find a way to get the scAddress programmatically.
If it is at all relevant, the model I have is a Xiaomi Redmi Note 6 Pro and the API of the android app:
minSdkVersion 25
targetSdkVersion 29
I assume you've tried setting the service center address in the second argument of smsManager.sendTextMessage?
https://developer.android.com/reference/android/telephony/gsm/SmsManager#sendDataMessage(java.lang.String,%20java.lang.String,%20short,%20byte[],%20android.app.PendingIntent,%20android.app.PendingIntent)
Looks like it should be a phone number: Look here for more info:
https://www.developershome.com/sms/cscaCommand.asp
The problem was indeed that the
SmsManager smsManager = SmsManager.getDefault();
wasn't getting the active sim slot. I used the snippet found in this answer:
Android: How to send sms with particular SIM in dual sim mobiles?
Now the app needs READ_PHONE_STATE permission, which I would prefer wasn't the case, but it works as expected (i.e the SMS is being sent by my app).

send and receive sms of specific number --android

I am work on a messaging system which is send and receive sms but the requirement is the application send sms to specific number which is store in its database and it also receive sms from specific number which is store in its database . actually the client is manufacturer of GPS system with GPRS in this system a sim card is stored which is reply when the sms is send it like current location and many function .when sms will receive which number is store in database of application the sms is not show in android phone default program which is already installed in device. tell me how can i start
You can use SmsManager to send sms.
SmsManager smsManager = SmsManager.getDefault();
smsManager.sendTextMessage("phoneNo", null, "sms message", null, null);
You can use BroadcastReceiver to receive sms.
Several tutorials are available online to understand BroadcastReceiver.

Sms received not the same sent

I am trying to develop an app that send and receive a sms
my sms's are too long so i used a multi partsend sms method
the sms is sent successfully bu when receiving the message the character are wrongly printed in screen
please help me
i tested it in a virtual device
SmsManager sms = SmsManager.getDefault();
ArrayList<String> parts = sms.divideMessage(keyAsString);
sms.sendMultipartTextMessage(getPhoneNo().getText().toString(), null, parts, null, null);
Have you checked the phone sending and the phone receiving are using the same character sets?
I'm not entirely sure how to check because I don't know what phone you're using but if the characters look something like this phenomenon then that might be your problem: http://en.wikipedia.org/wiki/Mojibake

send sms message from Android app to a device

I've implemented code to send sms message from an Android emulator to another, which works well. But when I try to send message from the emulator or an Android device(with wifi only, no data plan or number with the phone) to a device(iPhone ), it doesn't work. I'm not quite sure if sms needs a data plan to send message in real world. Thx for the help!
SmsManager sms = SmsManager.getDefault();
sms.sendTextMessage(number, null, message, null, null);
Though sms does not require a data plan, it needs a working GSM or CDMA Network connection with call working.
SMS is Short Message Service. It's been around longer than we've had internet on phones, and definitely requires a valid SIM card and a working network connection (data over network isn't necessary, but you should be able to make calls).

Sending sms text message from android emulator to second emulator instance

I am trying to send sms programmatically from one android emulator to another on Mac OSX. I am able to telnet into the first and send a text message to the second with:
sms send 5556 test
but... I am not able to send an sms from an android application, here is what I am using to test:
SmsManager sms = SmsManager.getDefault();
sms.sendTextMessage(phoneNumber, null, message, null, null);
the phoneNumber = 5556 and message = "test". Any help would be greatly appreciated. Thanks.
I ended up starting the application from the second emulator. That is, from 5556 and it successfully sent an sms to the first emulator I started, to 5554. I don't know why it would not send from the first emulator I started. But nonetheless, it worked.
Have you set the SEND_SMS permission in the Manifest?
<uses-permission android:name="android.permission.SEND_SMS" />

Categories

Resources