Android, Detect when other apps are launched

后端 未结 7 1161
臣服心动
臣服心动 2020-11-22 02:41

I\'m trying to develop an app that prevents a user from getting to a specified app without a password. The scenario is...

  1. user clicks on \"Email\" app (for exa
7条回答
  •  醉梦人生
    2020-11-22 03:20

    getRunningTasks() is deprecated in Android L.

    To obtain app usage statistics you can use UsageStats class from android.app.usage package.

    The new App usage statistics API allows app developers to collect statistics related to usage of the applications. This API provides more detailed usage information than the deprecated getRecentTasks() method.

    To use this API, you must first declare the android.permission.PACKAGE_USAGE_STATS permission in your manifest. The user must also enable access for this app through Settings > Security > Apps with usage access.

    Here is a basic app example showing how to use App usage statistics API to let users collect statistics related to usage of the applications.

提交回复
热议问题