<small id='ifyav'></small><noframes id='ifyav'>

    <legend id='ifyav'><style id='ifyav'><dir id='ifyav'><q id='ifyav'></q></dir></style></legend>
    <tfoot id='ifyav'></tfoot>

    • <bdo id='ifyav'></bdo><ul id='ifyav'></ul>

      <i id='ifyav'><tr id='ifyav'><dt id='ifyav'><q id='ifyav'><span id='ifyav'><b id='ifyav'><form id='ifyav'><ins id='ifyav'></ins><ul id='ifyav'></ul><sub id='ifyav'></sub></form><legend id='ifyav'></legend><bdo id='ifyav'><pre id='ifyav'><center id='ifyav'></center></pre></bdo></b><th id='ifyav'></th></span></q></dt></tr></i><div id='ifyav'><tfoot id='ifyav'></tfoot><dl id='ifyav'><fieldset id='ifyav'></fieldset></dl></div>
    1. 即使应用程序未运行,也会弹出带有通知的窗口

      时间:2024-04-14
      • <i id='XSAlN'><tr id='XSAlN'><dt id='XSAlN'><q id='XSAlN'><span id='XSAlN'><b id='XSAlN'><form id='XSAlN'><ins id='XSAlN'></ins><ul id='XSAlN'></ul><sub id='XSAlN'></sub></form><legend id='XSAlN'></legend><bdo id='XSAlN'><pre id='XSAlN'><center id='XSAlN'></center></pre></bdo></b><th id='XSAlN'></th></span></q></dt></tr></i><div id='XSAlN'><tfoot id='XSAlN'></tfoot><dl id='XSAlN'><fieldset id='XSAlN'></fieldset></dl></div>

        <small id='XSAlN'></small><noframes id='XSAlN'>

          <tbody id='XSAlN'></tbody>

          <tfoot id='XSAlN'></tfoot>
          <legend id='XSAlN'><style id='XSAlN'><dir id='XSAlN'><q id='XSAlN'></q></dir></style></legend>

                <bdo id='XSAlN'></bdo><ul id='XSAlN'></ul>
                本文介绍了即使应用程序未运行,也会弹出带有通知的窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                这是我的代码,我会按时收到通知,但应用程序在弹出过程中出现 ctrash

                here is my code and I am getting my notification on time but the application is being ctrash during pop up

                 private void showCustomPopupMenu()
                {
                    WindowManager windowManager2 = (WindowManager) App.getAppContext().getSystemService(WINDOW_SERVICE);
                    LayoutInflater layoutInflater=(LayoutInflater)App.getAppContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                    View view=layoutInflater.inflate(R.layout.window_popup_medicine, null);
                
                    int LAYOUT_FLAG;
                    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
                        LAYOUT_FLAG = WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY;
                    } else {
                        LAYOUT_FLAG = WindowManager.LayoutParams.TYPE_PHONE;
                    }
                
                  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);
                
                        params.gravity=Gravity.CENTER|Gravity.CENTER;
                        params.x=0;
                        params.y=0;
                    assert windowManager2 != null;
                    windowManager2.addView(view, params);
                    }
                

                我得到了这样的错误:

                Unable to add window android.view.ViewRootImpl$W@46b5050 -- permission denied for window type 2038
                

                我已添加所有权限:

                 <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
                <uses-permission android:name="android.permission.INTERNET" />
                <uses-permission android:name="android.permission.SYSTEM_OVERLAY_WINDOW" />
                
                <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
                
                <uses-permission
                    android:name="android.permission.INTERNAL_SYSTEM_WINDOW"
                    tools:ignore="ProtectedPermissions" />
                

                请解决这个问题,非常感谢您的回答并提前感谢您

                please resolve this I would really appreciate your answer and thank you in advance

                推荐答案

                您需要有 ACTION_MANAGE_OVERLAY_PERMISSION 权限才能打开/显示 Alert

                You need to have ACTION_MANAGE_OVERLAY_PERMISSION permission to open/display Alert

                  <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
                
                  <uses-permission
                        android:name="android.permission.INTERNAL_SYSTEM_WINDOW"
                        tools:ignore="ProtectedPermissions" />
                

                设置警报类型为TYPE_APPLICATION_OVERLAY".

                set alert type of "TYPE_APPLICATION_OVERLAY".

                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
                                alertDialog.getWindow().setType(WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY);
                            }else{
                                alertDialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
                            }
                

                将您的 TYPE_PHONE 更改为 TYPE_SYSTEM_ALERT

                您还应该参考 这个 回答.如果您仍有疑问,请告诉我.

                You should also refer this answer. If still you have doubt let me know.

                现在当通知到达时,检查一下:

                Now when notification arrived, check this:

                  public void notificationArrived(String myMsg){
                
                      if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) {
                                final boolean overlayEnabled = Settings.canDrawOverlays(MyFirebaseMessagingService.this);
                                Global.printLog("showTaskDetailPopup==", "overlayEnabled" + overlayEnabled);
                
                                if (!overlayEnabled) return;
                            }
                
                  new Handler(Looper.getMainLooper()).post(new Runnable() {
                            public void run() {
                
                                final Dialog dialog = new Dialog(MyFirebaseMessagingService.this);
                                dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
                                dialog.setContentView(R.layout.window_popup_medicine);
                                dialog.setCancelable(true);
                
                                TextView tv_msg = dialog.findViewById(R.id.tv_msg);
                
                                    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
                                            dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY);
                                    } else {
                                            dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
                                    }
                                    dialog.show();
                                }
                                } catch (JSONException e) {
                                    e.printStackTrace();
                                }
                            }
                        });
                     }
                

                这篇关于即使应用程序未运行,也会弹出带有通知的窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:在弹出的android中打开pdf 下一篇:如何在应用程序之外创建警报对话框?

                相关文章

                1. <tfoot id='vu3RR'></tfoot>
                2. <legend id='vu3RR'><style id='vu3RR'><dir id='vu3RR'><q id='vu3RR'></q></dir></style></legend>
                    <bdo id='vu3RR'></bdo><ul id='vu3RR'></ul>

                  <small id='vu3RR'></small><noframes id='vu3RR'>

                    <i id='vu3RR'><tr id='vu3RR'><dt id='vu3RR'><q id='vu3RR'><span id='vu3RR'><b id='vu3RR'><form id='vu3RR'><ins id='vu3RR'></ins><ul id='vu3RR'></ul><sub id='vu3RR'></sub></form><legend id='vu3RR'></legend><bdo id='vu3RR'><pre id='vu3RR'><center id='vu3RR'></center></pre></bdo></b><th id='vu3RR'></th></span></q></dt></tr></i><div id='vu3RR'><tfoot id='vu3RR'></tfoot><dl id='vu3RR'><fieldset id='vu3RR'></fieldset></dl></div>