get versionName of osmdroid library programmatically
See original GitHub issueIssue Type
[x] Question
Description and/or steps/code to reproduce the problem
Is there an easy way to retrieve the current versionName (e.g. “6.1.2”) of the osmdroid library? I tried the following, but in the last step, an exception is thrown.
String versionName = "?"; // default, unknown
MapView mapView = findViewById(R.id.mapview);
Class mapClass = mapView.getClass();
Package mapPackage = mapClass.getPackage();
String packageName = mapPackage.getName(); // = "org.osmdroid.views"
PackageManager pManager = this.getPackageManager();
try
{ // the next line throws NameNotFoundException
PackageInfo pInfo = pManager.getPackageInfo(packageName, 0);
versionName = pInfo.versionName;
}
catch (PackageManager.NameNotFoundException e)
{
e.printStackTrace();
}
Perhaps, I’m thinking too complicated, but an easy way - something like
String versionName = mapView.getVersionName();
doesn’t seem to exist. Any ideas appreciated.
Environment
Huawei P10 Lite, Android 8.0.0, SDK_INT 26 (“Oreo”)
Version of osmdroid the issue relates to:
6.1.2
Issue Analytics
- State:
- Created 4 years ago
- Comments:8 (1 by maintainers)
Top Results From Across the Web
How can you get the build/version number of your Android ...
To get the version code use int versionCode = BuildConfig.VERSION_CODE; and to get the version name String versionName = BuildConfig.VERSION_NAME;.
Read more >android get version number programmatically Code Example
get app version android ; 1. String versionName = context.getPackageManager() ; 2 .getPackageInfo(context.getPackageName(), 0).versionName;.
Read more >tutorial - osmdroid
osmdroid's MapView is basically a replacement for Google's MapView class. First of all, create your Android project, and follow HowToMaven if you're using...
Read more >Android Studio Editor Rendering Problems - Android
Marker (OSMdroid Android 5.2 API) · A Programmer's Day: Android Package Name From APK Java Code ... Can we use library functions to...
Read more >How to get the versionCode and versionName of your app
In you AndroidManifest.xml file, you can specify the values of android:versionCode and android:versionName .
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
There currently isn’t, but i can add it…
@spyhunter99 Thanks for your effort!
But what is the correct entry in “build.gradle” now? Until yesterday it was:
I tried ‘6.1.7’ and ‘6.1.7-SNAPSHOT’, but none of them was working. Error message in the Build Tab: