Nick
Nick

Reputation: 675

Kivy + PyJnius check android version

Is there any way to get the android version (4 or 5 or 6 or 7) directly from python or pyjnius?

If so, could anyone make an example?

I tried kivy.platform but it only tells me if it is android or not and using platform.release from python gives me the linux version

Upvotes: 0

Views: 999

Answers (3)

Oddthinking
Oddthinking

Reputation: 25332

I had the same question. I wanted to know the version to decide whether to reference a particular class which didn't exist in versions earlier than SDK 23.

Then I realised there was a better way.

try:
    AudioFocusRequest = autoclass('android.media.AudioFocusRequest')
except jnius.JavaException:
    # Not available on earlier versions of Android.
    AudioFocusRequest = None

Now, I don't need to know what the version actually is, and there won't be any bugs where I get the threshold values wrong. I just check whether the AutoFocusRequest exists before I use it.

Upvotes: 0

olokelo
olokelo

Reputation: 145

You can use my module from here (On page click download > Only file) and put downloaded file into folder with your kivy project. Add to your .py file:

import PyAndroid

Now you can use:

print(PyAndroid.android_version())

To print android version or

print(PyAndroid.android_name())

To print android name

For all functions you can read documentation.

I hope I helped :D

Upvotes: 0

inclement
inclement

Reputation: 29488

You can use pyjnius to retrieve the version via the Java API, as described e.g. here.

Upvotes: 1

Related Questions