2

This code that sets up a floating window for a video view was working great. Until Android 6.0 - it now throws NoClassDefFoundError. Also when migrating the project to Android Studio, gradle refuses to compile the project because of that line. Reading up a bit, I realize it would be unwise to try and copy/paste the android internals source code. How can a get a new window for my Playback Controller?

 private void initFloatingWindow() {
            mWindowManager = (WindowManager) mActivity.getSystemService(Context.WINDOW_SERVICE);
            **// original**
            mWindow = com.android.internal.policy.PolicyManager.makeNewWindow(mActivity.getApplicationContext());
            // attempt instead of PolicyManager, but it really needs a new window
            // mWindow = mActivity.getWindow();
            mWindow.setWindowManager(mWindowManager, null, null);
            mWindow.requestFeature(Window.FEATURE_NO_TITLE);

            mDecor = mWindow.getDecorView();
            mDecor.setOnTouchListener(mTouchListener);
            mWindow.setContentView(mViewGroup);
            mWindow.setBackgroundDrawableResource(android.R.color.transparent);

            // While the media controller is up, the volume control keys should
            // affect the media stream type
            mWindow.setVolumeControlStream(AudioManager.STREAM_MUSIC);

            mViewGroup.setFocusable(true);
            mViewGroup.setFocusableInTouchMode(true);
            mViewGroup.setDescendantFocusability(ViewGroup.FOCUS_AFTER_DESCENDANTS);
            mViewGroup.requestFocus();
            mViewGroup.setOnKeyListener(new View.OnKeyListener() {

                @Override
                public boolean onKey(View v, int keyCode, KeyEvent event) {
                    LLog.d(LOG_TAG, "onKey keyCode=" + keyCode);
                    if (keyCode == KeyEvent.KEYCODE_BACK
                            || keyCode == KeyEvent.KEYCODE_MENU) {
                        hideControlLayout();
                        InputMethodManager mInputManager = (InputMethodManager) mActivity
                                .getSystemService(Context.INPUT_METHOD_SERVICE);
                        mInputManager.hideSoftInputFromWindow(
                                mDecor.getWindowToken(), 0);
                        return true;
                    }
                    return false;
                }
            });
        }
0

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.