Is there any way to block SMS programmatically in Android KitKat? - java

Is this completely and utterly impossible in android Kitkat since Google has made so many changes to the way messaging works? I have tried using broadcast receivers and abortBroadcast, but to no avail.

Is there any way to block SMS programmatically in Android KitKat?
No. Starting with KitKat, the SMS_RECEIVED broadcast cannot be aborted, so any app with the RECEIVE_SMS permission can still listen for it and retrieve the incoming message. If your app is the default app, it can choose not to write the message to the Provider, so it will not appear to any app querying the Provider for messages, but even the default app cannot abort the SMS_RECEIVED broadcast.

Related

Android - Disable text message notifications programmatically

I'm working on an application that handles text messages. This is a personal application and I do not plan to release it, however it's basically going to allow me to share my text messages (and phone number) between numerous devices through the internet. It's a fun learning project too as a first application, and I've done quite a lot.
However the annoying part is the text-message popup that my device gets when receiving a message. I love it when I'm using the device, and I could always just go into the options and disable the popup when I'm not planning on using the device, but I'm a very, very forgetful person and turning it back on wont always happen. Then I'll never reply to messages.
Basically I want to programmatically interrupt (or not even notify) my default messaging application of the text message, however I still want it to be logged in my messaging history. So the message can't just be "discarded". This should only happen of-course while my applications service is running.
I've been searching through the android API for quite some time and I just can't seem to figure this out, is it possible and if so can you link me to the proper place in the API to begin?
Basically I want to programmatically interrupt (or not even notify) my default messaging application of the text message...
This isn't possible.
Assuming by "interrupt" you mean to prevent the default SMS app from issuing its Notification, you can no more do this with the default app than you could with any other app that you don't control.
Additionally, as the default SMS app responds to the SMS_DELIVER_ACTION broadcast, and it is the only app to receive this broadcast, it wouldn't be possible to "not...notify" the default app of an incoming message. Your app wouldn't even have a chance to abort the broadcast, even if it were possible to do so.
(In versions prior to KitKat, it was oftentimes possible to register a Receiver with a high priority for the SMS_RECEIVED_ACTION broadcast, and then abort the broadcast before the native SMS app received it. This is what rajan ks's answer refers to.)
...however I still want it to be logged in my messaging history.
The default SMS app is responsible for writing all incoming messages to the Provider. Even if you were able to prevent the default app from receiving the incoming message, your app would then have to write the message itself. This isn't really possible, either, as the default app is the only one with standard write access to the Provider.

Do SMS messages sent through Android's SmsManager appear in the normal Messaging app?

Do SMS messages sent through Android's SmsManager.sendTextMessage() appear in the normal Messaging app?
My tests suggest not, but I have limited access to devices, and none of them have active connections.
From the documentation:
Note: Beginning with Android 4.4 (API level 19), if and only if an app is not selected as the default SMS app, the system automatically writes messages sent using this method to the SMS Provider (the default SMS app is always responsible for writing its sent messages to the SMS Provider).
I can confirm that this is behavior that I've witnessed on all of the devices I've tested on (only 4 or 5 different ones, mostly newer Samsung and LG top end phones).
If you don't want your messages to appear in the stock Messaging app you have to get the user to set your app as the Default Message App.

Android: SMS receiver broadcast intent is triggered by unread sms'es at each reboot / at next SMS in chain

A schrödinbug appeared on one of my projects, where an Android application reportedly started to behave wrong on S4 running Hangouts (much like in Android. Error. Pop SMS notification after reboot).
I think this may be a common problem; so what are good ideas for filtering duplicate SMS broadcasts on Android?
http://developer.android.com/about/versions/android-4.4.html#SMS
I think this api will help you with the SMS part of Android.

Google Cloud Messaging listening broadcast receiver

In my android application i am using android push notification everything works fine until the user forces the application close(It happens always nowadays especially with the task monitoring application available in the play store).No more notifications are visible or possible.After some googling i found that From android 3.1, if the user force closes an app, it will stop to be notified of any broadcast until the user does not start your the again.
Is there any solution to prevent the broadcast receiver killing or any other possible (like making a Que of messages that aren't received by the device and send them later)?
if the user force closes an app, it will stop to be notified of any broadcast until the user does not start your the again.
sorry, that's not true. for sure.
I think you are confusing with something else: from android 3.x - broadcast receivers would never react to a broadcast until the app is launched for the first time.
if you implemented properly your GCM client side - it should work even if user force close the application. that's because the operating system waking up your application if it has the right broadcast intent filter and receiver, what mean that your application don't have to be running in order to receive this broadcast.
No more notifications are visible or possible
If your indication that the GCM not received is the fact that you don't see any Notification, then it's not necessarily true - there is no direct connection between GCM message to the system bar notifications. that's true that usually you'll show notification when push received, but it's deferentially not must.
what I'm saying basically - maybe you have a bug that takes affect after the user force close your app that causing the notifications not to be shown.

How to keep Listening for Push Notifications on Android in the background

I am working on Push Notifications in Android. Now the issue is that I want to keep running my Push Notifications on the back ground as soon as the app start because I have no idea when the server will push the data to the devices.
The main requirement is that our corporate app is having more than 10 activities and based on the notification received, I have to bring the related activity on the foreground so that user can preform action on that or do some silent action in the background regardless the activity is in foreground.
Can somebody suggest how can I implement this type of requirement. Do I need to do it in a Service.
Thanks
An Android application on an Android device doesn't need to be running to receive messages. The system will wake up the Android application via Intent broadcast when the message arrives, as long as the application is set up with the proper broadcast receiver and permissions.
take look at this;
http://developer.android.com/guide/google/gcm/gcm.html
when message received from gcm server
onMessage(Context context, Intent intent): method of GCMIntentService gets fire,
so you write your code there
take sample example from here
https://github.com/ketanpatel25/GCM-Demo/tree/master/gcm
What you're trying to do defeats the purpose of push notifications. In push notifications, the server sends the message through Google APIs. These APIs then send a broadcast message to your app, which you listen for. Continuously keeping the app open in the background and asking the server for new messages is called polling.
Read up on the GCM documentation. Whenever you receive a message, Android will ca the onMessage(); method of your GCMIntentService.

Categories