0

现在,我正在使用以下权限在另一个应用程序上显示对话框:

<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>

对话框:

 dialogBuilder = new AlertDialog.Builder(activity);
 LayoutInflater inflater2 = (LayoutInflater) AppController.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
 View dialogView = inflater2.inflate(R.layout.dialog_view, null);
 dialogBuilder.setView(dialogView);
 dialog = dialogBuilder.create();
 dialog.setCancelable(true);
 final WindowManager.LayoutParams layoutParams = new WindowManager.LayoutParams();
 layoutParams.width = WindowManager.LayoutParams.MATCH_PARENT;
 layoutParams.height = WindowManager.LayoutParams.WRAP_CONTENT;
 final Window dialogWindow = dialog.getWindow();
 if (dialogWindow != null) {
            dialogWindow.setAttributes(layoutParams);
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
                dialogWindow.setType(WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY);
            } else {
                dialogWindow.setType(WindowManager.LayoutParams.TYPE_PHONE);
            }
  }
 dialog.show();

Snaptube应用程序,在 YouTube 应用程序上显示一个对话框,无需请求任何许可:

我怎样才能做到这一点?

4

0 回答 0