Can android application check phone version

I would like to write an application that uses live wallpapers for insatnce. This feature is supported only in version 7 and higher. Is it possible that the application checks the version of the android phone and depending on what works with other code (for example, uses live wallpaper or a static background.)

Do you have sample code for this? Are special permissions required?

+4
source share
4 answers

Assuming you need Android 1.6 or later:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ECLAIR_MR1) { ... } 
+7
source

Yes there is. Take a look at the Build class in Android. You can use it like this: Build.VERSION.SDK_INT

+1
source
 public static final int ECLAIR_MR1 =7; public static final int FROYO =8; if(Build.VERSION.SDK_INT==FROYO){ Toast.makeText(getApplicationContext(), "Iam a FROYO-Phone", 1).show(); }else if(Build.VERSION.SDK_INT==ECLAIR_MR1){ Toast.makeText(getApplicationContext(), "Iam an ECLAIR-Phone", 1).show(); } 
0
source

SDK_INT is not available in very early versions. Therefore, if your manifest has, for example:

 android:minSdkVersion="1" 

you can use something like this:

 @TargetApi(Build.VERSION_CODES.DONUT) static boolean getPreHoneyComb() { try { Build.VERSION.class.getField("SDK_INT"); } catch (NoSuchFieldException e) { return true; } return Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB; } 
0
source

Source: https://habr.com/ru/post/1342194/


All Articles