How to determine whether an app is system ROM integration in Android

Source: Internet
Author: User

Codenong's style, directly on the code.

Android determines whether an app is system ROM integration:

Import android. app. activity; <br/> Import android. content. PM. applicationinfo; <br/> Import android. content. PM. packageinfo; <br/> Import android. content. PM. packagemanager. namenotfoundexception; <br/> Import android. OS. bundle; <br/> Import android. widget. textview; </P> <p> public class apptypeactivity extends activity {</P> <p> // software type judgment software <br/> // unknown software type <br/> Public static final int unknow_app = 0; <br/> // user software type <Br/> Public static final int user_app = 1; <br/> // System Software <br/> Public static final int system_app = 2; <br/> // system upgrade software <br/> Public static final int system_update_app = 4; <br/> // system + upgrade software <br/> Public static final int system_ref_app = system_app | system_update_app; </P> <p>/** called when the activity is first created. */<br/> @ override <br/> Public void oncreate (bundle savedinstancestate) {<br/> super. Oncreate (savedinstancestate); <br/> setcontentview (R. layout. main); </P> <p> // package name to be judged <br/> string pname = "com. hiapk. marketpho "; <br/> // text output in text <br/> stringbuffer sb = new stringbuffer (); <br/> Sb. append (pname ). append ("is:"); </P> <p> switch (checkapptype (pname) {<br/> case system_ref_app: <br/> // system ROM integration software <br/> Sb. append ("system_ref_app"); <br/> break; </P> <p> case user_app: <br/> // install software <br/> SB. append ("user_app"); <br/> break; </P> <p> default: <br/> // unknown software <br/> Sb. append ("unknow_app"); <br/> break; <br/>}</P> <p> textview TV = (textview) findviewbyid (R. id. textview); <br/> TV. settext (sb. tostring ()); </P> <p >}</P> <p>/** <br/> * check whether the app is integrated with the system ROM. <br/> * @ Param pname <br /> * @ return <br/> */<br/> private int checkapptype (string pname) {<br/> try {<br/> packageinfo pinfo = getpackagemanager (). get Packageinfo (pname, 0); <br/> // system software or System Software Update <br/> If (issystemapp (pinfo) | issystemupdateapp (pinfo )) {<br/> return system_ref_app; <br/>}else {<br/> return user_app; <br/>}</P> <p >}catch (namenotfoundexception E) {<br/> E. printstacktrace (); <br/>}< br/> return unknow_app; <br/>}</P> <p>/** <br/> * Whether it is a system software or an update software of the system software <br/> * @ return <br/> */<br/> Public Boolean issystemapp (packageinfo pinfo) {<br /> Return (pinfo. applicationinfo. Flags & applicationinfo. flag_system )! = 0); <br/>}</P> <p> Public Boolean issystemupdateapp (packageinfo pinfo) {<br/> return (pinfo. applicationinfo. flags & applicationinfo. flag_updated_system_app )! = 0); <br/>}</P> <p> Public Boolean isuserapp (packageinfo pinfo) {<br/> return (! Issystemapp (pinfo )&&! Issystemupdateapp (pinfo); <br/>}</P> <p>}

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.