Outbox message not being sent - android

In my app I want to keep track on sms sending. In case of sms does not sent due to network failure(No signal).
I managed to put sms in outbox :
private void putoutbox(String addr,String msg) {
// TODO Auto-generated method stub
ContentValues values = new ContentValues();
values.put("address", addr);
values.put("body", msg);
getContentResolver().insert(Uri.parse("content://sms/Outbox"), values);
}
sms is being shown in default message folder with status sending
but sms never sent
I also tried
content://sms/failed
and it also does not send sms.
Please tell me what I am missing.

Thank you all for helping me
as st0le gives a very useful link here one must have to provide all seven attribute
unfortunately i can not show the code for that,but it will work if you restart your phone

Related

How to get sip messages on during call on android?

I want to get and read sip info messages on during call. I sent other side to sip info message and I saw on logcat but I dont get the message on code. I use the pjsip.
How to get sip info messages on during call?
Thanks.
you will require. onCallTsxState call back function from call class to listen to Sip message shared during the call. It took quite some time for me to figure out and hopefully it could help some once else ,if its too late for you.
#Override
public void onCallTsxState(OnCallTsxStateParam prm) {
if (eventBody.getTsxState().getType() == (pjsip_event_id_e.PJSIP_EVENT_RX_MSG)) {
SipRxData rdata = eventBody.getTsxState().getSrc().getRdata();
//technically here in messageBuffer I am storing all header file info shared during the call
String messageBuffer = rdata.getWholeMsg();
Log.e("bingo", String.valueOf(messageBuffer));
// in my case in my case I am check presences of info message : Connection Established every time new header message is send
if(messageBuffer.contains("Connection established")){
Log.e("bingo", "bingo established");
try {
//perform what ever you want to do here when you receive info message
}
});

How to handle error situations when Broadcast is not triggered due to unfulfilled message criteria in case of SMS User Consent API?

In the following docs:
https://developers.google.com/identity/sms-retriever/user-consent/request
it is stated a message triggers the broadcast only if it meets these criteria:
The message contains a 4-10 character alphanumeric string with at
least one number.
The message was sent by a phone number that's not
in the user's contacts.
If you specified the sender's phone number,
the message was sent by that number.
However it's not mentioned how to deal with the situation when any of the above criteria is not met and broadcast is not triggered. How do we conduct this to the end-user?
I am able to handle success and timeout cases and handling this situation would make the code more user-friendly.
switch (smsRetrieverStatus.getStatusCode()) {
case CommonStatusCodes.SUCCESS:
// Get consent intent
Intent consentIntent = extras.getParcelable(SmsRetriever.EXTRA_CONSENT_INTENT);
try {
// Start activity to show consent dialog to user, activity must be started in
// 5 minutes, otherwise you'll receive another TIMEOUT intent
startActivityForResult(consentIntent, SMS_CONSENT_REQUEST);
} catch (ActivityNotFoundException e) {
Log.d("Exception","ActivityNotFound");// Handle the exception ...
}
break;
case CommonStatusCodes.TIMEOUT:
Log.e("Timeout-Error:","Listened for msg for 5minutes");
break;
}
You could try using CommonStatusCodes.ERROR but I am not sure if this would get triggered when the SMS received is specifically invalid.
One user-friendly solution may be: setting a timer of 30 seconds for example that starts as soon as you request the SMS/OTP. When the countdown is done, you display a "RESEND SMS" button. So in case the SMS was not received/retrieved, you have a more-user friendly way of letting the user retry and request another SMS.

Android - Modify SMS Body before arriving the Inbox

Currently I am trying to modify an incoming SMS before it is saved to the Inbox.
As the system is Android 4.4.4, a simple interception with a high priority broadcast receiver is not possible. That is also the reason why I'm modifying the Android Source (AOSP) and not building an App.
So far I have managed to identify a promising class: InboundSmsHandler. Within the inner class SmsBroadcastReceiver the method onReceive is triggered when a SMS has arrived and later on sends an "SMS_RECEIVED" intend. So basically this method seems to be at a good spot.
The problem is that I can not modify the SMS that is delivered with the intend of onReceive.
I have already tried to modify it with PDU:
byte[] pdu = createFakePDU("15555215556", "modified body");
intent.putExtra("pdus", new Object[] { pdu });
intent.putExtra("format", "3gpp");
(This approach did not work, the SMS App has shown the original message)
Tried to modify the body of a SmsMessage directly:
(I have added a method to SmsMessage to be able to modify the body)
SmsMessage[] msgs = Intents.getMessagesFromIntent(intent);
int pduCount = msgs.length;
for(int i=0; i<pduCount; i++)
{
msgs[i].modifyBody("test");
}
(This approach did not work, the SMS App has shown the original message)
And finally added a new SMS to the database:
....
contentResolver.insert( Uri.parse( SMS_URI ), values );
....
(The problem with that approach is that the original SMS still arrives and therefore not only one modified SMS but one original SMS and one modified arrive. The original SMS must be deleted, but I don't know how.)
Does anyone know how I can modify a SMS before it arrives at the Inbox?
Best regards
mint
AFAIK, on 4.4.4 there is nothing that can prevent your app to receive SMS by registering your BroadcastReceiver, setting the right permissions and the right intent filter. That is:
<uses-permission android:name="android.permission.READ_SMS" />
<uses-permission android:name="android.permission.SEND_SMS" />
<uses-permission android:name="android.permission.RECEIVE_SMS" />
and
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
(if I correctly remember them)
Then inside your BroadcastReceiver you call abortBroadcast(), modify the SMS as needed, and finally store it manually with
getContentResolver().insert(Uri.parse("content://sms/sent"), values);
Thanks for all the answers, I have found a spot in InboundSmsHandler where it is possible to modify the PDU before the broadcast is sent: the method proccessMessagePart. Before the command "intent.putExtra("pdus", pdus);" is executed, the pdus array and therefore the message body can be modified.

Google Hangouts breaks SMS order

I've got an app that sends a text message as a response after receiving a text message. (Auto Respond) When SMS is enabled in hangouts, my app wasn't sending its messages. I fixed that by doing this:
<intent-filter android:priority="500">
<action android:name="android.provider.Telephony.SMS_RECEIVED"/>
</intent-filter>
After sending the message, my app also writes that sent message to the user's SMS log (inbox/outbox displayed by messaging apps.)
But now that my SMS receiver is higher priority than Hangouts, the sent message is written to the user's SMS log AFTER the received message when it should be the other way around.
So it shows like this:
Response Message
Received Message - this is what triggered the response
But it should be:
Received Message - triggers response
Response Message
Is there a way for me to wait for the received message to be written before writing the response message? It works fine when SMS is disabled in Hangouts. But since Hangouts is now writing that message instead of the default SMS receiver, it messes things up like crazy.
EDIT: Thanks to Keith's response, this is the code that worked for me:
context.getContentResolver().registerContentObserver(
Uri.parse("content://sms"),
true,
smsObserver);
And this class:
private class SMSObserver extends ContentObserver
{
public SMSObserver()
{
super(null);
}
#Override
public boolean deliverSelfNotifications() {
return true;
}
#Override
public void onChange(boolean selfChange) {
super.onChange(selfChange);
if(!selfChange)
//sendResponse
context.getContentResolver().unregisterContentObserver(this);
}
#Override
public void onChange(boolean selfChange, Uri uri) {
super.onChange(selfChange, uri);
if(!selfChange)
//sendResponse
context.getContentResolver().unregisterContentObserver(this);
}
}
I'm not sure if the self change part is necessary, but it works so I'm not changing it.
Try a ContentObserver on the SMS database to listen for when Hangouts writes to the SMS content provider. This approach should be compatible with 4.4/Hangouts as well as earlier versions; you'd just wait until something is written to write your sent message.
Tested two different versions on Android 4.3, Galaxy Nexus:
context.getContentResolver().registerContentObserver(Uri.parse("content://sms"), true, myContentObserver);
or
cursor = context.getContentResolver().query(Uri.parse("content://sms/inbox"),
new String[] { SMS_ID, SMS_ADDRESS, SMS_READ },
"read = 0",
null,
null);
cursor.registerContentObserver(myContentObserver);
But I couldn't use the non-Cursor version with sms/inbox for some reason. The downside of the Cursor-based version is that it seems to need to stay open so then you have to be sure to close it later.
Also, neither version is being called when the read status changes.

Android app that opens inbox SMS

I am using an SMS manager in my app, so when a button is clicked, an SMS is sent,
btnPaket.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
String phoneNo = "0977";
String message = "stanje";
sendSMS(phoneNo, message);
Toast.makeText(getBaseContext(), "Zahtjev za provjeru stanja paketa je poslan, odgovor ocekuj uskoro!", Toast.LENGTH_SHORT).show();
}
});
So when I click on the button, the SMS is sent, and I get an automated response with the state of my SMS, and Internet packets. Is there any way such that a received SMS is automatically opened and shown to the user, without leaving the application, and going to the inbox, or the notifications bar?
I don't think Android allows you to directly open/read text messages (for extremely obvious reasons...), however, you might be able to just launch the SMS inbox from your application.
Reference here to how to launch activities.
EDIT:
This person apparently found out how to open the sms inbox, check his second post.

Categories

Resources