Advertisement
Guest User

Android OS version if check

a guest
Aug 22nd, 2023
474
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.44 KB | Gaming | 0 0
  1. //declaration of variables
  2. static AndroidJavaClass versionInfo;
  3.     int SDK_INT;
  4.  
  5. //function
  6.  
  7.    void Awake()
  8.     {
  9.  
  10.  
  11.  
  12.        
  13.         AndroidVersion();
  14.         SDK_INT = AndroidVersion();
  15.  
  16.  
  17.  
  18.  
  19.         if (SDK_INT >= 33)
  20.         {
  21.            
  22.          
  23.  
  24.  
  25.         }
  26.         else
  27.         {
  28.             if (Permission.HasUserAuthorizedPermission(Permission.ExternalStorageRead))
  29.             {
  30.                 Debug.Log("King of Crokinole has access to Gallery");
  31.             }
  32.             else
  33.             {
  34.                 Permission.RequestUserPermission(Permission.ExternalStorageRead);
  35.  
  36.             }
  37.  
  38.             if (Permission.HasUserAuthorizedPermission(Permission.ExternalStorageWrite))
  39.             {
  40.                 Debug.Log("King of Crokinole has access to Camera");
  41.             }
  42.             else
  43.             {
  44.                 Permission.RequestUserPermission(Permission.ExternalStorageWrite);
  45.  
  46.             }
  47.  
  48.         }
  49.      
  50.        
  51.  
  52.        
  53.  
  54.  
  55.     }
  56.  
  57.  
  58. //statics
  59.  
  60.    static int AndroidVersion()
  61.     {
  62.        
  63.         AndroidJavaClass tempJClass = new AndroidJavaClass("android.os.Build$VERSION");
  64.         versionInfo = tempJClass;
  65.  
  66.         int getSDK = PREVIEW_SDK_INT;      
  67.         Debug.Log($"getSDK = {getSDK}");
  68.  
  69.         return getSDK;
  70.     }
  71.     public static int PREVIEW_SDK_INT
  72.     {
  73.         get
  74.         {
  75.             return versionInfo.GetStatic<int>("SDK_INT");
  76.         }
  77.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement