As ActivityManager.getRunningTasks is deprecated from API level 21. So I decided to use UsageStatsManager instead. But getSystemService(USAGE_STATS_SERVICE) is only available from API level 22. That means I can only get the foreground package name in devices with API level >= 22 and <= 20. What about API 21 devices.
Get foreground app API level 21
2.2k Views Asked by The Dark Knight At
1
There are 1 best solutions below
Related Questions in ANDROID
- Creating global Class holder
- Flutter + Dart: Editing name of a tab shows up a black screen
- android-pdf-viewer Received status code 401 from server: Unauthorized
- Sdk 34 WRITE_EXTERNAL_STORAGE not working
- ussd reader in Recket Native module
- Incorrect display of LinearGradientBrush in IOS
- The Binary Version Of its metadata is 1.8.0, expected Version is 1.6.0 build error
- I can't make TextInput to auto expand properly in Android
- Creating multiple instances of a class with different initializing values in Flutter
- How to create a lottie animation
- making android analyze with coverity sast tool
- Flutter plugin development android src not opening after opening example
- I initialize my ViewModel in the Activity with several fragments as tabs, but the fragments(tabs) return null for the updated livedata
- Node.js Server + Socket.IO + Android Mobile Applicatoin XHR Polling Error...?
- How I can use the shared preferences class?
Related Questions in API
- Google Sheets API - Append Request not working
- Is there really no product for docs that has these?
- How to show suggested content in response using Azure Cognitive Search?
- error message when closing current position in binance futures, using ccxt library
- How to filter API data in React Native
- I have fetched an API with JS, but the output looks really bad and I don't know how to fix it
- Session is not storing in react and Asp Dot Core Web API
- Apex charts not rendering series value, showing cannot map values of NULL
- Configure IIS to accept API calls only from API Manager, Deny from direct calls
- Problems with API return using the Axios library in NextJS
- How to query by Iteration in pyral?
- Is there a way to have a user enter a url query and have a single function filter a database?
- Cant get value in Vue from data
- Read stories/posts using instagram API
- Need To Make Minor Change To REST API Response
Related Questions in FOREGROUND-SERVICE
- Is there a way to programatically exit split-screen or free-form window mode in Android?
- My Foreground service is crashing on Android 14
- Android 14 is not updating notifications using startForegroundService
- App using 3rd party SDK (Zoom Meeting SDK) has been rejected due to Foreground service permissions
- Keep a webview app of Android running in the background
- How to Prevent Foreground Service from Stopping on Clear All from Recent Apps on MI, Redmi, Xiaomi Devices?
- Is it a good idea to use SharedViewModel (with Flow inside it) between a ForegroundService and a UI Component (Fragment/ Composables)
- Handling Data Transmission in Foreground Service with WebSocket and Managing Downtime
- PeriodicWorker doesn't show notifications
- How to ensure that my foreground service will be running as long as possible?
- Service.startForeground() not allowed due to mAllowStartForeground false on Android 14
- Android 14 launching apps from foreground service
- How I can Start a foreground service on clicking a widget of an android app and I don't want to open any another activity just want to run a service
- is startService() then calling startForeground in service same as startForegroundService call?
- Android 34 - foreground location service started from background
Related Questions in USAGESTATSMANAGER
- Android how to detect apps running in split screen mode
- How to get live app usage stats in android
- How to restrict or detect an active camera device in a background process in Android?
- Application Usage Time Tracking Application for IOS with React Native
- UsageStatsManager.queryEvents does not return SCREEN_INTERACTIVE and USER_INTERACTION event in Android 11
- Getting foreground app not working on Android 14
- WearOS hidden permission "usage access" (how to permit?)
- How can I retrieve screen time for all apps used in the past 24 hours using UsageStatsManager in an Android app developed in Kotlin?
- Android Usage Stats Manager, how can I find out the apps for a specific time perios (couple of minutes)?
- How can we get other apps' screen time in react native? Is there any library or package available in react native?
- Is there a way to have more granular data using UsageStats in Android
- Android UsageStatsManager: queryEvents return null for Android R+
- Android Apps Usage Stats - how to get accurate result
- Trying to get lunch count using mAppLaunchCount from UsageStats
- Android - queryAndAggregateUsageStats returns empty map
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
Popular # Hahtags
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
I am also using UsageStatsManager now to get the foreground app, and I'm running 5.0.1. Even though Android Studio says it is available from 22, it still works.
Using some code like this: https://stackoverflow.com/a/30778294/969016