Android 我需要一个屏幕提示,当应用程序是离样本屏幕图像像这样

Android 我需要一个屏幕提示,当应用程序是离样本屏幕图像像这样,android,notifications,reminders,Android,Notifications,Reminders,上面的代码用于通知,但不知道屏幕上的提醒 WindowManager windowManager2 = (WindowManager) App.getAppContext().getSystemService(WINDOW_SERVICE); LayoutInflater layoutInflater=(LayoutInflater) App.getAppContext().getSystemService(Context.LAYOUT_INFL

上面的代码用于通知,但不知道屏幕上的提醒

 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);
                        WindowManager.LayoutParams
                         params= null;
                        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
                            params = new WindowManager.LayoutParams(
                                   WindowManager.LayoutParams.WRAP_CONTENT,
                                   WindowManager.LayoutParams.WRAP_CONTENT,
                                   WindowManager.LayoutParams.TYPE_APPLICATION_PANEL,
                                   WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
                                   PixelFormat.TRANSLUCENT);
                        }

                        params.gravity=Gravity.CENTER|Gravity.CENTER;
                        params.x=0;
                        params.y=0;
                        windowManager2.addView(view, params);

我需要一个这样的提醒,因为我已经分享了一张图片,你需要创建一个覆盖来实现这一点。使用前台服务并通过windowManager添加视图。请检查窗口管理器代码。它给出错误。。。。。android.view.WindowManager$BadTokenException:无法添加窗口--标记null无效;您的活动正在运行吗?您是否在前台服务中使用它?
 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);
                        WindowManager.LayoutParams
                         params= null;
                        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
                            params = new WindowManager.LayoutParams(
                                   WindowManager.LayoutParams.WRAP_CONTENT,
                                   WindowManager.LayoutParams.WRAP_CONTENT,
                                   WindowManager.LayoutParams.TYPE_APPLICATION_PANEL,
                                   WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
                                   PixelFormat.TRANSLUCENT);
                        }

                        params.gravity=Gravity.CENTER|Gravity.CENTER;
                        params.x=0;
                        params.y=0;
                        windowManager2.addView(view, params);