박민혁 박민혁 04-03
240315 박민혁 뒤로 가기 버튼 수정
@b407a453c6dac03d88baafb6e397c994cb187e08
app/src/main/java/co/kr/ajinpaper/salesTask/MainActivity.java
--- app/src/main/java/co/kr/ajinpaper/salesTask/MainActivity.java
+++ app/src/main/java/co/kr/ajinpaper/salesTask/MainActivity.java
@@ -1,5 +1,6 @@
 package co.kr.ajinpaper.salesTask;
 
+import androidx.activity.OnBackPressedCallback;
 import androidx.activity.result.ActivityResultLauncher;
 import androidx.activity.result.contract.ActivityResultContracts;
 import androidx.annotation.NonNull;
@@ -31,8 +32,9 @@
 public class MainActivity extends AppCompatActivity {
     private ValueCallback<Uri[]> mUploadMessage;
     private Uri mCapturedImageURI = null;
-
     private PermissionManager permission;
+    private long lastBackPressedTime = 0; // 마지막으로 뒤로 가기 버튼이 눌린 시간을 기록하는 변수
+    private static final int BACK_PRESS_INTERVAL = 2000; // 2초 간격
 
     @SuppressLint("SetJavaScriptEnabled")
     @Override
@@ -51,6 +53,24 @@
             SharedPreferences.Editor editor = sharedPreferences.edit();
             editor.putString("pushTitle", title).apply();
         }
+
+        // 뒤로 가기 버튼으로 뒤로 가기 구현
+        OnBackPressedCallback callback = new OnBackPressedCallback(true) {
+            @Override
+            public void handleOnBackPressed() {
+                if (myWebView.canGoBack()) {
+                    myWebView.goBack();
+                } else {
+                    if (lastBackPressedTime + BACK_PRESS_INTERVAL > System.currentTimeMillis()) {
+                        finish();
+                    } else {
+                        Toast.makeText(MainActivity.this, "뒤로 가기 버튼을 한 번 더 누르면 종료됩니다.", Toast.LENGTH_SHORT).show();
+                    }
+                    lastBackPressedTime = System.currentTimeMillis();
+                }
+            }
+        };
+        getOnBackPressedDispatcher().addCallback(this, callback);
 
         WebSettings webSettings = myWebView.getSettings();
         webSettings.setJavaScriptEnabled(true);
@@ -89,7 +109,7 @@
                     }
                 }
 
-                Intent contentSelectionIntent = new Intent(Intent.ACTION_OPEN_DOCUMENT); // 변경된 부분
+                Intent contentSelectionIntent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
                 contentSelectionIntent.addCategory(Intent.CATEGORY_OPENABLE);
                 contentSelectionIntent.setType("image/*");
                 contentSelectionIntent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
@@ -106,7 +126,7 @@
                 chooserIntent.putExtra(Intent.EXTRA_TITLE, "Image Chooser");
                 chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, intentArray);
 
-                mFileChooser.launch(chooserIntent);  // 수정된 부분
+                mFileChooser.launch(chooserIntent);
 
                 return true;
             }
@@ -117,6 +137,7 @@
 
     }
 
+    // 이미지 파일 등록 가능하도록
     private final ActivityResultLauncher<Intent> mFileChooser = registerForActivityResult(
             new ActivityResultContracts.StartActivityForResult(),
             result -> {
@@ -167,6 +188,7 @@
         }
     }
 
+    // 권함 알림 메소드
     private void permissionCheck(){
         if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
             permission = new PermissionManager(this, this);
Add a comment
List