来源:http://blog.csdn.net/wal812834184/archive/2010/10/20/5953906.aspx
PackageManager()的使用列举相关的事件
文章分类:移动开发
看来这个东西应该专门开一个帖子了,发现这个包里面的东西太多,以前写的很零碎不容易找
查询系统使用的Content Providers
Java代码
1. for (PackageInfo pack : getPackageManager().getInstalledPackages(PackageManager.GET_PROVIDERS)) {
2. ProviderInfo[] providers = pack.providers;
3. if (providers != null) {
4. for (ProviderInfo provider : providers) {
5. Log.d("Example", "provider: " + provider.authority);
6. }
7. }
8. }
Java代码
1. for (PackageInfo pack : getPackageManager().getInstalledPackages(PackageManager.GET_PROVIDERS)) {
2. ProviderInfo[] providers = pack.providers;
3. if (providers != null) {
4. for (ProviderInfo provider : providers) {
5. Log.d("Example", "provider: " + provider.authority);
6. }
7. }
8. }
for (PackageInfo pack : getPackageManager().getInstalledPackages(PackageManager.GET_PROVIDERS)) {
ProviderInfo[] providers = pack.providers;
if (providers != null) {
for (ProviderInfo provider : providers) {
Log.d("Example", "provider: " + provider.authority);
}
}
}
Java代码
1. class PInfo {
2. private String appname = "";
3. private String pname = "";
4. private String versionName = "";
5. private int versionCode = 0;
6. private Drawable icon;
7. private void prettyPrint() {
8. log(appname + "\t" + pname + "\t" + versionName + "\t" + versionCode + "\t");
9. }
10. }
11.
12. private void listPackages() {
13. ArrayList<PInfo> apps = getInstalledApps(false); /* false = no system packages */
14. final int max = apps.size();
15. for (int i=0; i<max; i++) {
16. apps.get(i).prettyPrint();
17. }
18. }
19.
20. private ArrayList<PInfo> getInstalledApps(boolean getSysPackages) {
21. ArrayList<PInfo> res = new ArrayList<PInfo>();
22. List<PackageInfo> packs = getPackageManager().getInstalledPackages(0);
23. for(int i=0;i<packs.size();i++) {
24. PackageInfo p = packs.get(i);
25. if ((!getSysPackages) && (p.versionName == null)) {
26. continue ;
27. }
28. PInfo newInfo = new PInfo();
29. newInfo.appname = p.applicationInfo.loadLabel(getPackageManager()).toString();
30. newInfo.pname = p.packageName;
31. newInfo.versionName = p.versionName;
32. newInfo.versionCode = p.versionCode;
33. newInfo.icon = p.applicationInfo.loadIcon(getPackageManager());
34. res.add(newInfo);
35. }
36. return res;
37. }
Java代码
1. class PInfo {
2. private String appname = "";
3. private String pname = "";
4. private String versionName = "";
5. private int versionCode = 0;
6. private Drawable icon;
7. private void prettyPrint() {
8. log(appname + "\t" + pname + "\t" + versionName + "\t" + versionCode + "\t");
9. }
10. }
11.
12. private void listPackages() {
13. ArrayList<PInfo> apps = getInstalledApps(false); /* false = no system packages */
14. final int max = apps.size();
15. for (int i=0; i<max; i++) {
16. apps.get(i).prettyPrint();
17. }
18. }
19.
20. private ArrayList<PInfo> getInstalledApps(boolean getSysPackages) {
21. ArrayList<PInfo> res = new ArrayList<PInfo>();
22. List<PackageInfo> packs = getPackageManager().getInstalledPackages(0);
23. for(int i=0;i<packs.size();i++) {
24. PackageInfo p = packs.get(i);
25. if ((!getSysPackages) && (p.versionName == null)) {
26. continue ;
27. }
28. PInfo newInfo = new PInfo();
29. newInfo.appname = p.applicationInfo.loadLabel(getPackageManager()).toString();
30. newInfo.pname = p.packageName;
31. newInfo.versionName = p.versionName;
32. newInfo.versionCode = p.versionCode;
33. newInfo.icon = p.applicationInfo.loadIcon(getPackageManager());
34. res.add(newInfo);
35. }
36. return res;
37. }
class PInfo {
private String appname = "";
private String pname = "";
private String versionName = "";
private int versionCode = 0;
private Drawable icon;
private void prettyPrint() {
log(appname + "\t" + pname + "\t" + versionName + "\t" + versionCode + "\t");
}
}
private void listPackages() {
ArrayList<PInfo> apps = getInstalledApps(false); /* false = no system packages */
final int max = apps.size();
for (int i=0; i<max; i++) {
apps.get(i).prettyPrint();
}
}
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;
}
用这个方法来获取系统内所包含的Applications信息:
Java代码
1. private void listPackages() {
2.
3. ArrayList < PInfo > apps = getInstalledApps(false); /* false = no system packages */
4.
5. final int max = apps.size();
6.
7. for (int i=0; i < max; i++) {
8.
9. apps.get(i).prettyPrint();
10.
11. }
12. }
Java代码
1. private void listPackages() {
2.
3. ArrayList < PInfo > apps = getInstalledApps(false); /* false = no system packages */
4.
5. final int max = apps.size();
6.
7. for (int i=0; i < max; i++) {
8.
9. apps.get(i).prettyPrint();
10.
11. }
12. }
private void listPackages() {
ArrayList < PInfo > apps = getInstalledApps(false); /* false = no system packages */
final int max = apps.size();
for (int i=0; i < max; i++) {
apps.get(i).prettyPrint();
}
}
Java代码
1. 01 PackageManager manager = this.getPackageManager();
2.
3. 02 try {
4.
5. 03
6.
7. 04 PackageInfo info = manager.getPackageInfo(this.getPackageName(), 0);
8.
9. 05 String packageName = info.packageName;
10.
11. 06 int versionCode = info.versionCode;
12.
13. 07 String versionName = info.versionName;
14.
15. 08
16.
17. 09 } catch (NameNotFoundException e) {
18.
19. 10 // TODO Auto-generated catch block
20.
21. 11 }
Java代码
1. 01 PackageManager manager = this.getPackageManager();
2.
3. 02 try {
4.
5. 03
6.
7. 04 PackageInfo info = manager.getPackageInfo(this.getPackageName(), 0);
8.
9. 05 String packageName = info.packageName;
10.
11. 06 int versionCode = info.versionCode;
12.
13. 07 String versionName = info.versionName;
14.
15. 08
16.
17. 09 } catch (NameNotFoundException e) {
18.
19. 10 // TODO Auto-generated catch block
20.
环境: Ubuntu 10.10 64 bit jdk1.6
错误1:
/usr/include/gnu/stubs.h:7:27: error: gnu/stubs-32.h: No such file or directory
解决:
sudo apt-get install libc6-dev-i386
错误2:
host Executable: acp (out/host/linux-x86/obj/EXECUTABLES/acp_intermediates/acp)
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.4.3/libstdc++.so when searching for -lstdc++
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.4.3/libstdc++.a when searching for -lstdc++
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.4.3/libstdc++.so when searching for -lstdc++
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.4.3/libstdc++.a when searching for -lstdc++
解决:
sudo apt-get install g++-multilib
错误3:
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.4.3/../../../libz.so when searching for -lz
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.4.3/../../../libz.a when searching for -lz
/usr/bin/ld: skipping incompatible /usr/lib/libz.so when searching for -lz
/usr/bin/ld: skipping incompatible /usr/lib/libz.a when searching for -lz
/usr/bin/ld: cannot find -lz
解决:
sudo apt-get install lib32z1-dev
错误4:
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.4.3/../../../libncurses.so when searching for -lncurses
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.4.3/../../../libncurses.a when searching for -lncurses
/usr/bin/ld: skipping incompatible /usr/lib/libncurses.so when searching for -lncurses
/usr/bin/ld: skipping incompatible /usr/lib/libncurses.a when searching for -lncurses
/usr/bin/ld: cannot find -lncurses
解决:
sudo apt-get install lib32ncurses5-dev
错误5:
In file included from external/qemu/android/skin/window.c:19:
prebuilt/linux-x86/sdl/include/SDL/SDL_syswm.h:55:22: error: X11/Xlib.h: 没有那个文件或目录
prebuilt/linux-x86/sdl/include/SDL/SDL_syswm.h:56:23: error: X11/Xatom.h: 没有那个文件或目录
解决:
sudo apt-get install libx11-dev
[u][/u]android签名,包,userId:http://mypyg.iteye.com/blog/720406
Android应用及应用管理简介:http://www.ophonesdn.com/article/show/20
android核心分析 http://blog.csdn.net/maxleng