从包名获取应用程序信息

时间:2013-01-19 19:06:25

标签: android

我有一个应用程序包名称。有没有办法得到这个应用程序的图标,名称? 包名称示例:com.example.name

4 个答案:

答案 0 :(得分:41)

尝试类似:

    try {
        ApplicationInfo app = this.getPackageManager().getApplicationInfo("com.example.name", 0);        

        Drawable icon = packageManager.getApplicationIcon(app);
        String name = packageManager.getApplicationLabel(app);
        return icon;
    } catch (NameNotFoundException e) {
        Toast toast = Toast.makeText(this, "error in getting icon", Toast.LENGTH_SHORT);
        toast.show();
        e.printStackTrace();
    }

答案 1 :(得分:1)

Drawable icon =getPackageManager().getApplicationIcon("ur_package");

Strign label = context.getPackageManager().getApplicationLabel("ur_package");

答案 2 :(得分:0)

def search(self, filename):
    with open('test.csv', 'r') as searchfile, open('weekly_test.txt', 'w') as search_results_file:
        for line in searchfile:
            if 'issue' in line:
                print >>search_results_file, line

    # At this point, both the files will be closed automatically

答案 3 :(得分:0)

如果您想要安装应用程序包名称,那么此代码将对您有所帮助。

 Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
                mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
                List<ResolveInfo> pkgAppsList = MainActivity.this.getPackageManager().queryIntentActivities( mainIntent, 0);
                Log.i("InstalledAPK",pkgAppsList.toString());


              for(int i=0;i<pkgAppsList.size();i++){
                  list.add(pkgAppsList.get(i).toString());
                  Log.e("PACKAGENAME",""+MainActivity.this.getPackageManager().getInstalledPackages(i).get(i).packageName);
              }


                ArrayAdapter<String> adapter=new ArrayAdapter<String>(MainActivity.this,android.R.layout.simple_list_item_1,list);
                listView.setAdapter(adapter);