Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/213.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Android创建视图崩溃_Java_Android_Visual Studio - Fatal编程技术网

Java Android创建视图崩溃

Java Android创建视图崩溃,java,android,visual-studio,Java,Android,Visual Studio,我正在尝试使用以下代码添加布局: LayoutInflater layoutInflater = (LayoutInflater) activity.getSystemService(LAYOUT_INFLATER_SERVICE); mYouTubePlayerLayout = (ConstraintLayoutKeyDispatchWrapper) layoutInflater.inflate(R.layout.background_player_layout, null,

我正在尝试使用以下代码添加布局:

    LayoutInflater layoutInflater = (LayoutInflater) activity.getSystemService(LAYOUT_INFLATER_SERVICE);
    mYouTubePlayerLayout = (ConstraintLayoutKeyDispatchWrapper) layoutInflater.inflate(R.layout.background_player_layout, null, false);
    mYouTubePlayerLayout.setOnDispatchKeyEventListener(this);
    mWindowManager = (WindowManager) activity.getSystemService(WINDOW_SERVICE);
    createWindowParams(true);
    mWindowManager.addView(mYouTubePlayerLayout, mWindowParams);
    if (Build.VERSION.SDK_INT >= 23 && !Settings.canDrawOverlays(this)) {
            isAppPlayStorePermission = true;

            AlertDialog.Builder dialog = new AlertDialog.Builder(activity);

            dialog.setCancelable(false);
            dialog.setIcon(R.drawable.ic_launcher);
            dialog.setTitle(R.string.dialog_need_playstore_permissions_title);
            dialog.setMessage(R.string.dialog_need_playstore_permissions_description);

            dialog.setPositiveButton(R.string.button_exit, new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                    AndroidUtils.exitApp(activity);
                }
            });

            dialog.setNegativeButton(R.string.button_settings, new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();

                    Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION, Uri.parse("package:" + getPackageName()));
                    startActivityForResult(intent, 0);
                }
            });

            dialog.show();

        }
我知道我需要从用户那里获得23及以上版本的权限,因此我请求用户使用以下代码获得权限:

    LayoutInflater layoutInflater = (LayoutInflater) activity.getSystemService(LAYOUT_INFLATER_SERVICE);
    mYouTubePlayerLayout = (ConstraintLayoutKeyDispatchWrapper) layoutInflater.inflate(R.layout.background_player_layout, null, false);
    mYouTubePlayerLayout.setOnDispatchKeyEventListener(this);
    mWindowManager = (WindowManager) activity.getSystemService(WINDOW_SERVICE);
    createWindowParams(true);
    mWindowManager.addView(mYouTubePlayerLayout, mWindowParams);
    if (Build.VERSION.SDK_INT >= 23 && !Settings.canDrawOverlays(this)) {
            isAppPlayStorePermission = true;

            AlertDialog.Builder dialog = new AlertDialog.Builder(activity);

            dialog.setCancelable(false);
            dialog.setIcon(R.drawable.ic_launcher);
            dialog.setTitle(R.string.dialog_need_playstore_permissions_title);
            dialog.setMessage(R.string.dialog_need_playstore_permissions_description);

            dialog.setPositiveButton(R.string.button_exit, new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                    AndroidUtils.exitApp(activity);
                }
            });

            dialog.setNegativeButton(R.string.button_settings, new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();

                    Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION, Uri.parse("package:" + getPackageName()));
                    startActivityForResult(intent, 0);
                }
            });

            dialog.show();

        }
但是现在我从
Fabric
收到了一个崩溃:

Fatal Exception: java.lang.RuntimeException
Unable to create service ***: android.view.WindowManager$BadTokenException: Unable to add window android.view.ViewRootImpl$W@c7450fc -- permission denied for this window type
该崩溃仅适用于Android操作系统为7及以下的用户。 你知道有什么问题吗