java - How to store the list of installed Android applications into an ArrayList? -
i got list of installed applications , want put them arraylist(for filtering purposes) organized in way - appname, packagename, icon.
the closest reference can find don't understand how implement / (use class , methods) code. can me this? in advance.
class pinfo { private string appname = ""; private string pname = ""; private string versionname = ""; private int versioncode = 0; private drawable icon; private void prettyprint() { log.v(appname + "\t" + pname + "\t" + versionname + "\t" + versioncode); } } private arraylist<pinfo> getpackages() { arraylist<pinfo> apps = getinstalledapps(false); /* false = no system packages */ final int max = apps.size(); (int i=0; i<max; i++) { apps.get(i).prettyprint(); } return apps; } private arraylist<pinfo> getinstalledapps(boolean getsyspackages) { arraylist<pinfo> res = new arraylist<pinfo>(); list<packageinfo> packs = getpackagemanager().getinstalledpackages(0); for(int i=0;i<packs.size();i++) { packageinfo p = packs.get(i); if ((!getsyspackages) && (p.versionname == null)) { continue ; } pinfo newinfo = new pinfo(); newinfo.appname = p.applicationinfo.loadlabel(getpackagemanager()).tostring(); newinfo.pname = p.packagename; newinfo.versionname = p.versionname; newinfo.versioncode = p.versioncode; newinfo.icon = p.applicationinfo.loadicon(getpackagemanager()); res.add(newinfo); } return res; }
here code working on.
public class appadapter extends arrayadapter<applicationinfo>{ private list<applicationinfo> applist = null; private context context; private packagemanager packagemanager; public appadapter(context context, int resource, list<applicationinfo> objects){ super(context, resource,objects); this.context = context; this.applist= objects; packagemanager= context.getpackagemanager(); } public view getview(int position, view convertview, viewgroup parent){ view view = convertview; if(null == view){ layoutinflater layoutinflater = (layoutinflater) context.getsystemservice(context.layout_inflater_service); view = layoutinflater.inflate(r.layout.activity_list_app,null); } applicationinfo data = applist.get(position); if(null != data){ textview appname = (textview) view.findviewbyid(r.id.app_name); textview packagename = (textview) view.findviewbyid(r.id.app_package); imageview iconview = (imageview) view.findviewbyid(r.id.app_icon); appname.settext(data.loadlabel(packagemanager)); packagename.settext(data.packagename); iconview.setimagedrawable(data.loadicon(packagemanager)); } return view; } public int getcount(){ return((null != applist) ? applist.size() : 0); } public applicationinfo getitem(int position){ return((null != applist) ? applist.get(position): null); } public long getitemid(int position) { return position; } }
Comments
Post a Comment