Calculating the number of messages sent in a period - android

Using the Messaging API in Android, is it possible to query the number of messages sent during a particular period - say 1 month?
I am not sure if using a BroadcastReceiver for the android.provider.Telephony.SMS_SENT event would be supported from Android 4.4 and up. I think this is the best approach as the first method will not be able to count if the user deletes some messages.
Can anyone give a better solution or if the first one I mentioned is possible?

Access the content provider
There is a content provider for accessing SMS messages, but it's not documented in the public SDK. If you use ContentResolver.query() with a Uri of content://sms you should be able to access these messages.
You can find more information on this Google Groups thread or previous questions on stackoverflow.

Related

Unable to send this number a text message

We are using Digits for SMS autenthication, and have started receiving notes from some users that they get an error message "Unable to send this number a text message". (this despite the number being a valid cell phone number) The common denominator seems to be that they operate with the same telecom operator in Norway (Telia). I saw a similar post for a carrier in Lebanon so wonder if the same would apply here, more importantly, what can we do to fix this?
Maybe is something about permissions, some of them needs to be asked to the user while their are using the app, read contacts for example.
If that is the problem, i can put here the solution i have to ask the user if he allow the app to use some functions.
If not, i cant help with that mobile company problem.

Poll vs Push... which would be better for multiple emails in an app?

I am working on an Android APP that will handle multiple email accounts, POP3 and IMAP. The current APP, to check for email, you open the APP and click on an update feature. That logs into each email account, and checks for any new mail. Although this works, we need a more efficient, and timely check for new messages.
At first I thought PUSH was the way to go but from what I have read on here, that may not be ideal... especially with multiple IMAP accounts. If I understand right, it keeps each IMAP connection open long-term which could cause some other issues and not sure I could even use it with POP3 accounts.
I looked into POLL as an alternative but that too has potential issues. That involves how frequent it fires up and does the account "checks", the amount of time that takes, and how that all effects battery life. In addition, there appears to be several different "ways" to schedule the POLL option (AlarmManager, JobScheduler, and SyncAdapter)... and I assume one might be better than the other... especially with new version of Android that let you "quiet" your device at certain times of the day.
So the question is, based on what we are looking to do, which is the better way to handle this capability? I am leaning towards PUSH (which format...still unsure), but don't want to waste hours of time to find out that I went down the wrong path.
Thanks ahead for any advice.
IMAP supports IDLE Command in which client acts as passive entity depending/relying upon the server to notify arrival of new mails in account. But as you correctly figured out that it will keep connection open and other issues of rebuilding the connection if it gets disturbed due to any possible reason.
POP do not provide such passive capability to clients. Clients have to pull the mails from server.
From my experience, total synchronization of account on client side is not a problem but it requires too many things to be taken care of like parsing the mail content, maintaining the active list of mails in an account's folder, etc.
[1] Very simple synchronization mechanism would be to simply show the MailList and whenever a message is clicked upon then dynamically load the content of mail.
MailList = Sorted order of Mail Entries in an account's folder.
Single Mail Entry = Sender + Mail Subject + Mail Date & Time + Mail Size
This method of showing MailList initially and fetching the mail content on demand can be achieved via both:
IMAP (FETCH Subject, INTERNALDATE, Sender, Size) and
POP (TOP n m {TOP is a POP command which can fetch m number of lines of nth mail's body along with complete MailHeaderSection of nth mail}). Afterwards MailHeaderSection can be parsed and MailList can be constructed.
[2] Simply fetch the complete mail and store accordingly. Now, Parse it on demand and show it to user. This is also readily supported in both:
IMAP (FETCH BODY.PEEK[])
POP (RETR n)
I like this method since its simple.
Both the above methods are working as if client is active entity (pulling mails on demand).

Android: Listening to contact changes like WhatsApp do

I'm building an App which relies heavily on the user's contacts.
I've created an Account and create RawContacts on behalf of this account when needed.
And I use SyncAdapter and things are great.
But I'm still missing some parts of this puzzle:
I'm trying to implement a behavior similar to WhatsApp. Such that-
When a change happens in the name or phone of any contact - it would be sent to the server for evaluation.
Whether this contact was already in "my" RawContacts, whether he was just created now by the user.
I know there's the ContentObserver but tracking ContactsContract.Contacts.CONTENT_URI seems like the wrong thing to do because it doesn't give the specific change, plus it gets raised to many times, and from to many events that don't interest me.
I know that WhatsApp are using SyncAdapter but I think they might be doing something more.
Any idea would be much appreciated.
ContentObserver tracking ContactsContract.Contacts.CONTENT_URI is indeed the way to go.
When you get onChange() you query the raw_contacts table with following condition:
String where = "(rawcontacts.dirty = true or rawcontacts.deleted = 1) and rawcontacts.account_type = <your_custom_type>"
The result will give you contacts added, updated or deleted.
If you are interested in knowing more details - the reason why you need to subscribe to ContactsContract.Contacts.CONTENT_URI is that the contacts provider currently does not notify which contacts were modified in onChange(). This is because of the applyBatch() transactions where multiple contacts may change. May be in future there will be a way to subscribe to a subset - but currently there is none.

Using/Obtaining SMS short code for application

I have searched google and have not found the answer I was looking for only bits and pieces. I would like to create an application where a user could text a SMS shortcode number with a certain string of text "example: IN" which would then run a command on a server if it matches a specific keyword. Basically it would update a database and then send a message back to the user. My questions are how do I obtain a SMS Short code number? How do I link that with a server? What programming language is the most efficient and effective for accomplishing the task? I have a little bit of programming experience in "HTML, JavaScript, PHP and C" and am willing to learn more languages if required. If someone could answer these questions for me I would be grateful.
Twilio offers this along with their other telephony services. I haven't actually used their SMS service, but I've heard good things about the company in general.
For less than 1/100 of the price of a dedicated shortcode, you can start with a "shared shortcode" provider like TextMarks.
TextMarks owns the "41411" shortcode, and you can lease keywords on it for use with your own applications.
You configure a callback URL, and any incoming SMS messages starting with your keyword get routed to your own web server as HTTP requests. If you respond with anything, your message even goes back to the user as another SMS response.
More info:
TextMarks SMS auto-responder API overview
[Disclosure: I built a large portion of the TextMarks API! Ask me anything.]
You will need a SMS server which is not very common. So you should look for providers like SMSMode or Essendex. But you'll have to pay to receive and send SMS.

Android: Get all sent sms? (outbox)

I'm writing an app to backup all text messages. Been working on it for a while and i just realized the method i'm using to retrieve sms' only gets the ones i got (the inbox).
Is it possible, in any way, to get the outbox?
If it's not in the Android API, is it possible to get it from the default SMS app somehow? Even if not everybody uses it it will work for now, it's kind of urgent.
to get the sent messages you need to read sent-directory
Use this Uri query
Uri.parse("content://sms/sent");

Categories

Resources