Android app lock get foreground process package name method

Source: Internet
Author: User

Today in the technical summary, the way to share knowledge, personal advocating sharing.

Get the package name of the foreground process in the following ways:

1.android API 10-20

Obtained by Getrunningtasks in Activitymanager.

2.android API 21-22 ( part of the Google update package is not upgraded)

Because the system disables the Getrunningtasks interface above API 21.

Get through getrunningappprocesses in Activitymanager

Cons: Possible miscarriage (probability is low)

3.android API 22

Because the system has disabled the Getrunningappprocesses interface above 22.

Combined with/proc/pid/oom_adj values and bg_non_interactive

Cons: Possibility of miscalculation (probability generally)

4.android API and above:

Combined with/proc/pid/oom_score values and bg_non_interactive

Cons: Possible miscarriage (higher probability)

5. Android API 22 and above:

Obtained by Usagestatsmanager's queryevents interface after opening usagestats permissions

Android app lock get foreground process package name method

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.