I want to be able to control incoming text messages. My application is still on a "proof of concept" version and I'm trying to learn Android programming as I go.
First my application need to catch incoming text messages. And if the message is from a known number then deal with it. If not, then send the message as nothing has happened to the default text message application.
I have no doubt it can be done, but I still have some concern and I see some pitfalls at how things are done on Android.
So getting the incomming text message could be fairly easy - except when there are other messaging applications installed and maybe the user wants to have normal text messages to pop up on one of them - and it will, after my application has had a look at it first.
How to be sure my application get first pick of incoming text messages?
And after that I need to send most text messages through to any other text message application the user has chosen so the user can actually read the message my application didn't need.
Since Android uses intents that are relative at best, I don't see how I can enforce my application to get a peek at all incoming text messages, and then stop it or send it through to the default text messaging application.
Espen,
The answer to this is multi-part. Understand first that our company has resolved this problem, but the solution is temporarily proprietary, so I will answer what I can without causing conflict either here or for my company.
1) You can never insure that your App ever gets first pick. What you can do is make your processing "fast enough" that is does not matter.
2) Intents ARE an absolute if you force the issue. Our company uses a concept called intent routing. This insures that the data is sent to the appropriate app. The most basic idea is that when you receive the SMS, you create a New Intent (not the same one) and send it to the class directly. This has some special considerations, but should give you some direction.
Unfortunately, without violating my company's confidence or stackoverflow's policies, I cannot say anymore publicly until the solution is made public (within the next month).
FuzzicalLogic
Retriving all incoming messages is just setting up listener, you can do it easily see here
and after that, its fine if you are at do nothing phase, but in case you want to prevent sms to go into the native messaging app it is not advisable to prevent user.
better you wait for some time and then delete the same from SMS database.
Related
I want to write an android app that changes the android standard message sms GUI giving it an extra send button. The one send button should be the usual one and the other should be the one that uses my application to send the message. How do I add this extra button in the android standard sms message GUI? Anyone got an example code on how to do this?
Kind regards
Benjamin
Ok, this you Cannot do for phones which are in the market. You will need to grab hold of the sources and come up with a custom ROM for users to flash.
However, as another option, you can build your own SMS application and let users install so. When users need to send a SMS, they will be asked whether we default/your app needs to be used. This way is a much cleaner approach and more reachable to users.
I know I can detect a message that is being sent using the following code
ContentResolver contentResolver = context.getContentResolver();
contentResolver.registerContentObserver(Uri.parse("content://sms"),true, myObserver);
what I need to know, is it possible to prevent it from going out or suspend it?
Thanks
Not possible unless you are the Messaging application that the user typed the message in to (then you could do whatever you want with it, including not send)
However if the user is using the stock Messaging app or another 3rd party one there is not a way for a different application to try to stop the SMS from being sent (this ability would almost certainly get abused.)
I think there are apps meant for use when driving that will block incoming texts from being shown to user, maybe look in to those, if there is a way to do outgoing maybe they'll have figured it out. I don't think it is going to be possible on a stock device though.
I have an android app which needs to keep sending SMS. My problem is that whenever we send a message we get a pop up showing (your SMS charges and your curent talktime balance in phone). When i send many SMS these pop ups keep getting accumulated one over the other which is undesirable for me. I need a way out to either remove or somehow consume these pop ups.
Any ideas ??
a pop up? Do you mean a toast? or notifications accumulating below the status bar?
You'll have to pardon my seemingly simple question. In the US, I've had multiple Android phones on at least two carriers, and I don't get any such message in any form, but may be that's because I've always had unlimited texting so additional texts do not cost me anything.
I bet you're talking about notifications accumulating in the status bar. So if your carrier is doing that, take a look at the code in the "API Demos" > App > Notification > Status Bar
There in the callback attached to the "Clear Notification" button, you'll find the code you're looking for.
And if I could suggest something, I know that many notifications accumulating on top of each other can be super annoying, but if you can try to consolidate all those notifications into one notification at least with the running count (unless your user explicitly opts out from being notified). This way, you still communicate to the user the most important part of the information - how many texts in total his phone has been sending so far, without completely overwhelming him with many-many notifications about basically the same event happening over and over again.
For those who don't know, "API Demos" is a free application you can download from the Market. And there may be several to choose from, so just pick the one with five stars next to it, but "API Demos" is also the same sample code that comes with different SDKs when you download it with the SDK Manager, and you can access that code when you create a new Android Project with the New Android Project... wizard from within Eclipse and then select the radio button "Create Existing Project from Sample" (or something like that, I don't have Eclipse in front of me, so the wording may be slightly incorrect). And of course, if you don't use Eclipse, you can always find that sample code through the Sample code directory itself.
As a potentially more elegant alternative, or may be just in case your carrier is indeed crude enough to pop up an actual modal dialog every time a text is sent, it may be that your carrier is using a broadcast receiver to trigger those notifications or those dialogs, so if that's the case, and hopefully the carrier isn't using "100" as a priority for its receiver, it may be possible for you to register a receiver with "100", and then kill the broadcast before it propagates to the other receivers. But of course, that's assuming that your carrier designed it that way for you.
Thank you for taking the time to help me out. I don't know if this is even possible but I though it would be worth asking seeing as it is vital for my app :/ In simple terms, what I want is for a function in my application (e.g. a Toast text to show or something) to be fired when another application is doing something -- like if I send a text message in the messaging application. (example - I send a text in the text msg app and (my app is running in background as a service or something) a Toast (created by my app) displays "You sent a text!".
Thank you for your feedback!
Sincerely,
Jackson Smith
You can't do it in general for every action, and I don't know if you can do it specifically for texting.
However, for some actions (like screen lock/unlock, wifi up/down etc.) either the android system or the application causing the action will broadcast an intent that you can catch with a BroadcastReceiver (if you have the right permissions to do it). You need to know what intent you want to respond to and what permissions you need to be able to receive it.
I am developing one GPS based application. in that i given few default values to user those are phone number which will used to make a phone call. and server address which is used to sent the location data to server.. In this I got 2 major and critical problems..
1) I have hide that default values in regular menu and that should display when user presses some key or combination of keys then only it should display.
2)When ever the Default phone number and server address is changed at provider side that should be updated at user side that should happen through SMS from a specific number in a encrypted format by accepting that SMS those values has to change
Please Any body knows about these things help which are very very very useful to me
Thanks for reading
Lots of good info here.
Having used SMSes to communicate with apps in the past, I highly recommend finding another way if possible. The messages coming in are often gibberish to the user, and practically never contain any information that the user needs to know about. They're confusing and they clutter up the user's phone experience.
I'd recommend using WAP pushes or periodic device-side checks instead. If you have to use SMSes, you may want to consider using the SMS content provider to delete the messages after your application responds to them. It'll still be annoying to the user, but at least you won't be leaving behind garbage in their messaging app. Be aware though that the SMS/MMS content providers aren't published, which means that they're not guaranteed to work, manufacturers can modify them however they want, and they could be phased out in a future SDK release.