Android - Unsupported Service: audio Android - Unsupported Service: audio android android

Android - Unsupported Service: audio


Are you using API 14 or higher? If so thats the problem. I guess it is a bug in that version. In API 11 it works.

If you try API 11 you have to do some hack with overriding the getResources() method. Check this for more info. After this it will work.

Actually i think there is no way to jump through this from your LatinKeyboardView on API 14 (or maybe higher) because you can not even use the isInEditMode() because you definitely have to invoke the View's constructor with super. And that constructor will try to get the audio system service which just simply fails because i guess you try to run this in eclipse graphical editor (actually i got this error when i tried to place my custom view into a layout in the grapical layout editor)

I think that the only way to hack this is to implement your own KeyboardView without the getSystemService. Maybe should not call that method if isInEditMode == true.


This is a bug in android.inputmethodservice.KeyboardView

The failing code is

public KeyboardView(Context context, AttributeSet attrs, int defStyle) { ...    mAudioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); ...}

It should be wrapped in isInEditMode() check to skip getting audio manager during layout editing. Strange but I cannot find any issue reported in the Android bug tracker!


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.