[Android] How to find out whether an intent is available (queryintentactivities)

Source: Internet
Author: User

Finding out if an intent is available

Sometimes you want to find if an application has registered for a certain intent. For example you want to check if a certain holding er is available and if you enable some functionality in your app.

Sometimes you want to know whether a certain AP has registered a clear intent. For example, you want to check whether a certain receiver exists, then, enable some functions in your AP based on whether the hacker exists.

This can be done via checking the packagemanager. The following code checks if an intent exists. You can check via this method for intent and change your application behavior accordingly for example disable or hide menu items.

You can check packagemanager.CodeCheck whether an intent exists.

Public Boolean isintentavailable (context, string action) {final packagemanager = context. getpackagemanager (); Final intent = new intent (action); List <resolveinfo> resolveinfo = packagemanager. queryintentactivities (intent, packagemanager. match_default_only); If (resolveinfo. size ()> 0) {return true;} return false ;}

This articleArticleIt is a bit similar to the previousDetermine whether an AP exists in the system (packagemanager and packageinfo)

 translated from; http://www.vogella.de/articles/AndroidIntent/article.html 
 
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.