Android : Sending an SMS (using the Outbox) - android

I'm working on an SMS Application for Android, which undoubtedly needs to send SMSes (go figure! ;)
Now, i know there are a plenty of sources on the net that describe using the SmsManager to send SMSes...But, apparently, when using that method, the SMSes aren't stored in the "SENT" Folder...which is kind of a basic requirement for an SMS application.
How do i add an entry (of a message) into the "Outbox", so that it gets sent (and stored in the SENT Folder Automatically)....
What would be the Values of the fields "_id,threadid,read,status,type,service_center" (Attributes of the message table)??
Any other alternatives are also welcome. :)
Thanks in Advance...

I had been looking for a work around this issue. Add the following lines of code after sending the sms... this will make an entry in the outbox of native sms application
ContentValues values = new ContentValues();
values.put("address", number);
values.put("body", desc);
getApplicationContext().getContentResolver().insert(Uri.parse("content://sms/sent"), values);
i would like to get help from ppl who could tell how to use this content provider to make entry for multiple receivers... Thanks..

But, apparently, when using that
method, the SMSes aren't stored in the
"SENT" Folder...which is kind of a
basic requirement for an SMS
application.
The concept of a "SENT" folder is a feature of an application, not the operating system. If you wish to create your own SMS client application, create your own "SENT" folder as a feature of that application. You know what messages you are sending, so you can store them wherever you like (e.g., SQLite database).
If you want to send SMS messages and have them appear in the "SENT" folder of the user's chosen SMS client, don't use SmsManager. Instead, use ACTION_SENDTO and have the message be sent by the user's chosen SMS client, as is demonstrated by this sample project.

At least on 6.0 and 7.0 the system app com.android.phone is responsible for storing the messages sent by other apps. Unfortunately, this functionality is broken by some manufacturers and this is why we don't see sent messages.
It does work on AVD though. See the method persistSentMessageIfRequired() in com.android.internal.telephony.SMSDispatcher.
Only this app or the selected default SMS app has a write permission to the SMS content provider. When you send it using the SMS app, it calls insert() directly. When you use SmsManager in your app, the system app com.android.phone somehow gets notified, performs the sending and then stores the sent message. Here's the callstack (I didn't dig further):
at android.os.Handler.obtainMessage(Handler.java:293)
at com.android.internal.telephony.gsm.GsmSMSDispatcher.sendSmsByPstn(GsmSMSDispatcher.java:291)
at com.android.internal.telephony.gsm.GsmSMSDispatcher.sendSms(GsmSMSDispatcher.java:274)
at com.android.internal.telephony.SMSDispatcher.sendRawPdu(SMSDispatcher.java:999)
at com.android.internal.telephony.gsm.GsmSMSDispatcher.sendText(GsmSMSDispatcher.java:198)
at com.android.internal.telephony.ImsSMSDispatcher.sendText(ImsSMSDispatcher.java:206)
at com.android.internal.telephony.IccSmsInterfaceManager.sendTextInternal(IccSmsInterfaceManager.java:452)
at com.android.internal.telephony.IccSmsInterfaceManager.sendText(IccSmsInterfaceManager.java:393)
at com.android.internal.telephony.UiccSmsController.sendTextForSubscriber(UiccSmsController.java:136)
at com.android.internal.telephony.ISms$Stub.onTransact(ISms.java:201)
at android.os.Binder.execTransact(Binder.java:565)
After the SMS is sent, the app posts a Handler message to itself:
at android.database.sqlite.SQLiteDatabase.insert(SQLiteDatabase.java:1343)
at com.android.providers.telephony.SmsProvider.insertInner(SmsProvider.java:618)
at com.android.providers.telephony.SmsProvider.insert(SmsProvider.java:442)
at android.content.ContentProvider$Transport.insert(ContentProvider.java:264)
at android.content.ContentResolver.insert(ContentResolver.java:1274)
at com.android.internal.telephony.SMSDispatcher$SmsTracker.persistSentMessageIfRequired(SMSDispatcher.java:1445)
at com.android.internal.telephony.SMSDispatcher$SmsTracker.persistOrUpdateMessage(SMSDispatcher.java:1476)
at com.android.internal.telephony.SMSDispatcher$SmsTracker.onSent(SMSDispatcher.java:1537)
at com.android.internal.telephony.SMSDispatcher.handleSendComplete(SMSDispatcher.java:638)
at com.android.internal.telephony.SMSDispatcher.handleMessage(SMSDispatcher.java:274)
at com.android.internal.telephony.gsm.GsmSMSDispatcher.handleMessage(GsmSMSDispatcher.java:108)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6077)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:756)

Related

Use of SMS permission groups exception for Anti-Smishing

I try to develop anti-smishing solution, which listen in background and analyze new SMS.
If I'm not default SMS app, I can only read the SMS.
I found information about some exceptions in use of SMS permission group for Anti-Phishing, where I have access not only to read, but also to write.
How does it work? For now I'm not able to write or edit any SMS in Android Studio. When Google accepts my request/form I will have some extra code for exception or something like it?
https://support.google.com/googleplay/android-developer/answer/10208820?hl=en&ref_topic=2364761#zippy=%2Cwyj%C4%85tki

How to implement AndroidPay auto OTP filling?

So I have a verification code that comes through from sms and user has exit app to go copy it into an EditText.
I found out the Android Pay has a method to scan the incoming verification text from your bank and autofill the text with a verification code.
I'd like to replicate this for my own app but I'm not 100% sure how I do this as I'm struggling to search for what I need. What I've found so far is it could be done via a ContentResolver but that might not be the best solution as it could be different on different Android flavours.
You want a broadcast receiver for SMS, which reads an incoming SMS, checks if the number is right and if the format of the SMS is right, and parses the number from it.
Actually if you can do that there's no need to autofill- just send the request to the correct API for verification directly, so they don't even have to press send.
Android has this built in since play services 10.2.x.
It works only if you include an app specific hash in the SMS message body, which android uses to determine which app to alert that a new message just came in.
When an SMS message with that exact hash is received, android will fire up a broadcastreceiver that youregister in the manifest with a special intent filter:
<receiver android:name=".MySMSBroadcastReceiver" android:exported="true">
<intent-filter>
<action android:name="com.google.android.gms.auth.api.phone.SMS_RETRIEVED"/>
</intent-filter>
</receiver>
How it works in more detail and what code is required etc, you can check here on the developer's blog or here in the official guides.
Note that this won't work if you don't have access to the system that sends out the SMS, meaning you can't add the hash to the message.

How to get draft SMS in Android 6 Marshmallow

My questions specific only for Android 6 (starting from v23 of SDK). I need to get all SMS, even draft for future processing. Nothing special here, used the following peace of code:
context.getContentResolver().query(Uri.parse("content://sms/"),
new String[] {...}, null, null, null)
And this work perfect for Android 5, meaning that I get all SMS messages including draft. But at all devices with Android 6, I get only sent and received messages and NO DRAFT. Try to make my app default SMS before trying to query SMS – but no luck, at Android 6 i still cannot get draft messages. What the problem?
I've already found some related posts
SMS missing from content provider results on Android Marshmallow
But this do not solve my issue at all.
For Marshmallow you need to add run time permissions to read messages .
Check permission like this
int permissionCheck = ContextCompat.checkSelfPermission(getApplicationContext(), Manifest.permission.READ_SMS);
If permission denied tha ask at run time like that
ActivityCompat.requestPermissions(this, new String[]{{Manifest.permission.READ_SMS}, PERMISSIONS_REQUEST_READMESSAGE);
to access draft this is URI for content provider.
Content provider for draft is
content://sms/draft
Note: dont forget to add permissions
<uses-permission android:name="android.permission.READ_SMS"></uses-permission>
I believe what your looking for is found in this answer. It provides a list of URI's for accessing the different SMS boxes. The one specifically for the draft SMS messages is
content://sms/draft
Query on URI content://sms/draft will return only the draft messages that are stored in SMS provider.
Default android messaging application implementation stores the draft messages within the application and will not add the drafts to SMS provider.
Only the draft messages that are part of SMS provider (can added using SMSManager's hidden API addTextMessageDraft) will be returned as results when query on URI content://sms/draft is performed.

How can I log all sent SMS along with package name?

I am trying to develop an app which logs all sent SMS along with UID or package name of the application which triggered that event. I am doing this for a research purpose.Thanks in advance ...
I am looking to log the UID or package name of application which send that sms.
Sorry for my english if it is disgusting.
After a series of researches, I found that package name of application which triggered the SMS is explicitly stored in creator field(index 19) of SMS DB.

Android read SMS history

I found a way to read the call log, e.g. incoming call, phone number, duration, etc. Now I am looking for something similar for SMS. How can I read that history for SMS? I don't need the content of the SMS only the date and the target phone number. Any idea?
Thanks,
A.
There is no API for "SMS history" in the Android SDK, sorry.
I have an open source Cordova 2.2.0 example app showing use of a Cordova plug-in for Android to read SMS inbox and sent messages. It uses some undocumented features of Android 4.2.
https://github.com/DavidWalley/CordovaPlugin_AndroidSmsRead
Hope you can use it.

Categories

Resources