之前的文章向大家介绍了几个项目中常用的实用功能,那么在这篇文中,我将向大家介绍如何获取Android手机中已经安装的手机应用程序,好了,废话不多说,直接上代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
private String getInstalledAppListAsString(){
PackageManager pm = context.getPackageManager();
List<ApplicationInfo> apps = pm.getInstalledApplications(PackageManager.GET_GIDS);
StringBuffer stringBuffer = new StringBuffer();
for (ApplicationInfo app : apps) {
if (pm.getLaunchIntentForPackage(app.packageName) != null ) {
// apps with launcher intent
if ((app.flags & ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) == 1 ) {
// updated system apps
} else if ((app.flags & ApplicationInfo.FLAG_SYSTEM) == 1 ) {
// system apps
} else {
// user installed apps
stringBuffer.append(app.packageName).append( ';' );
}
}
}
return stringBuffer.toString();
}
|
下面我们看看具体如何获取各个应用的相关信息呢
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
package cn.lyz.mobilesafe.domain;
import android.graphics.drawable.Drawable;
/**
* 获取的应用基本信息实体类
* @author liuyazhuang
*
*/
public class AppInfo {
//图标
private Drawable app_icon;
//应用名称
private String app_name;
//应用版本号
private String app_version;
//应用包名
private String packagename;
//是否是用户app
private boolean isUserApp;
public AppInfo() {
super ();
// TODO Auto-generated constructor stub
}
public AppInfo(Drawable app_icon, String app_name, String app_version,
String packagename) {
super ();
this .app_icon = app_icon;
this .app_name = app_name;
this .app_version = app_version;
this .packagename = packagename;
}
public AppInfo(Drawable app_icon, String app_name, String app_version,
String packagename, boolean isUserApp) {
super ();
this .app_icon = app_icon;
this .app_name = app_name;
this .app_version = app_version;
this .packagename = packagename;
this .isUserApp = isUserApp;
}
public Drawable getApp_icon() {
return app_icon;
}
public void setApp_icon(Drawable app_icon) {
this .app_icon = app_icon;
}
public String getApp_name() {
return app_name;
}
public void setApp_name(String app_name) {
this .app_name = app_name;
}
public String getApp_version() {
return app_version;
}
public void setApp_version(String app_version) {
this .app_version = app_version;
}
public String getPackagename() {
return packagename;
}
public void setPackagename(String packagename) {
this .packagename = packagename;
}
public boolean isUserApp() {
return isUserApp;
}
public void setUserApp( boolean isUserApp) {
this .isUserApp = isUserApp;
}
@Override
public String toString() {
return "AppInfo [app_icon=" + app_icon + ", app_name=" + app_name
+ ", app_version=" + app_version + ", packagename="
+ packagename + ", isUserApp=" + isUserApp + "]" ;
}
}
|