Android - Unsupported Service: audio

后端 未结 5 1237
挽巷
挽巷 2021-01-04 05:42

I am trying to understand and resolve and error I am seeing in the Eclipse workspace log while working on an Android app that implements an IME. I am new to Android and Ecli

5条回答
  •  误落风尘
    2021-01-04 06:34

    I found solution.

    Use KeyboardViewFix as replace KeyboardView:

    public class KeyboardViewFix extends KeyboardView {
        public static boolean inEditMode = true;
    
        @TargetApi(21) // Build.VERSION_CODES.L
        public KeyboardViewFix(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
            super(inEditMode ? new ContextWrapperInner(context) : context, attrs, defStyleAttr, defStyleRes);
        }
    
        public KeyboardViewFix(Context context, AttributeSet attrs, int defStyleAttr) {
            super(inEditMode ? new ContextWrapperInner(context) : context, attrs, defStyleAttr);
        }
    
        public KeyboardViewFix(Context context, AttributeSet attrs) {
            super(inEditMode ? new ContextWrapperInner(context) : context, attrs);
        }
    
        public static class ContextWrapperInner extends ContextWrapper {
            Context base;
            public ContextWrapperInner(Context base) {
                super(base);
                this.base = base;
            }
            public Object getSystemService(String name) {
                return Context.AUDIO_SERVICE.equals(name) ? null : base.getSystemService(name);
            }       
        }
    }
    

    One note: On start your app, before any other code you need set KeyboardViewFix.inEditMode = false; or you can get some errors.

提交回复
热议问题