Android 获取本机安装的应用程序

package com.example.test;

import java.util.List;

import android.app.Activity;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.util.Log;

/**
 * 
 * @author WangJintao
 * 
 * @date 2013-10-9
 */
public class MainActivity extends Activity {

	String name;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		PackageManager manager = getPackageManager();
		List<PackageInfo> packageInfos = manager.getInstalledPackages(0);

		for (int i = 0; i < packageInfos.size(); i++) {
			PackageInfo packageInfo = packageInfos.get(i);
			if (packageInfo.versionName == null) {
				continue;
			}
			ApplicationInfo applicationInfo = packageInfo.applicationInfo;
			if ((applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) > 0) {
				name = applicationInfo.loadLabel(manager).toString();
				Log.e("系统app", name);
			} else {
				name = applicationInfo.loadLabel(manager).toString();
				Log.e("非系统app", name);
			}
		}
	}

}

你可能感兴趣的:(android,本机应用)