How to write sms in Android 6.0? [duplicate] - android

Question regarding content://sms/inbox:
1) Is it advisable to explicitly store incoming messages to inbox?
2) What if an android device has a native messaging app and my messaging app was installed to it, and then I explicitly store incoming messages to inbox, will the messages duplicate?
3) Does android automatically store new messages to inbox regardless if there is a messaging application?
Thanks.

Regarding SMS, details vary depending on the Android version. Prior to KitKat, the SMS API was undocumented. With KitKat, the concept of a default SMS app
was introduced, and the SMS API became public.
Is it advisable to explicitly store incoming messages to inbox?
Pre-KitKat: Yes. If your app is the main or only SMS installed, and no other app gets the SMS_RECEIVED broadcast.
KitKat and on: If your app is the default SMS app, then it is responsible for writing the incoming messages to the Provider. If it isn't the default, then it's irrelevant, since your app won't have write access to the Provider.
What if an android device has a native messaging app and my messaging app was installed to it, and then I explicitly store incoming messages to inbox, will the messages duplicate?
Pre-KitKat: Yes. Unless your app intercepts and aborts the SMS_RECEIVED broadcast, the native app will write the messages.
KitKat and on: Only one app can be the default at any given time, and only it has write access to the Provider. When an app is not selected as the default, it is expected to adjust its behavior accordingly.
Does android automatically store new messages to inbox regardless if there is a messaging application?
Pre-KitKat: No. Native messaging apps are configured to handle the writes. The system doesn't do it automatically.
KitKat and on: No. As mentioned, the default app is responsible for writing incoming messages to the Provider.

Related

How to implement SMS blacklist for Android 4.4 and higher?

In accordance with the doc:
Note that—beginning with Android 4.4—any attempt by your app to abort
the SMS_RECEIVED_ACTION broadcast will be ignored so all apps
interested have the chance to receive it.
In order to implement blacklist for incoming SMS, my app should act as Default SMS app. But I don't want my app to be real default SMS app. So, I am thinking about the following solution:
1. user assigns my app as default SMS app in Android settings;
2. user choose another (real) SMS app in my application;
3. so, my app is able to stop SMS_RECEIVED_ACTION broadcast for spam SMS, but
4. all normal SMS should be passed to real SMS app.
So, I have two questions -
1. How to get the full list of apps, which could be assigned as default
SMS apps (Android somehow shows only particular apps in the
Preferences)?
2. How to pass further processing of incoming messages, message
creations etc. to real default SMS app?
you can get this list of application check all the application which have SMS SEND/RECEIVE permission and that a potential real SMS apps
public abstract int checkPermission (String permName, String pkgName)
method of package Manager can help
http://developer.android.com/reference/android/content/pm/PackageManager.html#checkPermission(java.lang.String, java.lang.String)

Android SMS API and usage

After checking the Android SMS API, I still get confuse about the document explanation.
http://developer.android.com/reference/android/telephony/SmsManager.html
In the API, it mentioned that SmsManager.sendTextMessage(), it described as below:
Note: Beginning with Android 4.4 (API level 19), if and only if an app is not selected as the default SMS app, the system automatically writes messages sent using this method to the SMS Provider (the default SMS app is always responsible for writing its sent messages to the SMS Provider). For information about how to behave as the default SMS app, see Telephony.
So, does it mean that only in Android 4.4 and above, if the app is not default SMS app, then using sendTextMessage() will also add to content://sms/sent?
If the device is below 4.4, then app is responsible for adding to content://sms/sent for the message sent?
I tested on sendTextMessage() on Android 4.3 and 4.2.2, it will not write to SMS provider.
http://developer.android.com/reference/android/provider/Telephony.html
In the Telephony API document about
Creating an SMS app
Only the default SMS app (selected by the user in system settings) is able to write to the SMS Provider (the tables defined within the Telephony class).
I don't understand what the tables defined within the Telephony class?
I tested in Android 4.4.2(Nexus 5), use sendTextMessage() then then add insert the sent message to content://sms/sent. It is successful. The app is not default SMS app. It still can access to the SMS provider. So i don't understand the document explanation that only default SMS app is able to write to the SMS provider....
For deleting a sms message
In the below thread:
Delete an sms from inbox
Here, replied that to delete an sms, need to delete on "content://sms/conversations/".
But why not from "content://sms/inbox"?
Thanks a lot for your kindly response.

How to send an SMS in Android Kitkat from non-default app without writing to SMS Provider

My Android app uses SMS to silently send out notifications. Prior to Kitkat these notifications were not recorded into the SMS Provider and hence did not appear in the user's conversation lists. This is the app's desired behavior.
With the Kitkat SMS changes (refer SmsManger documentation quoted below) these messages are still being sent but are now automatically being written to the SMS provider and thus appearing in the user's conversation lists. This is undesirable for my app.
Beginning with Android 4.4 (API level 19), if and only if an app is not selected as the default SMS app, the system automatically writes messages sent using this method to the SMS Provider (the default SMS app is always responsible for writing its sent messages to the SMS Provider). For information about how to behave as the default SMS app, see Telephony.
It sounds like I could prevent the automatic writing to the provider by making my app the default and then not writing to the provider. However, this would be a terrible user experience in the context of my app, so I would only consider it as an absolute last resort.
My question is then - is there a way to silently send SMS in Kitkat without my app having to be the default app?
I've read the responses to this question Send SMS message using non default SMS app on Android 4.4 but that is more concerned with ensuring that the messages are being written to the provider. I don't want that.
Short answer is no.
Long answer :
There are actually options but it involves a lot of work. One is to download the source code for aosp and modify the mms.apk to allow it to receive intents from your app to send sms without writing to provider.
Another way is to baksmali your phones default sms application and add smali code that would allow you to do the same as above. This would require technical knowledge of smali and decompiling/recompiling apks.
With that said, there are problems that will arise such as what if the phone user decides to use a third party sms/mms application for their short messaging needs.

How to change default app programatically?

I have an app that has device admin rights. My app monitors received SMS's and passes the content through some logic. Can i change the default SMS app to my app programatically . My app checks for spam messages so it needs to read/write/update SMS db. I want a fix for kitkat.
I just noticed that the incoming SMS notification on my app are no longer notifications for new SMS that are received , but instead are "new Hangout message" notifications that are caused by hangouts receiving the incoming SMS. So my app is also not able to receive incoming text messages with SMS_RECEIVED.
Google's Android Developers Blog post about the new SMS API in Kitkat, said that nothing would change for apps using just SMS_RECEIVED and don't try to write the SMS to the SMS Provider.
1 I always believed that the SMS_RECEIVED broadcast is abortable. But the Android 4.4 APIs site says something different: "…when a new SMS arrives by listening for the SMS_RECEIVED_ACTION broadcast, which is a non-abortable broadcast…"
Can i change the default SMS app to my app programatically
Not directly. You can prompt the user to change the default SMS app.
My app checks for spam messages
Repackage your code as a library and license it to SMS clients.
So the Pebble app is also not able to receive incoming text messages with SMS_RECEIVED
Possibly the Pebble app is simply having other problems and is crashing before it notifies the Pebble. Or, possibly the Pebble app is updated for Android 4.4 and, since it knows it cannot stop the Hangouts notification, simply suppresses its own.
Google's Android Developers Blog post about the new SMS API in Kitkat,said that nothing would change for apps using just SMS_RECEIVED and don't try to write the SMS to the SMS Provider
That is not what this blog post says.
I always believed that the SMS_RECEIVED broadcast is abortable
This undocumented, unsupported broadcast had been an ordered, abortable broadcast through Android 4.3. That is no longer the case with Android 4.4, as you can tell by reading the aforementioned blog post:
Note that—beginning with Android 4.4—any attempt by your app to abort the SMS_RECEIVED_ACTION broadcast will be ignored so all apps interested have the chance to receive it.

Check delivery report of sms sent from other application

Can we track the messages sent from other application? I mean, when user send sms by android default sms application (or other sms-managing application), can we track the sms situation and make a notification in our application when sms delivered?
No, this is not possible, unless that other app specifically has an API to support such monitoring.

Categories

Resources