androidnosuchmethoderrorandroid-powermanager

java.lang.NoSuchMethodError in PowerManager


I got the below error log and not sure how this could be fixed

Caused by: java.lang.NoSuchMethodError: android.os.PowerManager.isInteractive
    at com.example.myapp.app.ActivityLifecycleCallbackListener.onActivityPaused(ActivityLifecycleCallbackListener.java:131)
    at android.app.Application.dispatchActivityPaused(Application.java:217)
    at android.app.Activity.onPause(Activity.java:1295)
    at android.support.v4.app.FragmentActivity.onPause(FragmentActivity.java:384)

Solution

  • isInteractive id added in API level 20 as stated by developer.android.com.

    You need to check the API level before call the method:

    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT_WATCH) {
        //isInteractive() call
    }