Невозможно добавить окно android .view. ViewRootImpl$W@3660b6 - в типе окна 2038 запрещено разрешение - PullRequest
0 голосов
/ 18 марта 2020

Привет в приведенном ниже коде. Я сталкиваюсь с ошибкой щелчка оконным менеджером.

Для приведенного ниже кода я получаю эту ошибку. При попытке нажать кнопку, я не могу открыть окно

может любой. Диспетчер окон добавляет представление выдает ошибку

Невозможно добавить окно android .view. ViewRootImpl$W@3660b6 - в типе окна 2038

private void createPdf(int position){

        int LAYOUT_FLAG;
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            LAYOUT_FLAG = WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY;
            try {
                WindowManager windowManager = (WindowManager)getActivity().getSystemService(WINDOW_SERVICE);

                //here is all the science of params
                final WindowManager.LayoutParams  params = new WindowManager.LayoutParams(
                        WindowManager.LayoutParams.WRAP_CONTENT,
                        WindowManager.LayoutParams.WRAP_CONTENT,
                        LAYOUT_FLAG,
                        WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
                        PixelFormat.TRANSLUCENT);
                LayoutInflater layoutInflater =
                        (LayoutInflater) getActivity().getBaseContext().getSystemService(LAYOUT_INFLATER_SERVICE);
                final View popupView = layoutInflater.inflate(R.layout.pdf_layout, null);

                LinearLayout pdf=popupView.findViewById(R.id.pdf);
                TextView account_name=popupView.findViewById(R.id.account_name);
                TextView street=popupView.findViewById(R.id.street);
                TextView city=popupView.findViewById(R.id.city);
                TextView district=popupView.findViewById(R.id.district);
                TextView state=popupView.findViewById(R.id.state);
                TextView opp_no=popupView.findViewById(R.id.opp_no);
                TextView date=popupView.findViewById(R.id.date);
                TextView contact_name=popupView.findViewById(R.id.contact);
                String account=listSalesStageOpportunity.get(position).getRelated();
                account_name.setText(account);
                String opp=listSalesStageOpportunity.get(position).getPotentialNo();
                opp_no.setText("Ref No:" + opp);
                String cureent_date = new SimpleDateFormat("dd-MMM-yyyy", Locale.getDefault()).format(new Date());
                date.setText("Date:" +cureent_date);
                String contactname=listSalesStageOpportunity.get(position).getContact();
                contact_name.setText("Kind Attn :" +contactname);

                SynFields synFields = productList.get(position);
                String product_id= String.valueOf(synFields.getValue());
                Log.d("product_id",product_id);



                Handler hand=new Handler();
                windowManager.addView(popupView, params);
                PdfDocument document = new PdfDocument();
                PdfDocument.PageInfo pageInfo = new PdfDocument.PageInfo.Builder(params.x, params.y, 1).create();
                PdfDocument.Page page = document.startPage(pageInfo);
                Canvas canvas = page.getCanvas();

                Paint paint = new Paint();
                canvas.drawPaint(paint);

                // bitmap = Bitmap.createScaledBitmap(bitmap, convertWidth, convertHighet, true);

                //  paint.setColor(Color.GRAY);
                //canvas.drawBitmap(bitmap, 0, 0 , null);
                document.finishPage(page);


                // write the document content
                String targetPdf = "/sdcard/pdffromlayout2.pdf";
                File filePath;
                filePath = new File(targetPdf);
                try {
                    document.writeTo(new FileOutputStream(filePath));
                } catch (IOException e) {
                    e.printStackTrace();
                    Toast.makeText(getActivity(), "Something wrong: " + e.toString(), Toast.LENGTH_LONG).show();
                }
                // close the document
                document.close();
                Toast.makeText(getActivity(), "PDF is created!!!", Toast.LENGTH_SHORT).show();
                openGeneratedPDF();


            } catch (Exception e) {
                Handler hand = new Handler();
                e.printStackTrace();
            }
        } else {
            LAYOUT_FLAG = WindowManager.LayoutParams.TYPE_PHONE;
            WindowManager windowManager = (WindowManager) getActivity().getSystemService(WINDOW_SERVICE);

            final WindowManager.LayoutParams params = new WindowManager.LayoutParams(
                    WindowManager.LayoutParams.WRAP_CONTENT,
                    WindowManager.LayoutParams.WRAP_CONTENT,
                    LAYOUT_FLAG,
                    WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
                    PixelFormat.TRANSLUCENT);
            LayoutInflater layoutInflater =
                    (LayoutInflater) getActivity().getBaseContext().getSystemService(LAYOUT_INFLATER_SERVICE);
            final View popupView = layoutInflater.inflate(R.layout.pdf_layout, null);

            params.gravity = Gravity.TOP | Gravity.CENTER;
            params.x = ((getContext().getResources().getDisplayMetrics().widthPixels) / 2);
            params.y = ((getContext().getResources().getDisplayMetrics().heightPixels) / 2);
            windowManager.addView(popupView, params);

            PdfDocument document = new PdfDocument();
            PdfDocument.PageInfo pageInfo = new PdfDocument.PageInfo.Builder(params.x, params.y, 1).create();
            PdfDocument.Page page = document.startPage(pageInfo);
            // Canvas canvas = page.getCanvas();

            //  Paint paint = new Paint();
            // canvas.drawPaint(paint);

            // bitmap = Bitmap.createScaledBitmap(bitmap, convertWidth, convertHighet, true);

            //  paint.setColor(Color.GRAY);
            //canvas.drawBitmap(bitmap, 0, 0 , null);
            document.finishPage(page);


            // write the document content
            String targetPdf = "/sdcard/pdffromlayout2.pdf";
            File filePath;
            filePath = new File(targetPdf);
            try {
                document.writeTo(new FileOutputStream(filePath));
            } catch (IOException e) {
                e.printStackTrace();
                Toast.makeText(getActivity(), "Something wrong: " + e.toString(), Toast.LENGTH_LONG).show();
            }
            // close the document
            document.close();
            Toast.makeText(getActivity(), "PDF is created!!!", Toast.LENGTH_SHORT).show();
            openGeneratedPDF();
        }

        }
отказано в разрешении
...