android-package-determine if the installation application exists

Source: Internet
Author: User

Today, when modifying a bug, there is a problem, that is, after an application is uninstalled, the Super User permissions interface will still load the information about the application. When you modify, in order to facilitate, directly using the inside a load icon code as a condition, that is, if the application has been uninstalled, then this icon is not loaded in. However, others have pointed out the loophole of this method, because it is very likely that some applications themselves are not icons, although the likelihood of this situation is very small, but after all, this is a potential vulnerability. Then it is more rigorous, directly using the application installation or not to modify the judgment.

  The code is as follows

    

ImportAndroid.content.pm.ApplicationInfo;ImportAndroid.content.pm.PackageManager;Importandroid.content.pm.PackageManager.NameNotFoundException;ImportAndroid.content.pm.PackageInfo;Importjava.util.List;Private Booleancheckapkexist (Context context, String PackageName) {if(PackageName = =NULL|| "". Equals (PackageName)) {            return false; }           FinalPackagemanager Packagemanager =Context.getpackagemanager (); List< packageinfo> pinfo = packagemanager.getinstalledpackages (0); List<String> PName =NewArraylist<string>(); if(pinfo! =NULL) {             for(inti = 0; I < pinfo.size (); i++) {String pn=Pinfo.get (i). PackageName;            Pname.add (PN); }           }           returnPname.contains (PackageName); }   

Validation successful

android-package-determine if the installation application exists

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.