Android determines whether the current interface is a desktop method.

Source: Internet
Author: User

Android determines whether the current interface is a desktop method.
When developing a desktop floating control, you need to check whether the current desktop is used through the service to control the appearance and disappearance of the floating window. The following code is to determine whether the screen is a desktop.

/*** Determine whether the current interface is desktop */private boolean isHome () {ActivityManager mActivityManager = (ActivityManager) getSystemService (Context. ACTIVITY_SERVICE); List <RunningTaskInfo> RRTI = mActivityManager. getRunningTasks (1); return getHomes (). contains (rrps. get (0 ). topActivity. getPackageName ());} /*** get the application package name of the desktop application ** @ return returns a String List containing all Package Names */private List <String> getHomes () {List <String> names = new ArrayList <String> (); PackageManager packageManager = this. getPackageManager (); Intent intent = new Intent (Intent. ACTION_MAIN); intent. addCategory (Intent. CATEGORY_HOME); List <ResolveInfo> resolveInfo = packageManager. queryIntentActivities (intent, PackageManager. MATCH_DEFAULT_ONLY); for (ResolveInfo ri: resolveInfo) {names. add (ri. activityInfo. packageName);} return names ;}



Code snippet used by android to determine whether a desktop shortcut exists

Let's take a look at this: www.javaeye.com/..horcut

How does android determine whether the activity jump interface exists?

Programmers write this Activity on their own. How can you not know whether the Activity exists or not! So there is no need to judge it!

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.