How To Get Another App's Version Name

I want to get Minecraft Pocket Edition's versionName (Example 0.13.0.b5).

This is package of MCPE (Minecraft Pocket Edition)

com.mojang.minecraftpe

I want to get version to String . How can I do this?

My code to get package name:

List<PackageInfo> packages = getPackageManager().getInstalledPackages(0);

PackageInfo mypackage = <com.mojang.minecraftpe>;

String versionName = mypackage.versionName;

Solution:

try
    {
        PackageInfo eInfo = getPackageManager().getPackageInfo("com.mojang.minecraftpe", 0);
        changelog=eInfo.versionName;
        lol.setText(changelog);
        }
    catch (PackageManager.NameNotFoundException e)
    {}

它从包管理器(通过包)获取包信息并返回版本名称:

PackageInfo packageInfo = getPackageManager().getPackageInfo("com.mojang.minecraftpe", 0);
return packageInfo.versionName;

 List<PackageInfo> apps = getPackageManager().getInstalledPackages(0);
 ArrayList<App> result = new ArrayList<>();

 for(int i=0;i<apps.size();i++) {
      PackageInfo p = apps.get(i);
      App newApp = new App();
      newApp.pname = p.packageName;
      newApp.versionName = p.versionName;
      newApp.versionCode = p.versionCode;
 }

 String minecraft = "com.mojang.minecraftpe";

 for (App name : result) {
        if (Objects.equals(minecraft, name.pname))
        String versionName = name.versionName;

 }

//----- class description ------

class App {
    String pname = "";
    String versionName = "";
    int versionCode = 0;
 }

If you want the version code, modify the 'if' condition in for loop with name.VersionCode.

Reference: PackageManager(Class for retrieving various kinds of information related to the application packages that are currently installed on the device.)

链接地址: http://www.djcxy.com/p/90766.html

上一篇: 如何在首选项活动中显示应用程序版本?

下一篇: 如何获得另一个应用程序的版本名称