嗨,我正在使用UsageStatsManager api向用户显示一些使用情况列表。但是我面临一些问题。我在许多设备上都收到此错误,在某些设备上工作正常。我仍然在这个问题上冲浪。你们能帮我解决这个问题吗?

错误:

java.lang.NoClassDefFoundError: android.app.usage.UsageStatsManager
    at com.yourapp.fragment.AppUsageStatisticsFragment.onViewCreated(AppUsageStatisticsFragment.java:64)
    at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1086)
    at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1252)
    at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:738)
    at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1617)
    at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:517)
    at android.os.Handler.handleCallback(Handler.java:800)
    at android.os.Handler.dispatchMessage(Handler.java:100)
    at android.os.Looper.loop(Looper.java:194)
    at android.app.ActivityThread.main(ActivityThread.java:5463)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:525)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:854)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:621)
    at dalvik.system.NativeStart.main(Native Method)


我使用的代码:

    private UsageStatsManager mUsageStatsManager;

   //i am getting error at below line.
    mUsageStatsManager = (UsageStatsManager) getActivity()
            .getSystemService("usagestats"); //Context.USAGE_STATS_SERVICE


表现:

  <uses-permission android:name="android.permission.PACKAGE_USAGE_STATS"
    tools:ignore="ProtectedPermissions"/>


检查我的app

最佳答案

UsageStatsManager在API级别21中添加,这不是您的appcompat API的一部分。因此,在API级别21之前,您将获得ClassNotFoundException

关于java - java.lang.NoClassDefFoundError:android中的android.app.usage.UsageStatsManager,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/36760748/

10-10 16:42