Skip to content

Commit abd5589

Browse files
authored
Merge pull request #372 from DevNull-IR/master
Implement custom back press behavior(Android 13+)
2 parents dd530bc + 2079051 commit abd5589

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

app/src/main/java/mgks/os/swv/MainActivity.java

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
import android.widget.LinearLayout;
6868
import android.widget.Toast;
6969

70+
import androidx.activity.OnBackPressedCallback;
7071
import androidx.activity.result.ActivityResultLauncher;
7172
import androidx.activity.result.contract.ActivityResultContracts;
7273
import androidx.annotation.NonNull;
@@ -131,6 +132,32 @@ protected void onCreate(Bundle savedInstanceState) {
131132
if (SWVContext.ASWP_BLOCK_SCREENSHOTS) {
132133
getWindow().addFlags(WindowManager.LayoutParams.FLAG_SECURE);
133134
}
135+
136+
getOnBackPressedDispatcher().addCallback(this, new OnBackPressedCallback(true) {
137+
@Override
138+
public void handleOnBackPressed() {
139+
if (SWVContext.ASWP_EXIT_ON_BACK) {
140+
if (SWVContext.ASWP_EXITDIAL) {
141+
fns.ask_exit(MainActivity.this);
142+
} else {
143+
finish();
144+
}
145+
return;
146+
}
147+
148+
if (SWVContext.asw_view.canGoBack()) {
149+
SWVContext.asw_view.goBack();
150+
} else {
151+
if (SWVContext.ASWP_EXITDIAL) {
152+
fns.ask_exit(MainActivity.this);
153+
} else {
154+
finish();
155+
}
156+
}
157+
}
158+
});
159+
160+
134161

135162
// Enable edge-to-edge display
136163
WindowCompat.setDecorFitsSystemWindows(getWindow(), false);
@@ -1037,4 +1064,4 @@ public void onReceivedHttpError(WebView view, WebResourceRequest request,
10371064
}
10381065
}
10391066
}
1040-
}
1067+
}

0 commit comments

Comments
 (0)