Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
2
Question by Hoffa25 · Nov 09, 2015 at 11:51 AM · androidversion

How to detect the Android version of the user device?

My game doesnt run well with android 4. I would like some kind of waring popup if the game detects that the device runs on android 4 or older. How do I do that?

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image fafase · Nov 09, 2015 at 12:10 PM 0
Share

You can set the version on the google store so that user with an old version won't be able to download it.

This may sound like preventing people from downloading but it also protect your app from bad reviews.

Think about it.

2 Replies

· Add your reply
  • Sort: 
avatar image
4

Answer by RobWatling · Nov 09, 2015 at 01:08 PM

The following SystemInfo function will return what you are looking for http://docs.unity3d.com/ScriptReference/SystemInfo-operatingSystem.html

 using UnityEngine;
 using System.Collections;
 
 public class ExampleClass : MonoBehaviour {
     void Example() {
         print(SystemInfo.operatingSystem);
     }
 }
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
2

Answer by HenryStrattonFW · Nov 09, 2015 at 12:36 PM

SystemInfo is a class that will give you access to this information (via the operatingSystem variable). Or someone on a thread over at GameDev Stack Exchange has put up a small bit of C# that should return you the exact API level which you can then use to determine what android version is being run.

http://gamedev.stackexchange.com/questions/95342/is-there-a-way-to-check-android-version-running-the-game-using-unity3d

Hope this helps.

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image fschneider · Mar 16, 2016 at 06:01 PM 2
Share

the above link proposes the following code:

 public int GetSD$$anonymous$$Level() {
     var clazz = AndroidJNI.FindClass("android.os.Build$VERSION");
     var fieldID = AndroidJNI.GetStaticFieldID(clazz, "SD$$anonymous$$_INT", "I");
     var sdkLevel = AndroidJNI.GetStaticIntField(clazz, fieldID);
     return sdkLevel;
 }

  1. I needed to change the FindClass parameter to "android/os/Build$VERSION", as the above code was issuing the error message "JNI DETECTED ERROR IN APPLICATION: illegal class name 'android.os.Build$VERSION'"

  2. The corrected line seemed to do the trick, but now I am running the code again some weeks later and it crashes again. This time, I get the following messages :

JNI ERROR (app bug): accessed stale local reference [...] JNI DETECTED ERROR IN APPLICATION: jclass is an invalid local reference: [...] in call to GetStaticFieldID

Does anybody have an idea how to fix this?

avatar image fschneider fschneider · Mar 17, 2016 at 12:55 PM 0
Share

I found out that the above calls should not be made in a method that is called from a Thread. In my case it was called in a callback returning from an async call on WebClient.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

38 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Android exported project for Unity 5.2 Crashes. FMOD implementation error. 2 Answers

Daydream compatible Unity versions? 0 Answers

Gradle Build Failed Unity version 2020..3.23 1 Answer

Android platform version 0 Answers

Android platform version 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges