Making Android Messaging app recognize messages sent from other app - android

When I send an SMS message in my Android application, is it possible to make the built-in Messaging app recognize that the message was sent and show it in the appropriate thread?
Currently when my app sends a message, there is no record of it being sent. I would like the message to show up like any other message sent from the phone. I'm hoping for something easier than manually adding the message to the sms database.

You can use the following code to store to the same folder as Messaging app.
ContentValues values = new ContentValues();
values.put("address", phoneNumber);
values.put("body", smsText);
// Note: This uses an Android internal API to save to Sent-folder
context.getContentResolver().insert(Uri.parse("content://sms/sent"), values);
This uses some internal APIs and may brake in future releases / not work on some phones, but as I mentioned in my comment some apps with millions of installs are doing something similar.

is it possible to make the built-in Messaging app recognize that the message was sent and show it in the appropriate thread?
There is no "built-in Messaging app" in Android. While each device with SMS capability has an SMS client, only some use the Messaging app that is part of the Android open source project. Others use their own.
Regardless, they only show messages they sent. The notion of "sent" messages and "the appropriate thread" is a client concept, not an operating system concept.
I'm hoping for something easier than manually adding the message to the sms database.
There is no "sms database" in Android. You are probably thinking of the content provider from the Messaging app. Again, the Messaging app is an app, not an operating system feature, and that app is not on every device. The Messaging app's "sms database" is not documented or supported -- on the contrary, Google specifically states that it is not for your use.

Related

send and receive message in messenger software like WhatsApp

In messaging applications like WhatsApp or Telegram, how to send and receive messages.
Does the software check the server every few seconds once?
I've made a program for sending and receiving messages that the software checks the server every few seconds and if that message is new, it will display that message to the user.
Is my way of working correct?
You can use Firebase real-time database.
Reference: https://code.tutsplus.com/tutorials/how-to-create-an-android-chat-app-using-firebase--cms-27397
There is also a possibility of using Firebase messaging directly but it is more involved.
For your question about how do whatsApp and other messaging apps work, they basically rely on sending notifications to the device when a message is received.
https://medium.com/#cdmunoz/working-easily-with-fcm-push-notifications-in-android-e1804c80f74
User authentication, identification and determining which users to target for a notification are other constraints. Libraries such as those provided by Firebase can manage a lot of these details for you.

Querying for SMS sent via Project Fi

When an SMS is sent/received on a Project Fi Android phone using Hangouts/Messenger how is it stored?
When querying for messages using Android's sms or mms ContentProviders I'm only getting sms messages sent/received when the phone wasn't part of Project Fi.
Any way to query for those messages? Are those messages even stored on the same DB?
P.S.
I'm aware that only Hangouts/Messenger are supported for sending/receiving:
On third-party apps
If you're using any app other than Messenger or Hangouts to send and
receive messages, download the most recent version of Messenger and
make it your default messaging app for best results.
I want to be able only to query for those messages sent via one of those apps.

Android client to client messaging without my own server for GCM

I am doing a prototype that involves messaging between clients.
What I want to do - from MyApp on device1, able to send message to MyApp on device2. Device2 should receive this and show a notification.
I don't have my own application server to push notifications from GCM to GCM clients.Is this possible ? How to do it ?
What I investigated - PubNub, which has a trial license that seems to answer my need to send messages on a channel without needing a server.
This discussion at SO didn't help much.
sending client to client messages without server interaction
Can anyone suggest better ways ?
You basically have to use a server in one way or another. I think Firebase would be perfect for your purposes. It has an Android plugin you can use that will basically alert your app when something changes in the database. Here is the documentation for that feature. Take a look at this example for implementation. Before you can use the plugin, you need to create an account and whatnot (basic one is free). Here are the instructions.
PubNub Realtime Messaging and Push Notifications
(server not required)
With PubNub, you do not need your own server to do the realtime messaging or the mobile push notifications. You likely have your own server for your database (MySQL or similar, traditional RDBMS, a No SQL DB like MongoDB, or a realtime DB sync, like Firebase) to authenticate users and such.
For realtime DB or non-DB type change notifications and signaling (any type of realtime messaging), PubNub makes is super simple to receive messages in realtime with a mobile push notification fallback in one publish action. So the GCM message will be sent along with the realtime message. If the app is actively running, you get it in realtime (< 1/4 on average - typically faster) and the GCM message will be received if the app is not active (background or not started at all).
And PubNub's free plan is not a trial (anymore). It is free (including all add-ons) for as long as you stay within the free plan limits.
See the PubNub Android docs for more details and contact PubNub support if you have any further questions with getting started or getting answers to any questions you have as you progress with your app implementation.
Another possibility is to use the SMS.
Android Send and Recieve Messages
"Send Binary (Data) SMS
We can send binary messages (as opposed to text based messages that we covered earlier) to specific application ports using sendDataMessage(). According to this Stack Exchange thread data sms is one which is sent over 2G/3G as well as GSM. I’ve tested it with mobile data turned off and it works fine charging me the same amount, so not very sure on whether it uses 2G/3G or not, but generally the term data is used in telephony when it’s related to network (tcp/ip). Anyway, SMS’s are generally sent to a specific port on the device (which is probably port 0 [zero]). But using sendDataMessage() we can send SMS’s to some other random port on which our app can listen for incoming SMSs and do something with that. In this case the default messaging app will not store the SMSs in their inbox for both the sender as well as the receiver.
"

Is there a reason not to store data from messaging app in android sms databases?

I built a messaging app that allows users to send and receive sms messages along with other types of messages. Right now I am storing all of the sent and received messages in Android's default databases that hold all sms messages. (content://sms/inbox and content://sms/sent) Is there any reason why this would be a bad idea? I know I could use my own database but unless there is a reason I should I like the simplicity of using the database that already exists on the users phone.
Also will all android devices from all manufacturers have their sms databases in the same place that I will be able to access or will their be issues across different devices and manufacturers?
It is perfectly ok to use existing databases. This is the way many existing messaging apps work.
I can't answer for all users, but I imagine a significant number of them (myself included) would object to having non-SMS messages stored in the same database as SMS messages.
If I used your app, and then opened up the stock SMS app and saw non-SMS messages there, I'd go on a rampage.

Mail client that polls when it gets an SMS message?

Polling for mail uses up battery life and can't be done too often. I have written a Qt program to run on my always on server and use the IMAP IDLE command to notice mail nearly instantly and send me a SMS message when mail shows up in my account. That allows me to see the text message in a timely fashion and then go read mail and manually sync to actually fetch the message (very handy for the mail account I have setup for things like traffic alerts). I can then save battery life by turning off sync on my mail account.
The next obvious step is to get a mail client that looks for the specially formatted text messages and pulls the mail down itself. Any mail client developers out there who'd like to add a poll via sms option to their client? (Just curious).
What you're looking for is the Android C2DM (Cloud to Devices Messaging). It's the in-house push-notification framework that Android uses for gmail (and almost everything else Google-related).
It differs from SMS in that the C2DM message does not have the burden of guaranteed delivery and its payload is much smaller than an SMS message -- so very little content can be delivered on it, only a reference to the content can be delivered through it.
It's been rolled out to third party developers through a limited Beta (if a developer attended Google I/O, they'll have priority to get into that Beta program), but Google has been delaying the official launch of C2DM to everyone else in the developer community repeatedly for quite a while now.

Categories

Resources