박민혁 박민혁 03-11
240304 박민혁 푸시 클릭 시 해당 페이지로 이동 기능
@cdd4636cc562b1f1f8cb7a5af284155b03adfcdf
.idea/deploymentTargetDropDown.xml
--- .idea/deploymentTargetDropDown.xml
+++ .idea/deploymentTargetDropDown.xml
@@ -3,20 +3,7 @@
   <component name="deploymentTargetDropDown">
     <value>
       <entry key="app">
-        <State>
-          <runningDeviceTargetSelectedWithDropDown>
-            <Target>
-              <type value="RUNNING_DEVICE_TARGET" />
-              <deviceKey>
-                <Key>
-                  <type value="SERIAL_NUMBER" />
-                  <value value="RFCMA00RHQD" />
-                </Key>
-              </deviceKey>
-            </Target>
-          </runningDeviceTargetSelectedWithDropDown>
-          <timeTargetWasSelectedWithDropDown value="2024-03-11T06:24:22.295141900Z" />
-        </State>
+        <State />
       </entry>
     </value>
   </component>
app/src/main/AndroidManifest.xml
--- app/src/main/AndroidManifest.xml
+++ app/src/main/AndroidManifest.xml
@@ -4,6 +4,13 @@
 
     <uses-permission
         android:name="android.permission.POST_NOTIFICATIONS" />
+    <uses-permission android:name="android.permission.INTERNET" />
+    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"
+        android:maxSdkVersion="32" />
+    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"
+        android:maxSdkVersion="32"
+        tools:ignore="ScopedStorage" />
+    <uses-permission android:name="android.permission.WAKE_LOCK" />
 
     <application
         android:allowBackup="true"
@@ -32,7 +39,6 @@
             android:exported="true">
             <intent-filter>
                 <action android:name="android.intent.action.MAIN" />
-
                 <category android:name="android.intent.category.LAUNCHER" />
             </intent-filter>
         </activity>
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
@@ -35,16 +35,16 @@
     protected void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         setContentView(R.layout.activity_main);
+        WebView myWebView = (WebView) findViewById(R.id.webView);
 
         if (getIntent().getExtras() != null) {
-            Log.d("WebView", "백에서 실행함");
-            String title = getIntent().getExtras().getString("title");
+            String title = getIntent().getStringExtra("title");
+            Log.d("MainActivity", "Title: " + title);
+
             SharedPreferences sharedPreferences = getSharedPreferences("MyApp", MODE_PRIVATE);
             SharedPreferences.Editor editor = sharedPreferences.edit();
             editor.putString("pushTitle", title).apply();
         }
-
-        WebView myWebView = (WebView) findViewById(R.id.webView);
 
         WebSettings webSettings = myWebView.getSettings();
         webSettings.setJavaScriptEnabled(true);
app/src/main/java/co/kr/ajinpaper/salesTask/MyFirebaseMessagingService.java
--- app/src/main/java/co/kr/ajinpaper/salesTask/MyFirebaseMessagingService.java
+++ app/src/main/java/co/kr/ajinpaper/salesTask/MyFirebaseMessagingService.java
@@ -17,6 +17,7 @@
 import com.google.firebase.messaging.FirebaseMessagingService;
 import com.google.firebase.messaging.RemoteMessage;
 
+import java.util.Map;
 import java.util.Objects;
 
 public class MyFirebaseMessagingService extends FirebaseMessagingService {
@@ -34,21 +35,21 @@
     @Override
     public void onMessageReceived(@NonNull RemoteMessage remoteMessage) {
         super.onMessageReceived(remoteMessage);
-        // TODO: 푸시 메시지를 처리합니다.
-        if (remoteMessage.getNotification() != null) {
-            String title = remoteMessage.getNotification().getTitle();
+        Map<String, String> data = remoteMessage.getData();
+
+        if (!data.isEmpty()) {
+            String title = data.get("title");
+            String body = data.get("body");
+
+            Log.d("MyFirebaseMessaging", "Received data: " + title + ", " + body);
             SharedPreferences sharedPreferences = getSharedPreferences("MyApp", MODE_PRIVATE);
             SharedPreferences.Editor editor = sharedPreferences.edit();
             editor.putString("pushTitle", title);
             editor.apply();
-            // 알림 채널 생성 (Android Oreo 이상)
+
             createNotificationChannel();
-
-            // 알림 표시
-            showNotification(remoteMessage);
+            showNotification(title, body);
         }
-
-
     }
 
     // 알림 채널 생성
@@ -64,11 +65,10 @@
     }
 
     // 알림 표시
-    private void showNotification(RemoteMessage remoteMessage) {
+    private void showNotification(String title, String message) {
         Intent intent = new Intent(this, MainActivity.class);
-        String title = Objects.requireNonNull(remoteMessage.getNotification()).getTitle();
-        String message = remoteMessage.getNotification().getBody();
-        PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_IMMUTABLE);
+        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
+        PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_IMMUTABLE | PendingIntent.FLAG_UPDATE_CURRENT);
 
         NotificationCompat.Builder builder = new NotificationCompat.Builder(this, getString(R.string.default_notification_channel_id))
                 .setSmallIcon(R.mipmap.ic_launcher)
app/src/main/java/co/kr/ajinpaper/salesTask/WebAppInterface.java
--- app/src/main/java/co/kr/ajinpaper/salesTask/WebAppInterface.java
+++ app/src/main/java/co/kr/ajinpaper/salesTask/WebAppInterface.java
@@ -20,15 +20,18 @@
     @JavascriptInterface
     public String getTitle() {
         SharedPreferences sharedPreferences = mContext.getSharedPreferences("MyApp", MODE_PRIVATE);
+        Log.d("WebView", "호출됨: 등록");
+
         return sharedPreferences.getString("pushTitle", "");
     }
 
     @JavascriptInterface
-    public void deleteTitle() {
+    public int deleteTitle() {
         SharedPreferences sharedPreferences = mContext.getSharedPreferences("MyApp", MODE_PRIVATE);
         SharedPreferences.Editor editor = sharedPreferences.edit();
-        editor.remove("title");
-        editor.apply();
+        editor.remove("pushTitle").apply();
+        Log.d("WebView", "호출됨: 삭제");
+        return 0;
     }
 
     @JavascriptInterface
Add a comment
List