Home > Enterprise >  How do I check the android version for my app to set an alternative directory?
How do I check the android version for my app to set an alternative directory?

Time:01-13

So I have this code where I want to get some files in a certain app directory, but on android 11, this app directory is not the same as the old versions, how do i modify my code to check this and get all versions right directories:

```val bool = sharedPref.getBoolean("dwaBool",false)

    val oldPath = if (bool){
        Constants.STATUS_LOCATION_DW
    }else{
        Constants.STATUS_LOCATION
    }

the right directory for android 11 is in a "const val" called "STATUS_LOCATION_AVERS"

CodePudding user response:

you can use this snippet

val oldPath = if (Build.VERSION.SDK_INT >= 30){
       // android 11 or higher
        Constants.STATUS_LOCATION_DW
    }else{
        Constants.STATUS_LOCATION
    }

CodePudding user response:

BuildConfig.VERSION_CODE gives the current version integer number of the app.

  •  Tags:  
  • Related