I am planning to develop a new Android app with a camera use case in it. Reading the API documentation it seems like Android's 'Camera.hardware' class has been deprecated and new 'android.hardware.camera2' has been introduced. So my question is should which API should I start making my app with? Is it a good idea to start developing my app with the deprecated API, so in that case at least I am not restricted to just Android L? And then later once I get good traction, use the new Camera APIs. Will the old APIs work for Android L too ? What would be a good strategy?
The old android.hardware.Camera is deprecated, this means that it still works (i've tryed it) but there are new API that works better.
However Camera probably has everything you need, so I would recommend to use it because you will have compatibility with every android version.
When let's say an Object is deprecated,doesn't mean it's not going to work in your app.
Related
I am just a beginner but i have some questions regarding the support library.
Every time google team add's a new Support version it deprecated the use in new Version, so because of this we have to redo the code again just to support new API level.Can't it be like this , you can have this library but you will be not getting extra features .Instead of just deprecating the entire work ? Because of this there is a lot of extra work to do while making android app.
Why was PreferenceFragment deprecated in Android P and what are the support versions for both libraries PreferenceFragment and PreferenceFragmentCompat also what addition features to do you get?
Android platform is amazing but it's difficult to understand this things . If a developer has made an app what is the guaranty it will work when android releases new version ? With every release something is deprecated either the feature or the whole library.
Every time google team add's a new Support version it deprecated the use in new Version, so because of this we have to redo the code again just to support new API level.
That is not the case. "Deprecated" in Android usually means "we have something that we would prefer that you use". So, while eventually you should try to move off of deprecated APIs, "eventually" could be on the order of a couple of years.
Why was PreferenceFragment deprecated in Android P
The native android.preference.PreferenceFragment was deprecated in Android 9.0, mostly because it inherits from android.app.Fragment, which was deprecated in Android 9.0. The fragment code has had lots of bugs over the years. Google is trying to steer developers towards using a library-supplied fragment implementation, as the libraries can be kept up to date, while older Android devices (unfortunately) do not get updates.
There is nothing stopping you from using android.preference.PreferenceFragment in Android 9.0 if you wish. Ideally, over time, you stop using it, but you do not need to drop everything and change your code tomorrow.
what are the support versions for both libraries PreferenceFragment and PreferenceFragmentCompat
AFAIK android.support.v14.preference.PreferenceFragment should also be marked as deprecated, as it too inherits from android.app.Fragment.
android.support.v7.preference.PreferenceFragmentCompat extends from android.support.v4.app.Fragment, and so AFAIK this is the one that you should be using in the short term.
The whole preference fragment stuff is a bit of a mess at the moment — I am hoping that Google settles this out and provides clearer instructions as part of the migration to androidx over the next few months.
It is known that android.hardware.camera is deprecated and no longer available for new versions. What if I want to use it rather than going for new camera api? Is there a way to import the source code of the same to my local project directory?
What if I want to use it rather than going for new camera api?
Just use it. "Deprecated" means "we have something else that we recommend that you use". In this case, the original Camera API is still there, and it is your only option on API Level 19 and older.
Just bear in mind that manufacturer support for the Camera API will decline steadily over time, just because probably they won't spend as much engineering and Q&A time on it. By 2018, when Android 5.0+ has 90+% of the market, apps should be using the new camera2 API pretty much exclusively.
Is there a way to import the source code of the same to my local project directory?
No, and you don't need it, as it is part of the Android SDK, the same as everything else in the Android SDK.
If your device does not support the old interface, you have no choice but work with camera2, because these two APIs are based on completely different hardware abstraction level (HAL) and cannot be cross-ported to the other. This is why the new non-backward-compatible API was introduced.
I want to build an application where the front camera of the device is used to project the current image to a SurfaceView. All the tutorials I found so far implement this by using a Camera object from the android.hardware package.
This method, however, seems to be deprecated. When trying the 'new' preferred way to implement this feature following the Android documentation, I get the warning it can only be used with API level 21, which is pretty useless.
So I would like to know the currently preferred way to implement camera functionality in an application. Or is there maybe some support library for API levels lower than 21?
Thanks in advance.
Deprecated interface does not mean you should not use it. It means you should know that it will be phasing out in the future.
As a general rule, it is better to use a newer interface if possible, in order to avoid the need to update the software later.
The fact that API level 21 does not yet have a large enough market share means that you are probably better off using the old interface for now, and keep in mind that in a year or two, you may need to update the implementation.
I think you can implement the camera function in both sets of API and check the device`s build version first then decided to call which one implementation.
eg:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP){
openCameraNewAPI();
}else{
openCameraOldAPI();
}
For my new assignment, I wanted to use some library that can provide a "Posterize effect". I found many library like Aviary SDK and jhlabs, Yes, these are easy to use, but these making the code heavier. SO I keep searching for Android's API itself which can do the similar task. And after a lot of RnD, I finally found one my time saver class EffectsFactory which provides the same as I wanted. I applied it in my assignment also. But the bad thing it was added in API level 14, And my app should be compatible with at least API level 8.
So, My question is,
Can I use EffectsFactory class for lower version? If Yes then How?
Or, If No, Then Do we have any API in Android SDK itself which do similar to effectfactory ?
Please avoid referencing any library or NDK's open cv library.
No, there is not an Android API that will posterize an image below API 14. Even above API 14 EffectsFactory may not work, as it says in the Android documentation:
Some effects may not be available on all platforms, so before creating a certain effect, the application should confirm that the effect is supported on this platform by calling isEffectSupported(String).
However, you could easily make a lightweight solution yourself. Posterization is a simple process. For example, the code behind JHlabs' posterize filter is less than 50 lines (and most of them are sugar). In your shoes, if using a 3rd party library was out of the question, I wouldn't hesitate to write my own.
Edit: If you happen to be posterizing images your app takes from the camera, there is also Camera.Parameters.setColorEffect(), but again this is not supported on all devices, as it says in the documentation:
For example, the application should call getSupportedColorEffects() before calling setColorEffect(String).
I am using Camera.Parameters.setPixelFormat(PixelFormat.JPEG) in my android 1.6 application. The documentation says this is deprecated, but the constant value is the same as the new ImageFormat...
Should I not worry about it?
Typically, when something in an API is set as deprecated, it means that it is only there for compatibility purposes with old versions, and will eventually disappear from the API for future versions of Android.
This means that you don't need to rush to fix it, but you should start worrying about it long-term, and eventually create a new portion of code to do the same task using the current supported API functions, so that when a future version of Android API arrives that does not support the deprecated methods/functions anymore, your application is already ready to work and target new and upcoming versions of the Android platform.