SmsManager.sendTextMessage from a BroadcastReceiver does nothing on CDMA phones - java

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.

Related

Android Send sms when app not running in background

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...

Android failed sms observer

I'm trying to write an Android service app which intercepts failed outgoing sms messages (due to service unavailable) to store them and try to resend them as soon as the phone service is back. I almost got it to work, but i have this problem, which is not so simple to explain but i'll try, hoping you understand:
I have set a ContentObserver on the URI content://sms even if what i'm interested on is content://sms/failure because if i set it on this last URI the onChange method doesn't get triggered, and i don't know why. Provided successfully sent and received messages don't bother me since, in the onChange method in the observer, I read just the content in content://sms/failed, here is the real problem: onChange gets triggered also on DELETE events, of course, which occur, for example, in the moment a previously failed message is succesfully sent. This is bad for my application because if I can't distinguish between a delete event and an add event i don't know if i have to add or not the first sms in the failed message queue into the "resend" list. So, my question is: is there a way to distinguish between delete an add events with a content observer?
PS: It would be nice to understand why a ContentObserver on content://sms/failed doesn't work.
PPS: I have another minor issue: i'm resending the messages using the SmsManager, which works fine, the only problem is i can only set the destination number and the body of the message but not the ID of the message, so when i resent an sms the system think it's just a new sms and not an old one being resent (and so the old failed messages remains in the queue and doesn't get removed by the system).
...is there a way to distinguish between delete an add events with a content observer?
Query the URI passed into the onChange() method. If the Cursor is empty - i.e., getCount() returns 0 - then it was a deletion. For example:
public void onChange(boolean selfChange, Uri uri)
{
boolean deletion = false;
Cursor cursor = getContentResolver().query(uri, null, null,
null, null);
if(cursor != null)
deletion = cursor.getCount() == 0;
else
return;
...
}
It would be nice to understand why a ContentObserver on content://sms/failed doesn't work.
That's just how the SMS ContentProvider is implemented. You can't get any more specific than content://sms.
I have another minor issue...
The ID for a message is assigned by the ContentProvider, and the soonest your app can know its value is in the onChange() method. You have no control over the assignment of IDs, so your app will have to track failed message IDs itself, and delete the appropriate message upon a successful send.

Is it possible to send a message from one app to another?

I have a text messaging app that I want users to be able to text another app of mine on someone else's phone that will show up within the app. Printed on screen. I have one app that will send the message and one app on the receiving device that will display the message. How would I go about doing this?
The receiving app is an opengl app that will display the message in front of a 3d model from the sending app.
If someone could help me out or get me going in the right direction, I would greatly appreciate it. Thank you for your time.
EDIT: This is what I'm doing. I'm making a live wallpaper that women can put on their phone, a seperate "regular" app will allow the husband, fiance, etc to send a message to the lwp on the significant others phone that will display at the top half of the lwp screen.
public void sendSMS(String phoneNumber, String message)
{
PendingIntent sentPI = PendingIntent.getBroadcast(this, 0,
new Intent(SENT), 0);
PendingIntent deliveredPI = PendingIntent.getBroadcast(this, 0,
new Intent(DELIVERED), 0);
SmsManager sms = SmsManager.getDefault();
sms.sendTextMessage(phoneNumber, null, message, sentPI, deliveredPI);
}
You can do something like this for sending the sms.
Yes, it's possible.
Use SMSPopup as a working Android project you can use. It has the two parts you need: the sending part and the receiving part, and it's open source. Here it is on Google Play.
The only issue is that the user probably won't want those application messages intermingled with his normal SMS messages.
So you'll want to tag your application text messages with a unique keyword so that the receiving app knows it's a message for itself and no one else. And by tagging, I just mean to insert a unique keyword at the beginning of its subject line.
And your receiving app will have to register a BroadcastReceiver with a priority of 100 so that if it detects a message intended for itself, it can just delete it from the content provider and just do an AbortBroadcast so that the other text messaging apps don't beep for a message that wasn't meant for them in the first place.
In that sense, SMSPopup probably already does 90% of what you need. SMSPopup doesn't automatically delete the sms it receives, nor will it filter them on a particular keyword, but it must silently swallow them so that the normal notification system for sms doesn't get triggered (since SMSPopup provides its own notification popup interface instead).
Hi Steve we have RabbitMQServer to send messages between apps. We should configure the server and need to implement functionlities to send and receiving messages.
You may get details about RabbitMQ server at http://www.rabbitmq.com/.

android AppWidget: SMS query works on emulator, but not on a real device

I have built an appWidget which update it's unread sms count for specific contact when a new sms comes in, for that I've registered a contentObserver to monitor incoming sms.
The mySMSObserver class calls the method below for getting the number of unread messages for specific contact, by his ID.
So far so good, the problem is that the query below works fine on the emulator, but when I try that on my android device it allways return 0 unread messages (as shown by Toast).
private static String updateUnreadSMS(String contactID, Context context) {
ContentResolver cr=context.getContentResolver();
//final Uri SMS_INBOX=(Uri.parse("content://mms-sms/conversations"));
//final Uri SMS_INBOX=(Uri.parse("content://mms/inbox"));
final Uri SMS_INBOX=Uri.parse("content://sms/inbox");
Cursor c = cr.query(SMS_INBOX, null, "read = 0 AND person=?", new String[]{contactID}, null);
// get number of unread sms messages
int unreadMessagesCount = c.getCount();
Log.d("DEBUG", "UnreadSMS: "+unreadMessagesCount);
Toast.makeText(context, "updateUnreadSMS "+unreadMessagesCount, Toast.LENGTH_LONG).show();
c.deactivate();
return String.valueOf(unreadMessagesCount);
}
Is there different query's needed for different devices?
how do I write the same query for "content://mms/inbox"?, Because "person=?" is an illegal field for that query.
Will be glad for your help and advice for solving this problem :)
Accessing the databases directly might not be the best idea. As locations and data structure might change with different Android versions (It did so with the Calendar storage from 7 => 8). Nevertheless check if your device location and database structure is the same.
For MMS you might take a peek at PduParser used to parse MMS messages and other classes in this folder.

Trivial: Get confirmation of email sent in android

After starting an email intent how can I get confirmation that the email has sent or there has been an error back into the activity it was called from?
Intent emailIntent = new Intent(Intent.ACTION_SEND);
emailIntent.setType("png/image");
String subject = "Email Subject";
String body = "Message Body";
emailIntent.putExtra(Intent.EXTRA_SUBJECT, subject);
emailIntent.putExtra(Intent.EXTRA_TEXT, body);
emailIntent.putExtra(Intent.EXTRA_STREAM,
Uri.parse("file:///sdcard/" + IMAGE_FILENAME));
startActivity(Intent.createChooser(emailIntent, "Send email..."));
//Here I need to do something on a successfully sent email
Maybe start activityForResult? But what result should I expect back if any?
That really depends on the app that is launched by your Intent. It could be the Gmail app, it could be the Email app, or it could be any third-party app. Because of this, there is no 100% reliable way to determine whether the user actually pressed Send or not.
The only thing you can do is check if the Gmail and Email apps return anything relevant when called via startActivityForResult and rely on that. But beware that is not reliable because, again, there could be third party apps. Also, since these apps do not specify publicly what they return, they might change that at some point without any notice.
you cannot get any useful resultcode from an email intent. onActivityResult always return 0 as soon as sending starts or sending is canceled.
Additionaly if you attach files, onActivityResult is called BEFORE those files are read.
You can NOT do this.
ACTION_SEND does NOT have any output as a result you always get the default value which is RESULT_CANCELED.
Also you can NOT check it with Intent data coming back because it is always null either mail send or discard.

Categories

Resources