How to determine whether a package exists in the system for an activity

Source: Internet
Author: User

Tag: Io Div CTI new SP on res C

Determine whether a package exists in the system (from the network). After testing, it is easy to use:

Public Boolean checkbrowser (string packagename ){

If (packagename = NULL | "". Equals (packagename ))

Return false;

Try {

Applicationinfo info = getpackagemanager (). getapplicationinfo (

Packagename, packagemanager. get_uninstalled_packages );

Return true;

} Catch (namenotfoundexception e ){

Return false;

}

}

 

It is tested to determine whether an activity exists in the system (from the network:

Intent intent = new intent ();

Intent. setclassname ("package name", "package name. Activity name ");

If (getpackagemanager (). resolveactivity (intent, 0) = NULL ){

// This activity does not exist in the system

// After testing, the activity that is not in the system is indeed executed here

}

Else

{

// Some activities are actually executed here.

}

Note: after testing, the result of judging the self-contained package in this program is certainly exists and can only be used to determine the packages outside the program.

 

Public Boolean checkbrowser (string packagename) {If (packagename = NULL | "". equals (packagename) return false; try {applicationinfo info = getpackagemanager (). getapplicationinfo (packagename, packagemanager. get_uninstalled_packages); Return true;} catch (namenotfoundexception e) {return false ;}}

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.