Sms logs - Content resolver - android

I have few question about sms logs. Some of them are on the forum but I just want to get another opinion.
First of all I have read that it is not recommanded to use Content resolver for sms(getContentResolver().query(Uri.parse("content://sms/"..)) ) because it's not in the official api. Do you think there is a better way to get this information?
I would like also to trigger an action(like starting a service) when a message is received/sent. For received messages you can add a broadcast receiver with android.provider.Telephony.SMS_RECEIVED. Is there a way to do this also for the sent messages? From what I have seen Content observer works only when application is active and I would want something that can function all the time.
I want to know if there is a way to query deleted sms(including with Content resolver).
Thank you for your time.

Do you think there is a better way to get this information?
Better? No. There is worse - to obtain root privileges and query SMS db directly.
I want to know if there is a way to query deleted sms(including with
Content resolver).
I guess when data is deleted from db there's no way to get it back.

Related

Should I store messages in my database or query the system SMS database everytime?

I am developing an SMS app. I am getting messages from the Android Database every time user opens the App.
On a device with around 100 messages, it works fine. But with a device with 10,000 messages the app takes around 20 seconds to display the list after getting all the information.
To solve this, I am thinking about three possible options here:
Should I consider saving all the data to my own database? Will it make it faster?
Should I get some messages first, and then the rest in the background?
Any other option you might suggest.
Thanks in advance.
Below are the answers of your question
1. Should I consider saving all the data to my own database? Will it
make it faster?
No, don't do that. This will not make it faster. Same response you will get.
2. Should I get some messages first, and then the rest in the
background?
You can do this, but there is no need to do this to get all messages in background.Because User can see limited number of messages and chances are he will not see all messages down the bottom. So it will be useless to get those in background (untill or unless there is a business requirement)
Any other option you might suggest.
Yes, you need to implement pagination and need to keep track how many messages are needed to be loaded first time and while user scrolls then get more messages. In this case you need to keep track your own about how many messages you have already loaded and how many more you want to load. TO achive this, you will be required to implement PULL TO REFERESH mechanism of android. And a lot of tutorials can be found over the web.
Hope that answers your question.

How to determine where a contact was added?

I have been struggling with an approach to this problem for some time now. There is no Intent action fired off when a contact is added (as far as I know). What are my options to solve this issue?
Here are some ideas I have been playing with:
Firstly I kept a record of user locations with timestamps and periodically scan the Contacts DB and add new entries to my own DB with a timestamp. I could then compare these and try to find a decent match. I do not like this approach as it is very error prone.
Recently I've been looking at a ContentObserver for the Contacts DB, but I am not sure how to set this up so that it will constantly be observing, and not just when my app is in focus. Perhaps in a service? The documentation isn't clear to me about the life-cycle of a content observer, i.e does it die after the service/activity that registered it dies?
So really what I want is a seamless way to record where and when a user adds a contact when my app is installed on the device. It is not enough that the app should be in focus/running.
The second idea of yours is the correct one. The observer needs to be in a service as you had rightly guessed. Register the observer in the onCreate(). You will use contentProvider in the onChange of the contentObserver. You will need to maintain time when you last read the database using shared preferences. Note the changes of entries after the time stored in shared preferences. Now update the time of shared preferences to current time. Also unregister the content observer in onDestroy().

How to store flash information after call in android?

We get a flash message after a call finished.I need to take the details and store into sqlite db.
I need to get the duration and cost of that call from the flash message.
Then how to take this information.
You just use broadcast receivers to get the message. After that you have to parse the string to get the details like cost and time. But the main problem is different service providers have different format of flash messages. So you have to manage all these difficulties.
If I understand you want to be notified when some call is finished for storing the information in a sqlite database, right?
You can use a BroadCastReceiver that notifies you when the call state changes, here a brief explanation.
I don't sure if with the broadcast you get all the call information, if not you can always open the call log content provider example
Hope it helps :)

Android SQLite DB notifications

I am writing an Android app that needs to be notified whenever a given SQLite database changes (any new row added, deleted or updated).
Is there any programmatic way to listen to these notifications ?
Is writing DB triggers for each table the only way ?
SQLite provides Data Change Notification Callbacks. I don't think that Android exposes them directly but it does have for example CursorAdapter which provides some change notifications.
As thinksteep asked however, do you expect your DB to be changed outside the scope of your own application?
You can register an observer class such as DataSetObserver
Then whenever you change something you can call cursor.registerDataSetObserver(..) to register observe changes.
It's not well documented but I'm sure that there are some examples out there
You can use also use the getContentResolver().registerContentObserver but unfortunately it doesn't tell you what kind of change was made, it could be a delete, insert or update.
If you control the ContentProvider that interfaces with the DB then you could fire an Intent or use getContentResolver().notifyChange to send a special Uri notification that identifies both the table and action. An example Uri you could notify with might be: content://my-authority/change/table-name/insert
But even then you don't know exactly which rows were effected by the change.
Seems like triggers that write to a change log table will guarantee you hear about all changes regardless of where they came from, and you can know the exact id and action that occurred. Unfortunately it means slower inserts/updates/deletes and it means you probably need a Service of some kind to process and delete changes.
I'd love to hear if these is some better solution out there!

Check against a DB when an SMS is received on an Android phone

I want to develop an app that checks against a DB what to do after receiving an SMS, that is, it will receive a message and depending on the content or number or both, it performs different actions, it occurred to me that the best way to do this was by checking against a DB am I right? And if so, can this be done? I have no experience on Android dev.
A database is certainly one way to do this. Basically, any data storage mechanism that can be queried will work, be it an SQLite database of trigger strings, or simply a String[] array. It simply depends how many actions you wish your system to understand, and how complex they are.
First, there are many answers about SMS receiving stuff, i'm sure you can get these answers by searching.
And here i will give you some tips about that. There're two ways to observe on SMS receiving.
1.Register a BroadcastReceiver to listen on "android.provider.Telephony.SMS_RECEIVED"(google ti), and when your android receive a SMS message, it will call your BroadcastReceiver.
2.Observe on SMS database. Actually it's not database, it's Content Provider. In android OS, there're many content providers, you can register ContentObserver, whenever the SMS database changed, the OS will call your code.

Categories

Resources