For checking device version which is greater than or equal to Marshmallow ,use this code.
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M){
}
for ckecking others just change the VERSION_CODES like,
K for kitkat,
L for loolipop
N for Nougat and so on...