开发者

How to get the List of Installed Applications in Android?

This is the source code...

public class GetAppList extends Activity {    
    @Override
    public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    try {
        List<PackageInfo> appListInfo = this.getPackageManager()
        .getInstalledPackages(0);
        JSONArray ja = new JSONArray();
        for (PackageInfo p : appListInfo) {
            if (p.applicationInfo.uid > 10000) {
                JSONObject jo = new JSONObject();
                jo.put("label", p.applicationInfo.name);
                jo.put("packageName", p.applicationInfo.packageName);
                ja.put(jo);
            }


        }
        System.out.println(ja);
    } catch (Exception e) {
        // TODO: handle exception
    }

    }
}

this is the result~

[{"packageName":"com.android.soundrecorder"},{"packageName":"com.android.alarmclock"},{"packageName":"com.android.sdksetup"},{"packageName":"com.android.launcher"},{"packageName":"com.google.android.providers.enhancedgooglesearch"},{"packageName":"com.gameloft.android.ANMP.GloftAsphalt5.asphalt5"},{"packageName":"com.android.contacts"},{"packageName":"com.zhang7nan.android"},{"packageName":"com.android.inputmethod.latin"},{"packageName":"irdc.ex03_19"},{"packageName":"com.android.calculator2"},{"packageName":"com.zhang7nan.getAppList"},{"packageName":"com.android.htmlviewer"},{"packageName":"com.androidbook.layout"},{"packageName":"irdc.EX05_04"},{"packageName":"com.android.browser"},{"packageName":"com.android.customlocale"},{"packageName":"com.android.music"},{"packageName":"com.android.netspeed"},{"packageName":"com.android.providers.userdictionary"},{"packageName":"com.android.inputmethod.pinyin"},{"packageName":"android.tts"},{"packageName":"com.andro开发者_StackOverflowid.providers.media"},{"packageName":"com.android.globalsearch"},{"packageName":"com.wd.AndroidDaemon"},{"packageName":"com.android.fallback"},{"packageName":"com.gameloft.android.GAND.GloftBia2.bia2"},{"packageName":"com.android.gesture.builder"},{"packageName":"org.lee.android"},{"packageName":"android.tether"},{"packageName":"com.android.providers.contacts"},{"packageName":"com.android.providers.applications"},{"packageName":"com.android.providers.drm"},{"packageName":"com.android.term"},{"packageName":"com.android.development"},{"packageName":"com.android.packageinstaller"},{"packageName":"com.svox.pico"},{"packageName":"com.android.camera"},{"packageName":"jp.co.omronsoft.openwnn"},{"packageName":"com.android.email"},{"packageName":"com.wandoujia.wandouapp"},{"packageName":"com.android.spare_parts"},{"packageName":"com.android.providers.downloads"}]

app name does not exist!help!


Here's a snippet illustrating what you want to do:


    public InstalledPackage(PackageManager pm, ApplicationInfo ai, Drawable defaultIcon) {
        name = ai.packageName;
        icon = defaultIcon;
        pkg = ai.packageName;
        if (ai.labelRes != 0) {
            name = (String) pm.getText(ai.packageName, ai.labelRes, ai);
        }
        if (ai.icon != 0) {
            icon = pm.getDrawable(ai.packageName, ai.icon, ai);
        }
    }

Keep in mind many packages won't have a label.


Solution:

    JSONArray ja = new JSONArray();
    try {
        HttpClient httpclient = new DefaultHttpClient();
        HttpPost request = new HttpPost(sendDataUrl.toString());
        List<NameValuePair> params = new ArrayList<NameValuePair>();
        PackageManager pm = context.getPackageManager();
        List<PackageInfo> appListInfo = pm.getInstalledPackages(0);
        for (PackageInfo p : appListInfo) {
            if (p.applicationInfo.uid > 10000) {
                JSONObject jo = new JSONObject();
                jo.put("label", p.applicationInfo.loadLabel(pm).toString());
                jo.put("packageName", p.applicationInfo.packageName);
                ja.put(jo);
            }

        }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜