获取全部应用名跟包名

package com.llm.showpk;

import java.util.List;

import android.app.Activity;
import android.content.pm.PackageInfo;
import android.os.Bundle;
import android.widget.TextView;

public class MainActivity
    extends Activity {
    /** Called when the activity is first created. */
    TextView texView;
    String _info;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        texView = (TextView) findViewById(R.id.text);
        List<PackageInfo> packages = getPackageManager().getInstalledPackages(0);

        for (int i = 0; i < packages.size(); i++) {
            PackageInfo packageInfo = packages.get(i);

            _info +=
                packageInfo.applicationInfo.loadLabel(getPackageManager()).toString() + "->" +
                    packageInfo.packageName + "\n";
            texView.setText(_info);
        }

    }
}

 

posted @ 2013-01-14 14:09  灰太狼_lilongmin  阅读(226)  评论(0编辑  收藏  举报