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

Commit 5afa9d5

Browse files
ivk1800Chris Yang
authored and
Chris Yang
committed
[package_info] calling new method for BuildNumber in new android versions (#1275)
Fixed flutter/flutter#28155 We kept the old method for backward compatibility.
1 parent 4b24153 commit 5afa9d5

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

packages/package_info/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.4.0+2
2+
3+
* Android: Using new method for BuildNumber in new android versions
4+
15
## 0.4.0+1
26

37
* Log a more detailed warning at build time about the previous AndroidX

packages/package_info/android/src/main/java/io/flutter/plugins/packageinfo/PackageInfoPlugin.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import android.content.Context;
88
import android.content.pm.PackageInfo;
99
import android.content.pm.PackageManager;
10+
import android.os.Build;
1011
import io.flutter.plugin.common.MethodCall;
1112
import io.flutter.plugin.common.MethodChannel;
1213
import io.flutter.plugin.common.MethodChannel.MethodCallHandler;
@@ -42,7 +43,7 @@ public void onMethodCall(MethodCall call, Result result) {
4243
map.put("appName", info.applicationInfo.loadLabel(pm).toString());
4344
map.put("packageName", context.getPackageName());
4445
map.put("version", info.versionName);
45-
map.put("buildNumber", String.valueOf(info.versionCode));
46+
map.put("buildNumber", String.valueOf(getLongVersionCode(info)));
4647

4748
result.success(map);
4849
} else {
@@ -52,4 +53,12 @@ public void onMethodCall(MethodCall call, Result result) {
5253
result.error("Name not found", ex.getMessage(), null);
5354
}
5455
}
56+
57+
private static long getLongVersionCode(PackageInfo info) {
58+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
59+
return info.getLongVersionCode();
60+
}
61+
//noinspection deprecation
62+
return info.versionCode;
63+
}
5564
}

packages/package_info/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ description: Flutter plugin for querying information about the application
33
package, such as CFBundleVersion on iOS or versionCode on Android.
44
author: Flutter Team <[email protected]>
55
homepage: https://github.com/flutter/plugins/tree/master/packages/package_info
6-
version: 0.4.0+1
6+
version: 0.4.0+2
77

88
flutter:
99
plugin:

0 commit comments

Comments
 (0)