Android to determine if the current interface is a desktop method

Source: Internet
Author: User

in the development of the desktop floating control, you need to view the current desktop through the service, so as to control the appearance and disappearance of the floating window, the following code is to determine whether the desktop method
  /** * Determine if the current interface is desktop */private Boolean ishome () {Activitymanager Mactivitymanager = (activitymana          GER) Getsystemservice (Context.activity_service);          list<runningtaskinfo> RTI = mactivitymanager.getrunningtasks (1);      Return Gethomes (). Contains (Rti.get (0). Topactivity.getpackagename ()); /** * Get the app package name for apps that belong to the desktop * * @return returns a list of strings that contain all the 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_d          EFAULT_ONLY);          for (ResolveInfo ri:resolveinfo) {names.add (ri.activityInfo.packageName);      } return names;   }


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.