question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

get versionName of osmdroid library programmatically

See original GitHub issue

Issue 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:closed
  • Created 4 years ago
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
spyhunter99commented, Mar 8, 2020

There currently isn’t, but i can add it…

0reactions
mikebravoyescommented, Mar 9, 2020

@spyhunter99 Thanks for your effort!

But what is the correct entry in “build.gradle” now? Until yesterday it was:

dependencies {
    implementation group: 'org.osmdroid', name: 'osmdroid-android', version: '6.1.6'
}

I tried ‘6.1.7’ and ‘6.1.7-SNAPSHOT’, but none of them was working. Error message in the Build Tab:

ERROR: Failed to resolve: org.osmdroid:osmdroid-android:6.1.7 Show in Project Structure dialog Affected Modules: app

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found