I want to be able to get active notifications from my Android app on demand. (actually I just need to know if there are any)
I've been searching for this behavior and it seems, like I have only two options: NotificationManager.getActiveNotifications() which is exactly what I need, but is only available from SDK 23 or using a NotificationService but I really dislike this solution as I have to provide the permission to my app to read all notifications which is definitely an overkill.
Does anybody know about any solution which would behave like NotificationManager.getActiveNotifications() and not require SDK >= 23?
Thanks in advance!
You know which notifications you raised, because your code raised them.
In theory, you can know which notifications were removed, by using setDeleteIntent() to register a PendingIntent to find out when the user clears that notification. I have not used this in quite some time, so it is possible that this does not work as well as it used to.
But, if you know which notifications you raised, and you know which notifications were cleared, knowing which notifications are still outstanding is a matter of bookkeeping.
To be honest, "what are the active notifications?" feels like a code smell. There may be very good reasons for asking that question. If we were teammates, and this was part of code review, I would be asking why we care whether any given notification is active or not.
And, at this point, API Level 23 (Android 6.0) is six years old. You really should be reconsidering whether you should be supporting older versions of Android than that, given all the security problems that would remain on Android 5.x and older devices.
In my project, I used a static array to save all pending notifications.
This array will be cleared when the app come onto foreground.
Thanks.
Related
My questions are basically for AOSP code (Android version 4.3).
Questions:
1) When we change system language, already generated notifications are not updated to new language. Is it a bug in Android. If yes, why they are not supporting it(any major problem as such).
Is there any plan for supporting this?
2) If automatic updates are not supported by android, what is the best possible way of doing it?
Awaiting for positive reply on this.
Thanks,
Mayank
Updated answer.
No, it is not a bug and is working as intended I suppose.
Notification text is dynamic and there is no way the OS will know how to translate it automatically. The best thing to do is let the app handle it. I don't think it will be supported.. No at least anytime soon.
Best way is to override the onConfigurationChanged method and update all your notifications from within the method.
OK, so I have done some research and the consensus seems to be that you can't update android:updatePeriodMillis programatically.
It seems that you have to use AlarmManager instead, which seems like using a sledghammer to crack a nut... odd that the API doesn't just let you update the core updatePeriodMillis.
There's always a slight risk with relying on what's out there on the web, since APIs tend to develop and old answers are no longer relevant.
So I'm just checking that this is still the case. For example, the guide at http://developer.android.com/guide/topics/appwidgets/index.html at least hints that it is possible to change the update period of the AppWidgetProvider. When discussing updatePeriodMillis it says:
"You might also allow the user to adjust the frequency in a configuration—some people might want a stock ticker to update every 15 minutes, or maybe only four times a day."
And then goes on to talk about using AlarmManager but apparently only in relation to avoiding waking the device rather than to changing the update period.
Thanks for any help on this.
So I'm just checking that this is still the case.
Yes, it is still the case that you cannot update updatePeriodMillis. Which is too bad, as I'd love to see an updateUpdatePeriodMillis() method. Particularly if this were done via some sort of builder or transaction object, implying that it too might be changed via an updateUpdateUpdatePeriodMillis() method.
:-)
It seems that you have to use AlarmManager instead
You could use JobScheduler on Android 5.0+ as well, though I suspect that you won't like that much either.
You could also allow the user to configure some multiple of updatePeriodMillis, then only do your work every N updates, though this isn't terribly efficient.
Or, you could not update your app widget periodically at all, instead updating it only as needed based on app functionality, rather than based on time. IMHO, this is what most apps should be doing.
I would like to know the correct way to monitor system events and operating system activity in Android. My research so far indicates there are various methods for running Activities, Services, BroadCastReceivers, etc. but I don't have an overall comprehensive answer for everything I want to accomplish yet. I did come across an app today called "Carrier IQ" and was wondering how they do it. I believe their app is built into the kernel or at least the phone's OS image, something I want to avoid doing if at all possible.
I know that the Android SDK offers various ways to obtain
Since my app cannot be allowed to be suspended, should it run as a foreground service? If I do this, will I consume too many resources if I need to poll for various activity? I ask this because I don't think I can get everything through receiving events (i.e., using a BroadCastReceiver). I think I need a combination of polling and events.
I want to log sensors, events, OS activity, etc. for a user study. This is NOT for hacking or phishing purposes!
These are the top three projects that I think may accomplish something similar to what I want to achieve, but I have not yet determined if they are viable solutions:
android-hci-extractor
cellbots data logger
android-os-monitor
Does the Android manifest permissions list contain all of the permissions your app will need?
http://developer.android.com/reference/android/Manifest.permission.html
Then you can just ask for permissions when the app is installed and you should be able to access them.
I am using a phone without LED notifications. I would like to dev an app to simulate that, however first, with root, I would like to get access to the notifications system on the OS level (so it can be app-agnostic), to get the notifications.
How can I do so, or where can I read up more about this?
Thank you!
Despite this being old and already having an answer accepted, I want to offer an alternative solution since I think the end goal can be achieved. With all due respect to Mark, I think the direction the question is a little misleading, but the end goal is attainable.
If you are looking for something that would allow you to make an app that listens for notifications and then performs some action based on them regardless of the source app (or could be tailored to specific apps), then I think you can do this without writing firmware or rooting using an Accessibility Service. Accessibility Services would allow access to notifications as they come in, allowing your app to do something with them. You would be able to filter by the source package, get the notification contents, and a lot of other things.
There is a lot I could say on it, but it is still rather new to me, so I'll provide a couple of links to get started.
Accessibility Services page: http://developer.android.com/guide/topics/ui/accessibility/services.html
I would also recommend trying it out for yourself. I came across a small project file that I was able to copy and run on my own as a proof-of-concept. If you run this, you'll be able to see in the log that you really can read notifications: https://gist.github.com/qihnus/1909616
Don't forget to enable the accessibility feature for the app after you install it in your phone's accessibility settings.
You have to write your own firmware. This is not possible from an SDK application, rooted or not.
how can i get all the system notifications that are shown now?i want to write a programe that can intercept the notifications that other apps notified.
You cannot interfere with another appliactions notifications so it will not be possible to write such application.
This thread from the Android Beginners Google group answers the question with a solid "No." Quoting a user from the thread:
No, sorry. Intercepting notifications,
in particular, would be quite the
security loophole. In general, on
Android, one application cannot see or
mess with another application's
stuff. So, while your desired features
would be interesting for the OS
itself, they aren't going to be very
practical to implement in an
application written to the SDK.