--- .idea/deploymentTargetDropDown.xml
+++ .idea/deploymentTargetDropDown.xml
... | ... | @@ -3,20 +3,7 @@ |
3 | 3 |
<component name="deploymentTargetDropDown"> |
4 | 4 |
<value> |
5 | 5 |
<entry key="app"> |
6 |
- <State> |
|
7 |
- <runningDeviceTargetSelectedWithDropDown> |
|
8 |
- <Target> |
|
9 |
- <type value="RUNNING_DEVICE_TARGET" /> |
|
10 |
- <deviceKey> |
|
11 |
- <Key> |
|
12 |
- <type value="SERIAL_NUMBER" /> |
|
13 |
- <value value="RFCMA00RHQD" /> |
|
14 |
- </Key> |
|
15 |
- </deviceKey> |
|
16 |
- </Target> |
|
17 |
- </runningDeviceTargetSelectedWithDropDown> |
|
18 |
- <timeTargetWasSelectedWithDropDown value="2024-03-11T06:24:22.295141900Z" /> |
|
19 |
- </State> |
|
6 |
+ <State /> |
|
20 | 7 |
</entry> |
21 | 8 |
</value> |
22 | 9 |
</component> |
--- app/src/main/AndroidManifest.xml
+++ app/src/main/AndroidManifest.xml
... | ... | @@ -4,6 +4,13 @@ |
4 | 4 |
|
5 | 5 |
<uses-permission |
6 | 6 |
android:name="android.permission.POST_NOTIFICATIONS" /> |
7 |
+ <uses-permission android:name="android.permission.INTERNET" /> |
|
8 |
+ <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" |
|
9 |
+ android:maxSdkVersion="32" /> |
|
10 |
+ <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" |
|
11 |
+ android:maxSdkVersion="32" |
|
12 |
+ tools:ignore="ScopedStorage" /> |
|
13 |
+ <uses-permission android:name="android.permission.WAKE_LOCK" /> |
|
7 | 14 |
|
8 | 15 |
<application |
9 | 16 |
android:allowBackup="true" |
... | ... | @@ -32,7 +39,6 @@ |
32 | 39 |
android:exported="true"> |
33 | 40 |
<intent-filter> |
34 | 41 |
<action android:name="android.intent.action.MAIN" /> |
35 |
- |
|
36 | 42 |
<category android:name="android.intent.category.LAUNCHER" /> |
37 | 43 |
</intent-filter> |
38 | 44 |
</activity> |
--- app/src/main/java/co/kr/ajinpaper/salesTask/MainActivity.java
+++ app/src/main/java/co/kr/ajinpaper/salesTask/MainActivity.java
... | ... | @@ -35,16 +35,16 @@ |
35 | 35 |
protected void onCreate(Bundle savedInstanceState) { |
36 | 36 |
super.onCreate(savedInstanceState); |
37 | 37 |
setContentView(R.layout.activity_main); |
38 |
+ WebView myWebView = (WebView) findViewById(R.id.webView); |
|
38 | 39 |
|
39 | 40 |
if (getIntent().getExtras() != null) { |
40 |
- Log.d("WebView", "백에서 실행함"); |
|
41 |
- String title = getIntent().getExtras().getString("title"); |
|
41 |
+ String title = getIntent().getStringExtra("title"); |
|
42 |
+ Log.d("MainActivity", "Title: " + title); |
|
43 |
+ |
|
42 | 44 |
SharedPreferences sharedPreferences = getSharedPreferences("MyApp", MODE_PRIVATE); |
43 | 45 |
SharedPreferences.Editor editor = sharedPreferences.edit(); |
44 | 46 |
editor.putString("pushTitle", title).apply(); |
45 | 47 |
} |
46 |
- |
|
47 |
- WebView myWebView = (WebView) findViewById(R.id.webView); |
|
48 | 48 |
|
49 | 49 |
WebSettings webSettings = myWebView.getSettings(); |
50 | 50 |
webSettings.setJavaScriptEnabled(true); |
--- app/src/main/java/co/kr/ajinpaper/salesTask/MyFirebaseMessagingService.java
+++ app/src/main/java/co/kr/ajinpaper/salesTask/MyFirebaseMessagingService.java
... | ... | @@ -17,6 +17,7 @@ |
17 | 17 |
import com.google.firebase.messaging.FirebaseMessagingService; |
18 | 18 |
import com.google.firebase.messaging.RemoteMessage; |
19 | 19 |
|
20 |
+import java.util.Map; |
|
20 | 21 |
import java.util.Objects; |
21 | 22 |
|
22 | 23 |
public class MyFirebaseMessagingService extends FirebaseMessagingService { |
... | ... | @@ -34,21 +35,21 @@ |
34 | 35 |
@Override |
35 | 36 |
public void onMessageReceived(@NonNull RemoteMessage remoteMessage) { |
36 | 37 |
super.onMessageReceived(remoteMessage); |
37 |
- // TODO: 푸시 메시지를 처리합니다. |
|
38 |
- if (remoteMessage.getNotification() != null) { |
|
39 |
- String title = remoteMessage.getNotification().getTitle(); |
|
38 |
+ Map<String, String> data = remoteMessage.getData(); |
|
39 |
+ |
|
40 |
+ if (!data.isEmpty()) { |
|
41 |
+ String title = data.get("title"); |
|
42 |
+ String body = data.get("body"); |
|
43 |
+ |
|
44 |
+ Log.d("MyFirebaseMessaging", "Received data: " + title + ", " + body); |
|
40 | 45 |
SharedPreferences sharedPreferences = getSharedPreferences("MyApp", MODE_PRIVATE); |
41 | 46 |
SharedPreferences.Editor editor = sharedPreferences.edit(); |
42 | 47 |
editor.putString("pushTitle", title); |
43 | 48 |
editor.apply(); |
44 |
- // 알림 채널 생성 (Android Oreo 이상) |
|
49 |
+ |
|
45 | 50 |
createNotificationChannel(); |
46 |
- |
|
47 |
- // 알림 표시 |
|
48 |
- showNotification(remoteMessage); |
|
51 |
+ showNotification(title, body); |
|
49 | 52 |
} |
50 |
- |
|
51 |
- |
|
52 | 53 |
} |
53 | 54 |
|
54 | 55 |
// 알림 채널 생성 |
... | ... | @@ -64,11 +65,10 @@ |
64 | 65 |
} |
65 | 66 |
|
66 | 67 |
// 알림 표시 |
67 |
- private void showNotification(RemoteMessage remoteMessage) { |
|
68 |
+ private void showNotification(String title, String message) { |
|
68 | 69 |
Intent intent = new Intent(this, MainActivity.class); |
69 |
- String title = Objects.requireNonNull(remoteMessage.getNotification()).getTitle(); |
|
70 |
- String message = remoteMessage.getNotification().getBody(); |
|
71 |
- PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_IMMUTABLE); |
|
70 |
+ intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); |
|
71 |
+ PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_IMMUTABLE | PendingIntent.FLAG_UPDATE_CURRENT); |
|
72 | 72 |
|
73 | 73 |
NotificationCompat.Builder builder = new NotificationCompat.Builder(this, getString(R.string.default_notification_channel_id)) |
74 | 74 |
.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
... | ... | @@ -20,15 +20,18 @@ |
20 | 20 |
@JavascriptInterface |
21 | 21 |
public String getTitle() { |
22 | 22 |
SharedPreferences sharedPreferences = mContext.getSharedPreferences("MyApp", MODE_PRIVATE); |
23 |
+ Log.d("WebView", "호출됨: 등록"); |
|
24 |
+ |
|
23 | 25 |
return sharedPreferences.getString("pushTitle", ""); |
24 | 26 |
} |
25 | 27 |
|
26 | 28 |
@JavascriptInterface |
27 |
- public void deleteTitle() { |
|
29 |
+ public int deleteTitle() { |
|
28 | 30 |
SharedPreferences sharedPreferences = mContext.getSharedPreferences("MyApp", MODE_PRIVATE); |
29 | 31 |
SharedPreferences.Editor editor = sharedPreferences.edit(); |
30 |
- editor.remove("title"); |
|
31 |
- editor.apply(); |
|
32 |
+ editor.remove("pushTitle").apply(); |
|
33 |
+ Log.d("WebView", "호출됨: 삭제"); |
|
34 |
+ return 0; |
|
32 | 35 |
} |
33 | 36 |
|
34 | 37 |
@JavascriptInterface |
Add a comment
Delete comment
Once you delete this comment, you won't be able to recover it. Are you sure you want to delete this comment?