Skip to content

Commit

Permalink
fix: show AlertDialog on Android P
Browse files Browse the repository at this point in the history
  • Loading branch information
osfans committed Dec 14, 2018
1 parent d937d72 commit d8e9da2
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_MEDIA_STORAGE"/>
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
<application android:label="@string/ime_name"
android:icon="@drawable/icon"
android:allowBackup="false" >
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/java/com/osfans/trime/Pref.java
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,11 @@ private void requestPermission() {
},
0);
}
if (!Settings.canDrawOverlays(this)) {
Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION, Uri.parse("package:" + getPackageName()));
//startActivityForResult(intent, OVERLAY_PERMISSION_REQ_CODE);
startActivity(intent);
}
}

private void deployOpencc() {
Expand Down
6 changes: 5 additions & 1 deletion app/src/main/java/com/osfans/trime/Trime.java
Original file line number Diff line number Diff line change
Expand Up @@ -1058,7 +1058,11 @@ private void showDialog(AlertDialog dialog) {
Window window = dialog.getWindow();
WindowManager.LayoutParams lp = window.getAttributes();
if (mCandidateContainer != null) lp.token = mCandidateContainer.getWindowToken();
lp.type = WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG;
if (VERSION.SDK_INT >= VERSION_CODES.O) {
lp.type = WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY; //Android P中AlertDialog要顯示在最上層
} else {
lp.type = WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG;
}
window.setAttributes(lp);
window.addFlags(WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
dialog.show();
Expand Down

0 comments on commit d8e9da2

Please sign in to comment.