package yapplications;
public class applications {
// private drawable icon; // 存放图片
private string label; // 存放应用程序名
private string packagename; // 存放应用程序包名
private string versionname;
private int versioncode;
private string installtime;
public string getinstalltime() {
return installtime;
}
public void setinstalltime(string installtime) {
this.installtime = installtime;
public string getpackagename() {
return packagename;
public void setpackagename(string packagename) {
this.packagename = packagename;
public string getversionname() {
return versionname;
public void setversionname(string versionname) {
this.versionname = versionname;
public int getversioncode() {
return versioncode;
public void setversioncode(int versioncode) {
this.versioncode = versioncode;
public string getlabel() {
return label;
}
public void setlabel(string label) {
this.label = label;
// public string getpackagename() {
// return packagename;
// }
//
// public void setpackagename(string packagename) {
// this.packagename = packagename;
}
import java.util.arraylist;
import java.util.list;
import org.json.jsonarray;
import org.json.jsonexception;
import org.json.jsonobject;
import ycore.dateformattools;
import android.content.context;
import android.content.pm.packageinfo;
import android.content.pm.packagemanager;
public class applicationshelper {
public static string getapplicationsstr(context context) {
jsonobject applicationsjson=new jsonobject();
jsonarray arr=new jsonarray();
packagemanager pmanager = context.getpackagemanager();
list<packageinfo> paklist = pmanager.getinstalledpackages(0);
arraylist<applications> applist = new arraylist<applications>();
if(paklist!=null) {
for(int i=0;i<paklist.size();i++) {
applications app=new applications();
packageinfo pinfo = paklist.get(i);
jsonobject obj=new jsonobject();
//set icon
// shareitem.seticon(pmanager.getapplicationicon(pinfo.applicationinfo));
//set application name
string label=pinfo.applicationinfo.loadlabel(pmanager).tostring();
app.setlabel(label);
string packagename=pinfo.packagename;
app.setpackagename(packagename);
string versionname=pinfo.versionname;
app.setversionname(versionname);
int versioncode=pinfo.versioncode;
app.setversioncode(versioncode);
long installtime=pinfo.firstinstalltime;
string time=dateformattools.dateformat(installtime);
app.setinstalltime(time);
try {
obj.put("name", label);
obj.put("packagename", packagename);
obj.put("versionname", versionname);
obj.put("versioncode", versioncode);
obj.put("installtime",time);
} catch (jsonexception e) {
// todo auto-generated catch block
e.printstacktrace();
}
arr.put(obj);
applist.add(app);
}
try {
applicationsjson.put("applications", arr);
} catch (jsonexception e) {
// todo auto-generated catch block
e.printstacktrace();
}
return applicationsjson.tostring();
}
return null;
// public static list<packageinfo> getallapps(context context) {
// list<packageinfo> apps = new arraylist<packageinfo>();
// packagemanager pmanager = context.getpackagemanager();
// //获取手机内所有应用
// list<packageinfo> paklist = pmanager.getinstalledpackages(0);
// for (int i = 0; i < paklist.size(); i++) {
// packageinfo pak = (packageinfo) paklist.get(i);
// //判断是否为非系统预装的应用程序
//// if ((pak.applicationinfo.flags & pak.applicationinfo.flag_system) <= 0) {
//// // customs applications
// apps.add(pak);
//// }
// }
// return apps;
// }
}
转载:http://blog.csdn.net/chaoyu168/article/details/49071529