在entry下的config.json中加入权限:
"reqPermissions": [
{
"name": "ohos.permission.GET_BUNDLE_INFO"
}
],
在java类中调用:
try {
BundleInfo bundleInfo = getBundleManager().getBundleInfo(getBundleName(), 0);
String versionName = "版本名:" + bundleInfo.getVersionName();
String versionCode = "版本号:" + bundleInfo.getVersionCode();
} catch (RemoteException e) {
e.printStackTrace();
}
在entry下的config.json中加入权限:
"reqPermissions": [
{
"name": "ohos.permission.GET_BUNDLE_INFO"
}
],
在java类中调用:
try {
BundleInfo bundleInfo = getBundleManager().getBundleInfo(getBundleName(), 0);
String versionName = "版本名:" + bundleInfo.getVersionName();
String versionCode = "版本号:" + bundleInfo.getVersionCode();
} catch (RemoteException e) {
e.printStackTrace();
}
举报