Does setAllowFileAccessFromFileURLs affects devices API under 16? - android

The android API doc of this method setAllowFileAccessFromFileURLs says "The default value is true for API level android.os.Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1 and below, and false for API level android.os.Build.VERSION_CODES.JELLY_BEAN and above." But this method is added from android.os.Build.VERSION_CODES.JELLY_BEAN, how can it get the default value true for android.os.Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1 and below? If I call this method setAllowFileAccessFromFileURLs(false), I have to set the min sdk version >= 16, or check Build.VERSION.SDK_INT >= 16, if it has a default value true under 16, how can I change it? It's so weird. same problem about setAllowUniversalAccessFromFileURLs.

Related

Use setRequiredPasswordComplexity(passwordComplexity : Int) in API less than 31

I want to set password policy on screen lock and now I use setPasswordQuality(ComponentName admin, int quality) in DevicePolicyManager but this method is deprecated on API 31 and they add new method(setRequiredPasswordComplexity(passwordComplexity : Int)).
I can use this method in API < 31?
If I can,how should I use it?
https://developer.android.com/reference/android/app/admin/DevicePolicyManager#setRequiredPasswordComplexity(int)
As the documentation already states the method was added in API 31 and since there is no backward compatibility library for this so this functionality can only be used on devices with api 31 or above
I think your problem might solve here. You can check the build version by
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.S){
// Do something for version 31 and above versions
} else{
// do something for phones running an SDK before 31
}

Notification.bigContentView is deprecated in API 24 (Nougat) what is the alternative?

I just upgraded compile sdk version to API 24 from API 23 and it seems the Notification.bigContentView is deprecated.
So the question what is the equivalent method in API 24 to set bigContentView in Android API 24(Nougat)?
The NotificationBuilderCompat has a new method setCustomBigContentView()
in the v4 support library 24.
You can use this method to avoid the deprecated warning and the method is backward compatible.
Quoting the Docs:
As of N, this field may be null. The expanded notification view is determined by the inputs to Notification.Builder; a custom RemoteViews can optionally be supplied with setCustomBigContentView(RemoteViews).
https://developer.android.com/reference/android/app/Notification.html#bigContentView

TimePicker getCurrentMinute, getCurrentHour method is deprecated in API 23

I'm Creating a Alarm based Application with API version 23. But TimePicker getCurrentMinute,getCurrentHour method is Deprecated. Which method will be replace of this method ?
EDIT:
According to google documentation now we have to use getMinute() and getHour() method. But it's only working in api 23. what we have to do for other api?
Just check the Android official docs .. http://developer.android.com/reference/android/widget/TimePicker.html
it tells you everything
public Integer getCurrentMinute ()
Added in API level 1
This method was deprecated in API level 23.
Use getMinute()
Returns
the current minute
and
public Integer getCurrentHour ()
Added in API level 1
This method was deprecated in API level 23.
Use getHour()
Returns
the current hour in the range (0-23)
Android offers runtime checks for API version.
Most of the time in such cases, you'll want to run cases like
if (Build.VERSION.SDK_INT >= 23 )
myTimePickerView.getHour();
else
myTimePickerView.getCurrentHour();
#see http://developer.android.com/reference/android/os/Build.VERSION.html
i faced same issue. if you write your code such as
getCurrentHour()*(striked through) it doesnt make an issue
the code runs gets complied and runs saying
"complete build performed and run since..."
since if you use getHour or getMinute you have to put the version.SDK if else statement (which i tried but didnt work at that time for some reason)
and none the less increases code lines and complexity.

Call requires API level 11 (current min is XX) - For AlertDialog.Builder.Ctor

I try to use constructor of AlertDialog.Builder which gets a context and a theme:
AlertDialog.Builder b = new AlertDialog.Builder(this, 0);
It shows an error on my Eclipse (marking the "Builder" type): "Call requires API level 11 (current min is 7)".
When I use the constructor which gets only the context (without theme), it doesn't show this error.
I want to be able to deploy my app also on old androids (such as version 2.1 etc.). Is there any convenient way for me to use the simple constructor of AlertDialog.Builder when it's an old version, and to use the more complicated constructor when it's API 11 and above?
Just out of curiosity, how does the compiler know what API version is needed for the use of a certain method?
You may use the const Build.VERSION.SDK_INT on an if clause, to check if your API level is above or below the required level (You will probably have to add an annotation to suppress the API level warning / error from that method / class).
Android Lint does that for you. It checks which methods and ctors are allowed on a certain API level.
Example:
if(Build.VERSION.SDK_INT >= 11) {
//API level 11 and above ctor here
} else {
//Lower than API level 11 code here
}

Use high API function when targeting lower API

in my app minSdkVersion="16" and targetSdkVersion="19". And I wish to use MediaMuxer that introduced in API 18. So when I detetect the API on the phone how can I deside if API>=18 use
MediaMuxer and if API<18 use other function. When targeting minSdkVersion="16" the function MediaMuxer is now shown at all in eclipse.
Test the version number like this
if (Build.VERSION.SDK_INT >= 18) {
// do high api
else {
// do low api
}
You have to check the target version of the Android device using below code
if (android.os.Build.VERSION.SDK_INT >= 16) {
System.out.println("Android Version of device is getter or equal to 16 ::Version::"
+ android.os.Build.VERSION.SDK_INT);
}else{
System.out.println("Android Version of device is getter or equal to 16 ::Version::"
+ android.os.Build.VERSION.SDK_INT);
}

Categories

Resources