Android to determine whether the application is a system program or a user program

Source: Internet
Author: User

Directly on the code:

Appinfo.java

<span style= "FONT-SIZE:18PX;" >package Com.example.packages;public class AppInfo {private String packname;private Boolean userapp;public string Getpackname () {return packname;} public void Setpackname (String packname) {this.packname = Packname;} public Boolean Isuserapp () {return userapp;} public void Setuserapp (Boolean userapp) {This.userapp = Userapp;}} </span>

Apptools.java

<span style= "FONT-SIZE:18PX;" >package com.example.packages;import java.util.arraylist;import Java.util.list;import android.content.Context; Import Android.content.pm.applicationinfo;import Android.content.pm.packageinfo;import Android.content.pm.packagemanager;public class Apptools {public static list<appinfo> Getappinfos (Context context) {Packagemanager pm = Context.getpackagemanager (); list<appinfo> Appinfos = new arraylist<appinfo> (); list<packageinfo> Packinfos = pm.getinstalledpackages (0); for (PackageInfo Packinfo:packinfos) {AppInfo AppInfo = New AppInfo (); String packname = Packinfo.packagename;appinfo.setpackname (packname); int flags = packinfo.applicationinfo.flags;//identity if ((Applicationinfo.flag_system & Flags) ==0) {//User program Appinfo.setuserapp (TRUE);} else{//System Program Appinfo.setuserapp (FALSE);} Appinfos.add (appInfo);} return Appinfos;}} </span>


Android to determine whether the application is a system program or a user program

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.