I created a BroadcastReceiver and configured it with an android.provider.Telephony.SMS_RECEIVED action filter so it is called everytime the phone receives a text.
Is there some event/action or other way for my application to be notified whenever the phone sends a text (preferably independent of the application that sends it)?
So far the only option I see is to poll the content provider for content://sms/sent which doesn't even give me all sent texts because applications can choose not to put it there.
Unfortunately there is (currently) no way to implement a BroadcastReceiver because the standard sms application uses a SmsManger to send the messages but specifies concrete internal classes for the sent and delivered intents (SmsReceiver.class and MessageStatusReceiver.class respectively). Not that it is any consolation but you can find the following comment in the Sms application's source:
// TODO: Fix: It should not be necessary to
// specify the class in this intent. Doing that
// unnecessarily limits customizability.
The best alternative seems to be polling content://sms/sent, potentially using a ContentObserver.
Related
Seems like GCM for Android only works if there is internet. Wondering whether there are any other methods (maybe via text/call, etc) that could trigger a background service which would send back user's location (via text, etc. or maybe keep it until connection is present)?
My two concerns are:
How much can I do without the user doing anything (or even knowing it's happening... assuming they downloaded the app already and gave appropriate permissions)?
How would I send the data back? (if via text, Reason #1 seems to be a bigger matter)
Here is an alternate solution but it is costly,
Create Broradcast Receiver that listen for incoming SMS.
In any sms with start some predefined word like "START_SERVICE" is arrived then fire the broadcast and start the service you want.
You may use normal SMS scheme or any bulk sms kind of service.
The above scenario doesn't require any INTERNET connection at all.
I am new in Android development and I'm doing an SMS app that receives multiple SMSes i.e notification SMS that's captured into the ListView and another SMS that contains the location of the sender for use in displaying the sender's location on google map.I've managed the first part,how do I listen again for the second SMS using the BroadcastReceiver...In other words how to listen for an incoming SMS when multiple different SMSes are expected.
If you impleted correctly the BroadCastReceiver you shouldnt worry about the second time, it would be fired automatically. You should post your code to have more information.
Welcome to Android development!
In order to receive incoming SMS's, you need to use the BroadcastReceiver mechanism that listens to incoming SMS's intent.
But, If you want to be sure that the message is going throw your app before it gets into the System's database, you have to give your BroadcastReceiver's Class a high priority on the manifest.
Good Luck.
What will happen when in an handset there are some apps which have defined some action on onReceive() method for any incoming SMS and any one app is calling abortBroadcast() method to remove sms from Inbox. Of course, I don't know that what priority they have defined in their App for their listener.
So in such scenario suppose I also want to perform some action on any incoming sms and also want to keep it in user's Inbox folder then how I will get that SMS when some other app have already read it and removed it too.
Since sms is a protected broadcast and only Android framework can send the broadcast, no one can do a abortBroadcast on it.
For storing of sms you should never use the Default sms contentProvider, since that will be updated by system Messaging application. You should use your own db or just fetch the items from the db already stored by default messaging application.
I am developing the app which holds the messages in it's own inbox rather than the native inbox.
This can be achieved only if the incoming messages are prevented from reaching the native inbox.
There is some attribute android:priority in <intent-filter>, by which message can be first received by current receiver than others.
But I do not know how to do it properly, does anyone know?
I assume you mean SMS messages? The best, and only AFAIK, is to receive the message via registering the proper BroadcastReceiver object, copying the message into your database, marking it is read in the SMS ContentProvider and then deleting it from the SMS ContentProvider. Check out this article on how to receive SMS messages and then check out this SO post on how to use the SMS content provider.
Edit I actually stand corrected, there is another method that I've had sometimes limited success with. In the BroadcastReceiver you can call the abortBroadcast() method to cancel the broadcast. The important thing here is that you register your receiver with an intent filter that has a higher priority (say, 100) so that it receives the SMS before anybody else does.
I want my AppWidgetProvider (which is a direct subclass of BroadcastReceiver) to be notified when the user reads a previously unread sms or when he opens the list of missed calls. So far I gound out that it seems to be impossible to get a Intent delivered to the BroadcastReceiver as the actions that open the (sms/phone) activities are not broadcast actions.
Is there another way to let a BroadcastReceiver know when an unread sms is read or the missed calls list is opened?
Short answer: no, sorry.
Neither "unread sms is read" nor "missed calls list is opened" are part of the operating system. They are features of applications. Different implementations of those applications are found on different devices. None have any sort of broadcasts of this nature, AFAIK, mostly because none have any sort of authorized and supported API for developers to use.