This question has been answered elsewhere but all solutions use ".getRunningTask()", which has been depreciated in the most recent API. I am trying to make an app that allows people to monitor their phone use and need to know when an app come to the foreground and when the foreground app changes.
I think if you have a look at this answer you will find what you are looking for:
https://stackoverflow.com/a/27304318/1173391
Related
I have a simple Android app I have been working on for a few weeks.
The app is a diary to which you can set tasks you have to complete.
I need the app to have a functionality in which it will save an object to room at 12:00 am while the app is either open, open in the background, or completely closed.
My question to you is what do you think would be the best and most efficient approach for building this feature?
Thank you
I think the best fit for this might be WorkManager: https://developer.android.com/topic/libraries/architecture/workmanager
You are basically abstracting out most of the other obvious choices, like AlarmManager, Services (background/foreground) - WorkManager lets the OS pick the best approach for your device and you only have to define it once.
Scheduling for specific times like you want is covered here: https://developer.android.com/topic/libraries/architecture/workmanager/how-to/define-work#schedule_periodic_work
for a university project I have to track the screen time of an android smartphone. It's hard to find proper search results, because my search engines do only suggest apps, that already do this for you. I am interested in how these apps do this. I assume, there is a native API on android which supports you with this. Unfortunately, I can't find anything that already does this.
The app is supposed to run a little service which tracks the time of the screen activity and other stuff (like location). It would be great, if someone of you can help me out on where to look for examples and where to find information about the android API.
Edit:
To be a bit more precise: It's about the overall screen time, not about the screen time a specific app has.
Broadcast Actions might be a solution for this,
ACTION_SCREEN_ON
ACTION_SCREEN_OFF
https://developer.android.com/reference/android/content/Intent.html#ACTION_SCREEN_ON
https://developer.android.com/reference/android/content/Intent.html#ACTION_SCREEN_OFF
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.
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.