It says method call requires API level 23. My code below,
But it is not possible because, following is from android official android.widget.Editor.java source file in API 19.
Also associated constants TYPE_APPLICATION_SUB_PANEL was added from api level 1. Also I used this successfully on Xamarin under api 14.
What is wrong here?
It simply show that setWindowLayoutType method does not available for API level 14.
you have to add API level condition.
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
{
mContainer.setWindowLayoutType(WindowManager.LayoutParams.TYPE_APPLICATION_SUB_PANEL);
}
Did you install api 23 sdk? You must download from android sdk manager.
Related
I'm working in API 22, but I want to compile my project in Android M 6.0, I have this code:
Declared at the top:
private static final String[] REQUIRED_PERMISSIONS = new String[]{"READ_EXTERNAL_STORAGE"};
private static final int REQUEST_PERMISSIONS = (Integer) null;
And on my onCreate():
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
LinkedList<String> missingPermissions = new LinkedList<>();
for(String p : REQUIRED_PERMISSIONS){
if(checkCallingOrSelfPermission(p) != PackageManager.PERMISSION_GRANTED){
missingPermissions.add(p);
}
}
if(!missingPermissions.isEmpty()){
String[] mpArray = new String[missingPermissions.size()];
missingPermissions.toArray(mpArray);
requestPermissions(mpArray, REQUEST_PERMISSIONS);
}
}
I was inspired here for checking my problem
and in Eclipse is giving me an error on Build.VERSION_CODES.M(M not found), and then, the callback method requestPermissions(mpArray, REQUEST_PERMISSIONS) isn't found too, any suggestion?
If I'm working on API 22, and I'm compiling with Android 6.0 M. How I can solve the issue for the dangerous permissions like READ_EXTERNAL_STORAGE correctly on API 22?
As per the documentation, Build.VERSION_CODES.M and requestPermissions() were added in API level 23.
Since you are compiling with API level 22, those simply do not exist.
To access APIs introduced in API level 23, you need to compile with API 23. You cannot access these APIs if you continue to compile with API 22.
Note that simply compiling with API 23 will not affect the way your application behaves on any devices, it simply opens up the newer APIs for your use on devices running at least API 23.
if I'm working on API 22, and I'm compiling with Android 6.0 M, how i can do for solve the issue for the dangerous permissions like READ_EXTERNAL_STORAGE correctly on API 22?
Devices running API 22 will continue to use the old install-time model for permissions. Nothing has changed for devices running API 22 and below. Only devices running API 23 use the new runtime permissions model.
i want to add addAllowedApplication(String packageName) in my android app for api level 14. but it does not work on api 14 .
please give solution for that
I have this line in my code:
linearLayout.setBackground(drawable);
setBackground() shows the following error:
Call requires API level 16 (current min is 14)
What does this mean?
Can I raise my API level?
What does a higher/lower API level mean?
Does it limit the amount of devices my app can be used on if the API level is higher?
What does this mean?
It means that the setBackground(Drawable) method was added in API Level 16, and older devices do not have it. However, your app's minSdkVersion is 14. So, unless you take steps to avoid this line on API Level 14 and 15 devices, your app will crash on those devices.
Can I raise my API level?
You could set your minSdkVersion to 16.
Does it limit the amount of devices my app can be used on if the API level is higher?
Yes. If you say that your minSdkVersion is 16, then devices running a version of Android older than that cannot run your app.
At the time of this writing, about 90% of Android devices accessing the Play Store are on API Level 16 or higher (i.e., are running Android 4.1 or higher).
You can read more about the concept of API levels in the documentation. Note that this documentation is a bit old, in that it focuses on the minSdkVersion being defined in the manifest. In Android Studio projects, minSdkVersion is usually defined in your app module's build.gradle file.
Can I raise my API level?
You can set API to 16 it will limit device below 16 but it will perfectly work on devices API 16 and higher
Or else You can use API check and set
final int sdk = android.os.Build.VERSION.SDK_INT;
if(sdk < android.os.Build.VERSION_CODES.JELLY_BEAN) {
layout.setBackgroundDrawable( getResources().getDrawable(R.drawable.ready) );
} else {
layout.setBackground( getResources().getDrawable(R.drawable.ready));
}
Use a validation method that will be supported only in API LEVEL >= 16 (note the use of ContextCompat class:
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) {
linearLayout.setBackground(ContextCompat.getDrawable(this, drawableid));
}
Use:
layout.setBackgroudResource(R.drawable.ready);
I'm curious about what is the sense in setting both target and minimal supported API version when starting a new Android Studio project. I mean, if I set that minimal API is, say, 8, then I won't be able to use features from 22 (which could be my target), because it would break compatibility with API 8.
if I set that minimal API is, say, 8, then I won't be able to use
features from 22
You can use API level >= 8 features in application, but you have to check OS version of the device first, see following code, that's how you can maintain compatibility
if (android.os.Build.VERSION.SDK_INT == android.os.Build.VERSION_CODES.HONEYCOMB){
//use features of API 3.0
} else if (android.os.Build.VERSION.SDK_INT == android.os.Build.VERSION_CODES.HONEYCOMB_MR1){
//use features of API 3.1
} else if (android.os.Build.VERSION.SDK_INT == android.os.Build.VERSION_CODES.HONEYCOMB_MR2){
//use features of API 3.2
}else{
// and so on....
}
Other then code, use can use resource folders on the basis of API level, like:
values-v11
values-v12
values-14
....
and
drawable-v11
drawable-v12
drawable-14
....
This is not correct. By setting target API to 8 you can't use any features added after, but specifying minimum API is just a guarantee that you application will work on such devices. You don't guarantee that it provide all features on such devices, nor minimum API level restricts what features it could use when running on later versions of OS.
Look at PE history - all win32 executable files are compatible with MSDOS, but all they say after executing is just "This is not a MSDOS program.". Similar to this, it is your decision what features you provide on which OS you support.
I am working with a large project, which has a minimum API level:16. however, I came across API usages that are above API level 16.
Is there any tool in Android studio or elsewhere, other than testing with a device, to check if the code doesn't violate the minimum required API level or better point it out like an error etc.?
Thank you.
The IDE will use the minimum android SDK, thus you will not get compile errors. If you there are classes in SDK 14 which are moved in sdk 16, yet you are using the imports from SDK 14, it will give a standard compile error.
So no, not that I am aware of.
You can use something like this:
public static boolean supports(final int version) {
return Build.VERSION.SDK_INT >= version;
}
Like this,
if (supports(Build.VERSION_CODES.HONEYCOMB)) {
// do something HONEYCOMB+ compatible here
}
More codes here,
http://developer.android.com/reference/android/os/Build.VERSION_CODES.html