Get Application Info from package name

后端 未结 4 1108
太阳男子
太阳男子 2020-12-29 05:59

I have an application package name. Is there any way to get the icon, name of this application ? package name example: com.example.name

相关标签:
4条回答
  • 2020-12-29 06:41
    Drawable icon =getPackageManager().getApplicationIcon("ur_package");
    
    Strign label = context.getPackageManager().getApplicationLabel("ur_package");
    
    0 讨论(0)
  • 2020-12-29 06:49

    if you want to get installed app package name then this code will be helpful to you.

     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);
    
    0 讨论(0)
  • 2020-12-29 06:52

    Try something like:

        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();
        }
    
    0 讨论(0)
  • 2020-12-29 07:04
    String PackgeNameApp = "com.test.icon";
                String name="NULL";
                try
                {
                    ApplicationInfo app = this.getPackageManager().getApplicationInfo(PackgeNameApp, 0);
                    Drawable icon = getPackageManager().getApplicationIcon(app);
                     name = getPackageManager().getApplicationLabel(app).toString();
    
                }
                catch (PackageManager.NameNotFoundException e)
                {
                    //
                }
    
    0 讨论(0)
提交回复
热议问题