diff --git a/doc/emacs/android.texi b/doc/emacs/android.texi index 15415f12570..c92700980de 100644 --- a/doc/emacs/android.texi +++ b/doc/emacs/android.texi @@ -507,12 +507,25 @@ application via cut-and-paste. @cindex volume/multimedia buttons, Android The volume keys are normally reserved by Emacs and used to provide the ability to quit Emacs without a physical keyboard -(@pxref{On-Screen-Keyboards}.) However, if you want them to adjust +(@pxref{On-Screen Keyboards}.) However, if you want them to adjust the volume instead, you can set the variable @code{android-pass-multimedia-buttons-to-system} to a non-@code{nil} value; note that you will no longer be able to quit Emacs using the volume buttons in that case. +@cindex dialog boxes, android + Emacs is unable to display dialog boxes (@pxref{Dialog Boxes}) while +it does not have the input focus on Android 6.0 or later. If this is +important to you, this ability can be restored by granting Emacs +permission to display over other programs. Normally, this can be done +from the: + +@indentedblock +System -> Apps -> Emacs -> More -> Display over other apps +@end indentedblock + +menu in the system settings, but this procedure may vary by device. + @node Android Fonts @section Font backends and selection under Android @cindex fonts, android diff --git a/java/org/gnu/emacs/EmacsDialog.java b/java/org/gnu/emacs/EmacsDialog.java index aed84de29e5..de5a37bd5c5 100644 --- a/java/org/gnu/emacs/EmacsDialog.java +++ b/java/org/gnu/emacs/EmacsDialog.java @@ -23,8 +23,14 @@ import java.util.ArrayList; import android.app.AlertDialog; -import android.content.DialogInterface; + import android.content.Context; +import android.content.DialogInterface; + +import android.os.Build; + +import android.provider.Settings; + import android.util.Log; import android.widget.Button; @@ -33,6 +39,8 @@ import android.view.View; import android.view.ViewGroup; +import android.view.Window; +import android.view.WindowManager; /* Toolkit dialog implementation. This object is built from JNI and describes a single alert dialog. Then, `inflate' turns it into @@ -225,33 +233,54 @@ private class EmacsButton implements View.OnClickListener, /* Internal helper for display run on the main thread. */ + @SuppressWarnings("deprecation") private boolean display1 () { - EmacsActivity activity; - int size; + Context context; + int size, type; Button buttonView; EmacsButton button; AlertDialog dialog; + Window window; - if (EmacsActivity.focusedActivities.isEmpty ()) + /* First, try to display a dialog using the service context. */ + + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M + || Settings.canDrawOverlays (EmacsService.SERVICE)) + context = EmacsService.SERVICE; + else if (EmacsActivity.focusedActivities.isEmpty ()) { /* If focusedActivities is empty then this dialog may have been displayed immediately after a popup dialog is dismissed. */ - activity = EmacsActivity.lastFocusedActivity; + context = EmacsActivity.lastFocusedActivity; - if (activity == null) + if (context == null) return false; } else - activity = EmacsActivity.focusedActivities.get (0); + context = EmacsActivity.focusedActivities.get (0); - dialog = dismissDialog = toAlertDialog (activity); + Log.d (TAG, "display1: using context " + context); + + dialog = dismissDialog = toAlertDialog (context); try { + if (context == EmacsService.SERVICE) + { + /* Apply the system alert window type to make sure this + dialog can be displayed. */ + + window = dialog.getWindow (); + type = (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O + ? WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY + : WindowManager.LayoutParams.TYPE_PHONE); + window.setType (type); + } + dismissDialog.show (); } catch (Exception exception)