Getting screen width on API Level 30 (Android 11): getDefaultDisplay() and getMetrics() are now deprecated. What should we use instead?

For calculating screen width minus any system bars, this should work: public static int getScreenWidth(@NonNull Activity activity) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { WindowMetrics windowMetrics = activity.getWindowManager().getCurrentWindowMetrics(); Insets insets = windowMetrics.getWindowInsets() .getInsetsIgnoringVisibility(WindowInsets.Type.systemBars()); return windowMetrics.getBounds().width() – insets.left – insets.right; } else { DisplayMetrics displayMetrics = new DisplayMetrics(); activity.getWindowManager().getDefaultDisplay().getMetrics(displayMetrics); return displayMetrics.widthPixels; } } Note that this isn’t … Read more

After updating Android Studio to version 1.3.0 I am getting “NDK integration is deprecated in the current plugin” Error

Here is how to solve this issue : add gradle.properties file to root folder of your project add ‘android.useDeprecatedNdk=true’ to gradle.properties file Here is my gradle.properties : # Project-wide Gradle settings. # IDE (e.g. Android Studio) users: # Gradle settings configured through the IDE *will override* # any settings specified in this file. # For … Read more

setBackgroundDrawable() deprecated

It’s an interesting topic. The way you are doing it is correct, apparently. It is actually just a naming decision change. As this answer points out, setBackground() just calls setBackgroundDrawable(): public void setBackground(Drawable background) { //noinspection deprecation setBackgroundDrawable(background); } @Deprecated public void setBackgroundDrawable(Drawable background) { … } You can see this thread for more information … Read more

Why is accelerometer:didAccelerate: deprecated in IOS5?

I did not yet use iOS 5, but already in 4.x UIAccelerometer and UIAccelerometerDelegate were replaced by the CoreMotion framework. It is more sophisticated, takes gyroscope signals into account and performs a sensor fusion i.e. does calibrating stuff like bias calculation for you. Basically the CMDeviceMotionHandler block callback is now the equivalent. It is called … Read more

ActivityManager.getRunningTasks is deprecated android

This should work for the pre Lollipop devices as well as for Lollipop devices public static boolean isBackgroundRunning(Context context) { ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); List<ActivityManager.RunningAppProcessInfo> runningProcesses = am.getRunningAppProcesses(); for (ActivityManager.RunningAppProcessInfo processInfo : runningProcesses) { if (processInfo.importance == ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND) { for (String activeProcess : processInfo.pkgList) { if (activeProcess.equals(context.getPackageName())) { //If your app is the process … Read more

Android LocationServices.FusedLocationApi deprecated

Original Answer This is happening because FusedLocationProviderApi deprecated in a recent version of google play services. You can check it here. The official guide now suggests using FusedLocationProviderClient. You can find the detailed guide here. for e.g inside onCreate() or onViewCreated() create a FusedLocationProviderClient instance Kotlin val fusedLocationClient = LocationServices.getFusedLocationProviderClient(requireContext()) and for requesting the last … Read more

BaseException.message deprecated in Python 2.6

Solution – almost no coding needed Just inherit your exception class from Exception and pass the message as the first parameter to the constructor Example: class MyException(Exception): “””My documentation””” try: raise MyException(‘my detailed description’) except MyException as my: print my # outputs ‘my detailed description’ You can use str(my) or (less elegant) my.args[0] to access … Read more

Rails I18n validation deprecation warning

Important: Make sure your app is not using I18n 0.6.8, it has a bug that prevents the configuration to be set correctly. Short answer In order to silence the warning edit the application.rb file and include the following line inside the Rails::Application body config.i18n.enforce_available_locales = true The possible values are: false: if you want to … Read more