Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

[package_info] calling new method for BuildNumber in new android versions #1275

Merged
merged 4 commits into from
Mar 11, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import io.flutter.plugin.common.PluginRegistry.Registrar;
import java.util.HashMap;
import java.util.Map;
import android.os.Build;

/** PackageInfoPlugin */
public class PackageInfoPlugin implements MethodCallHandler {
Expand Down Expand Up @@ -42,7 +43,7 @@ public void onMethodCall(MethodCall call, Result result) {
map.put("appName", info.applicationInfo.loadLabel(pm).toString());
map.put("packageName", context.getPackageName());
map.put("version", info.versionName);
map.put("buildNumber", String.valueOf(info.versionCode));
map.put("buildNumber", String.valueOf(getLongVersionCode(info)));

result.success(map);
} else {
Expand All @@ -52,4 +53,12 @@ public void onMethodCall(MethodCall call, Result result) {
result.error("Name not found", ex.getMessage(), null);
}
}

private static long getLongVersionCode(PackageInfo info) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
return info.getLongVersionCode();
}
//noinspection deprecation
return info.versionCode;
}
}