Failed to find provider in android TV Preferences fragment

萝らか妹 提交于 2021-02-10 14:51:51

问题


Getting Failed to find provider com.google.android.katniss.search.searchapi.VoiceInteractionProvider for user 0; expected to find a valid ContentProvider for this authority for tv Preference Fragment

E/AndroidRuntime: FATAL EXCEPTION: main Process: com.omniwyse.tvprefdemo, PID: 2025 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.omniwyse.tvprefdemo/com.omniwyse.tvprefdemo.SettingActivity}: android.view.InflateException: Binary XML file line #18: Binary XML file line #18: Error inflating class at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2913) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3048) at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78) at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108) at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1808) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loop(Looper.java:193) at android.app.ActivityThread.main(ActivityThread.java:6669) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858) Caused by: android.view.InflateException: Binary XML file line #18: Binary XML file line #18: Error inflating class Caused by: android.view.InflateException: Binary XML file line #18: Error inflating class Caused by: java.lang.reflect.InvocationTargetException at java.lang.reflect.Constructor.newInstance0(Native Method) at java.lang.reflect.Constructor.newInstance(Constructor.java:343) at android.view.LayoutInflater.createView(LayoutInflater.java:647) at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:790) at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730) at android.view.LayoutInflater.inflate(LayoutInflater.java:492) at android.view.LayoutInflater.inflate(LayoutInflater.java:423) at android.support.v17.preference.BaseLeanbackPreferenceFragment.onCreateRecyclerView(BaseLeanbackPreferenceFragment.java:42) at android.support.v14.preference.PreferenceFragment.onCreateView(PreferenceFragment.java:270) at android.support.v17.preference.LeanbackPreferenceFragment.onCreateView(LeanbackPreferenceFragment.java:54) at android.app.Fragment.performCreateView(Fragment.java:2522) at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1298) at android.app.FragmentManagerImpl.addAddedFragments(FragmentManager.java:2426) at android.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2205) at android.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(FragmentManager.java:2161) at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:2062) at android.app.FragmentManagerImpl.dispatchMoveToState(FragmentManager.java:3051) at android.app.FragmentManagerImpl.dispatchActivityCreated(FragmentManager.java:2998) at android.app.Fragment.performActivityCreated(Fragment.java:2537) at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1318) at android.app.FragmentManagerImpl.addAddedFragments(FragmentManager.java:2426) at android.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2205) at android.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(FragmentManager.java:2161) at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:2062) at android.app.FragmentManagerImpl.dispatchMoveToState(FragmentManager.java:3051) at android.app.FragmentManagerImpl.dispatchActivityCreated(FragmentManager.java:2998) at android.app.FragmentController.dispatchActivityCreated(FragmentController.java:182) at android.app.Activity.performCreate(Activity.java:7143) at android.app.Activity.performCreate(Activity.java:7127) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1271) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2893)

     public class SettingsFragment extends LeanbackSettingsFragment {
@Override
public void onPreferenceStartInitialScreen() {

    startPreferenceFragment(new PrefsFragment());
}

@Override
public boolean onPreferenceStartFragment(PreferenceFragment caller, Preference pref) {
    final Fragment f =
            Fragment.instantiate(getActivity(), pref.getFragment(), pref.getExtras());
    f.setTargetFragment(caller, 0);
    if (f instanceof PreferenceFragment || f instanceof PreferenceDialogFragment) {
      //  startPreferenceFragment(f);
    } else {
       // startImmersiveFragment(f);
    }
    return true;
}

@Override
public boolean onPreferenceStartScreen(PreferenceFragment caller, PreferenceScreen pref) {
    final Fragment f = new PrefsFragment();
    final Bundle args = new Bundle(1);
    args.putString(PreferenceFragment.ARG_PREFERENCE_ROOT, pref.getKey());
    f.setArguments(args);
    startPreferenceFragment(f);
    return true;
}

}

@SuppressLint("ValidFragment") public class PrefsFragment extends LeanbackPreferenceFragment {

@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
    // Load the preferences from an XML resource
    setPreferencesFromResource(R.xml.preferences, rootKey);
}

}


回答1:


I solve this issue with changing theme preference Theme.Leanback

On your manifest file :

<activity android:name=".ui.setting.YourSettingPrefActivity"
        android:exported="true"
        android:theme="@style/Theme.Pref.LeanbackPreferences"/>

And here on styles.xml

<style name="Theme.Pref.LeanbackPreferences" parent="Theme.Leanback">
    <item name="preferenceTheme">@style/PreferenceThemeOverlay.v14.Leanback</item>
    <item name="android:windowIsTranslucent">true</item>
    <item name="android:windowBackground">@android:color/transparent</item>
    <item name="android:backgroundDimEnabled">true</item>
    <item name="android:colorPrimary">@color/fastlane_background</item>
</style>


来源:https://stackoverflow.com/questions/53002769/failed-to-find-provider-in-android-tv-preferences-fragment

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!