From d723165b76de17644eacf36f190e58a091944c64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=82=8D=E3=82=80=E3=81=AD=E3=81=93?= Date: Thu, 11 Jul 2024 14:22:28 +0900 Subject: [PATCH 01/72] =?UTF-8?q?=E4=B8=8D=E8=A6=81=E3=81=AA=E6=AF=94?= =?UTF-8?q?=E8=BC=83=E3=82=92=E5=89=8A=E9=99=A4(=E3=82=A2=E3=83=97?= =?UTF-8?q?=E3=83=AA=E3=81=AE=E8=A6=81=E6=B1=82API=E3=83=90=E3=83=BC?= =?UTF-8?q?=E3=82=B8=E3=83=A7=E3=83=B3=E3=81=8C=E3=82=82=E3=81=A8=E3=82=82?= =?UTF-8?q?=E3=81=A826(=3D8.0(=3DOreo))=E3=81=AE=E3=81=9F=E3=82=81)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/example/childguard/TestService.java | 28 +++++++++---------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/app/src/main/java/com/example/childguard/TestService.java b/app/src/main/java/com/example/childguard/TestService.java index 7a69b01..e616227 100644 --- a/app/src/main/java/com/example/childguard/TestService.java +++ b/app/src/main/java/com/example/childguard/TestService.java @@ -181,22 +181,20 @@ public class TestService extends Service { .setPriority(NotificationCompat.PRIORITY_HIGH) // プライオリティを高く設定 .setVisibility(NotificationCompat.VISIBILITY_PUBLIC); // ロック画面に表示する - // NotificationChannelの作成(Android 8.0以降) - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { - NotificationManager notificationManager = context.getSystemService(NotificationManager.class); - if (notificationManager != null) { - NotificationChannel channel = new NotificationChannel( - CHANNEL_ID, - "Channel Name", - NotificationManager.IMPORTANCE_HIGH - ); + // 通知チャンネルの作成 + NotificationManager notificationManager = context.getSystemService(NotificationManager.class); + if (notificationManager != null) { + NotificationChannel channel = new NotificationChannel( + CHANNEL_ID, + "Channel Name", + NotificationManager.IMPORTANCE_HIGH + ); - channel.setDescription("Channel Description"); - channel.enableLights(true); - channel.setLightColor(Color.RED); - channel.enableVibration(true); - notificationManager.createNotificationChannel(channel); - } + channel.setDescription("Channel Description"); + channel.enableLights(true); + channel.setLightColor(Color.RED); + channel.enableVibration(true); + notificationManager.createNotificationChannel(channel); } From 6667a63bff93250f0e8e9539e8a4356cb1385b24 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=82=8D=E3=82=80=E3=81=AD=E3=81=93?= Date: Thu, 11 Jul 2024 14:23:18 +0900 Subject: [PATCH 02/72] =?UTF-8?q?notificationManager=E3=82=92=E5=85=B1?= =?UTF-8?q?=E6=9C=89=E3=81=99=E3=82=8B=E3=82=88=E3=81=86=E3=81=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/com/example/childguard/TestService.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/app/src/main/java/com/example/childguard/TestService.java b/app/src/main/java/com/example/childguard/TestService.java index e616227..c22f70a 100644 --- a/app/src/main/java/com/example/childguard/TestService.java +++ b/app/src/main/java/com/example/childguard/TestService.java @@ -197,8 +197,6 @@ public class TestService extends Service { notificationManager.createNotificationChannel(channel); } - - NotificationManager notificationManager = (NotificationManager) context.getSystemService(context.NOTIFICATION_SERVICE); if (ActivityCompat.checkSelfPermission(this, android.Manifest.permission.POST_NOTIFICATIONS) != PackageManager.PERMISSION_GRANTED) { return; } From e77b50eee3326201372d01a694b200bf283919e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=82=8D=E3=82=80=E3=81=AD=E3=81=93?= Date: Thu, 11 Jul 2024 14:25:05 +0900 Subject: [PATCH 03/72] =?UTF-8?q?=E6=A8=A9=E9=99=90=E3=83=81=E3=82=A7?= =?UTF-8?q?=E3=83=83=E3=82=AF=E3=81=AF=E3=83=A1=E3=82=BD=E3=83=83=E3=83=89?= =?UTF-8?q?=E3=81=AE=E6=9C=80=E5=88=9D=E3=81=A7=E8=A1=8C=E3=81=86=E3=82=88?= =?UTF-8?q?=E3=81=86=E3=81=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/com/example/childguard/TestService.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/com/example/childguard/TestService.java b/app/src/main/java/com/example/childguard/TestService.java index c22f70a..65e6a2b 100644 --- a/app/src/main/java/com/example/childguard/TestService.java +++ b/app/src/main/java/com/example/childguard/TestService.java @@ -161,6 +161,11 @@ public class TestService extends Service { } public void NotificationBluetooth(Context context) {//実際に通知を行うメソッド + + // 権限の保有を確認 + if (ActivityCompat.checkSelfPermission(this, + android.Manifest.permission.POST_NOTIFICATIONS) != PackageManager.PERMISSION_GRANTED) return; + final String CHANNEL_ID = "my_channel_id"; // 通知がクリックされたときに送信されるIntent Intent intent = new Intent(context, MainActivity.class); @@ -196,10 +201,6 @@ public class TestService extends Service { channel.enableVibration(true); notificationManager.createNotificationChannel(channel); } - - if (ActivityCompat.checkSelfPermission(this, android.Manifest.permission.POST_NOTIFICATIONS) != PackageManager.PERMISSION_GRANTED) { - return; - } notificationManager.notify(R.string.app_name, builder.build());//通知の表示 } From 8a4fa768a80706690083cb09671a8c5fa5b9abb1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=82=8D=E3=82=80=E3=81=AD=E3=81=93?= Date: Thu, 11 Jul 2024 14:27:52 +0900 Subject: [PATCH 04/72] =?UTF-8?q?=E9=9D=9E=E6=8E=A8=E5=A5=A8=E3=81=AB?= =?UTF-8?q?=E3=81=AA=E3=81=A3=E3=81=9F=E3=83=90=E3=82=A4=E3=83=96=E3=83=AC?= =?UTF-8?q?=E3=83=BC=E3=82=B7=E3=83=A7=E3=83=B3=E5=87=A6=E7=90=86=E3=82=92?= =?UTF-8?q?=E7=BD=AE=E6=8F=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/com/example/childguard/TestService.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/example/childguard/TestService.java b/app/src/main/java/com/example/childguard/TestService.java index 65e6a2b..076175a 100644 --- a/app/src/main/java/com/example/childguard/TestService.java +++ b/app/src/main/java/com/example/childguard/TestService.java @@ -16,6 +16,7 @@ import android.graphics.Color; import android.os.Build; import android.os.Handler; import android.os.IBinder; +import android.os.VibrationEffect; import android.os.Vibrator; import android.preference.PreferenceManager; import android.util.Log; @@ -175,7 +176,10 @@ public class TestService extends Service { int flags = 0; PendingIntent pendingIntent = PendingIntent.getActivity(context, requestCode, intent, flags | PendingIntent.FLAG_IMMUTABLE); - ((Vibrator) getSystemService(Context.VIBRATOR_SERVICE)).vibrate(2000);//バイブレーション + Vibrator vibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE); + if (vibrator.hasVibrator()) { + vibrator.vibrate(VibrationEffect.createOneShot(2000, VibrationEffect.DEFAULT_AMPLITUDE)); + } @SuppressLint("NotificationTrampoline") NotificationCompat.Builder builder = new NotificationCompat.Builder(context, "CHANNEL_ID") .setSmallIcon(android.R.drawable.ic_menu_info_details) From 55334597c3130d65b1aba3482c6bf26063d429b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=82=8D=E3=82=80=E3=81=AD=E3=81=93?= Date: Thu, 11 Jul 2024 14:29:03 +0900 Subject: [PATCH 05/72] =?UTF-8?q?=E4=B8=8D=E8=A6=81=E3=81=AASuppress?= =?UTF-8?q?=E3=82=92=E5=89=8A=E9=99=A4(=E4=B8=8D=E5=85=B7=E5=90=88?= =?UTF-8?q?=E3=81=AB=E6=B0=97=E3=81=A5=E3=81=91=E3=81=AA=E3=81=8F=E3=81=AA?= =?UTF-8?q?=E3=82=8B=E3=81=9F=E3=82=81)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/com/example/childguard/TestService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/com/example/childguard/TestService.java b/app/src/main/java/com/example/childguard/TestService.java index 076175a..5d0308b 100644 --- a/app/src/main/java/com/example/childguard/TestService.java +++ b/app/src/main/java/com/example/childguard/TestService.java @@ -181,7 +181,7 @@ public class TestService extends Service { vibrator.vibrate(VibrationEffect.createOneShot(2000, VibrationEffect.DEFAULT_AMPLITUDE)); } - @SuppressLint("NotificationTrampoline") NotificationCompat.Builder builder = new NotificationCompat.Builder(context, "CHANNEL_ID") + NotificationCompat.Builder builder = new NotificationCompat.Builder(context, "CHANNEL_ID") .setSmallIcon(android.R.drawable.ic_menu_info_details) .setContentTitle("子供の置き去りをしていませんか?")//通知のタイトル .setContentText("Bluetoothと車の切断から5分が経過しました")//通知の本文 From 2c5f0fe66788453f20a325d0848b72682b5ac0c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=82=8D=E3=82=80=E3=81=AD=E3=81=93?= Date: Thu, 11 Jul 2024 14:40:34 +0900 Subject: [PATCH 06/72] =?UTF-8?q?=E9=80=9A=E7=9F=A5=E3=83=81=E3=83=A3?= =?UTF-8?q?=E3=83=B3=E3=83=8D=E3=83=AB=E3=81=AE=E4=BD=9C=E6=88=90=E5=87=A6?= =?UTF-8?q?=E7=90=86=E3=82=92=E7=B5=B1=E4=B8=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/example/childguard/TestService.java | 58 ++++++++----------- 1 file changed, 25 insertions(+), 33 deletions(-) diff --git a/app/src/main/java/com/example/childguard/TestService.java b/app/src/main/java/com/example/childguard/TestService.java index 5d0308b..3de3f32 100644 --- a/app/src/main/java/com/example/childguard/TestService.java +++ b/app/src/main/java/com/example/childguard/TestService.java @@ -36,6 +36,7 @@ public class TestService extends Service { DocumentReference mDocRef; public static final String TAG = "InspirationQuote"; + private static final String CHANNEL_ID = "child_guard_emergency"; @Override @@ -58,6 +59,27 @@ public class TestService extends Service { } + @Override + public void onCreate() { + super.onCreate(); + if (!isNotificationChannelCreated()) { + createNotificationChannel(); + } + } + + private boolean isNotificationChannelCreated() { + NotificationManager notificationManager = getSystemService(NotificationManager.class); + return notificationManager.getNotificationChannel(CHANNEL_ID) != null; + } + + private void createNotificationChannel() { + int importance = NotificationManager.IMPORTANCE_DEFAULT; + NotificationChannel channel = new NotificationChannel(CHANNEL_ID, "通知", importance); + channel.setDescription("第三者により置き去りの通報が行われたときに通知します。"); + NotificationManager notificationManager = getSystemService(NotificationManager.class); + notificationManager.createNotificationChannel(channel); + } + private void initNotification(DocumentReference mDocRef) {//サイト上で押されたボタンの管理 // PeriodicTaskManagerのインスタンス化 @@ -126,7 +148,7 @@ public class TestService extends Service { ((Vibrator) getSystemService(Context.VIBRATOR_SERVICE)).vibrate(2000);//バイブレーション - @SuppressLint("NotificationTrampoline") NotificationCompat.Builder builder = new NotificationCompat.Builder(context, "CHANNEL_ID") + @SuppressLint("NotificationTrampoline") NotificationCompat.Builder builder = new NotificationCompat.Builder(context, CHANNEL_ID) .setSmallIcon(android.R.drawable.ic_menu_info_details) .setContentTitle("子供の置き去りをしていませんか?")//通知のタイトル .setContentText("第三者からの通報が行われました。")//通知の本文 @@ -135,26 +157,8 @@ public class TestService extends Service { .setPriority(NotificationCompat.PRIORITY_HIGH) // プライオリティを高く設定 .setVisibility(NotificationCompat.VISIBILITY_PUBLIC); // ロック画面に表示する - // NotificationChannelの作成(Android 8.0以降) - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { - NotificationManager notificationManager = context.getSystemService(NotificationManager.class); - if (notificationManager != null) { - NotificationChannel channel = new NotificationChannel( - CHANNEL_ID, - "Channel Name", - NotificationManager.IMPORTANCE_HIGH - ); + NotificationManager notificationManager = context.getSystemService(NotificationManager.class); - channel.setDescription("Channel Description"); - channel.enableLights(true); - channel.setLightColor(Color.RED); - channel.enableVibration(true); - notificationManager.createNotificationChannel(channel); - } - } - - - NotificationManager notificationManager = (NotificationManager) context.getSystemService(context.NOTIFICATION_SERVICE); if (ActivityCompat.checkSelfPermission(this, android.Manifest.permission.POST_NOTIFICATIONS) != PackageManager.PERMISSION_GRANTED) { return; } @@ -181,7 +185,7 @@ public class TestService extends Service { vibrator.vibrate(VibrationEffect.createOneShot(2000, VibrationEffect.DEFAULT_AMPLITUDE)); } - NotificationCompat.Builder builder = new NotificationCompat.Builder(context, "CHANNEL_ID") + NotificationCompat.Builder builder = new NotificationCompat.Builder(context, CHANNEL_ID) .setSmallIcon(android.R.drawable.ic_menu_info_details) .setContentTitle("子供の置き去りをしていませんか?")//通知のタイトル .setContentText("Bluetoothと車の切断から5分が経過しました")//通知の本文 @@ -192,19 +196,7 @@ public class TestService extends Service { // 通知チャンネルの作成 NotificationManager notificationManager = context.getSystemService(NotificationManager.class); - if (notificationManager != null) { - NotificationChannel channel = new NotificationChannel( - CHANNEL_ID, - "Channel Name", - NotificationManager.IMPORTANCE_HIGH - ); - channel.setDescription("Channel Description"); - channel.enableLights(true); - channel.setLightColor(Color.RED); - channel.enableVibration(true); - notificationManager.createNotificationChannel(channel); - } notificationManager.notify(R.string.app_name, builder.build());//通知の表示 } From 61c2abcdad4aeba6ef7c5f9203887e2606de37b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=82=8D=E3=82=80=E3=81=AD=E3=81=93?= Date: Thu, 11 Jul 2024 14:41:17 +0900 Subject: [PATCH 07/72] add JavaDoc --- app/src/main/java/com/example/childguard/TestService.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/app/src/main/java/com/example/childguard/TestService.java b/app/src/main/java/com/example/childguard/TestService.java index 3de3f32..7592145 100644 --- a/app/src/main/java/com/example/childguard/TestService.java +++ b/app/src/main/java/com/example/childguard/TestService.java @@ -67,11 +67,18 @@ public class TestService extends Service { } } + /** + * 通知チャネルが作成されているか確認 + * @return 通知チャンネルの有無 true: 作成済み false: 未作成 + */ private boolean isNotificationChannelCreated() { NotificationManager notificationManager = getSystemService(NotificationManager.class); return notificationManager.getNotificationChannel(CHANNEL_ID) != null; } + /** + * 通知チャネルの作成 + */ private void createNotificationChannel() { int importance = NotificationManager.IMPORTANCE_DEFAULT; NotificationChannel channel = new NotificationChannel(CHANNEL_ID, "通知", importance); From e9c10fc2664905f256779e30768144fcc148fece Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=82=8D=E3=82=80=E3=81=AD=E3=81=93?= Date: Thu, 11 Jul 2024 14:42:22 +0900 Subject: [PATCH 08/72] =?UTF-8?q?=E6=9C=AA=E4=BD=BF=E7=94=A8=E5=87=A6?= =?UTF-8?q?=E7=90=86=E3=82=92=E5=89=8A=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/com/example/childguard/TestService.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/app/src/main/java/com/example/childguard/TestService.java b/app/src/main/java/com/example/childguard/TestService.java index 7592145..6e128f6 100644 --- a/app/src/main/java/com/example/childguard/TestService.java +++ b/app/src/main/java/com/example/childguard/TestService.java @@ -126,8 +126,6 @@ public class TestService extends Service { String IdPref = sharedPreferences.getString("ID", null);//アプリに記録されているIDの取得 db = FirebaseFirestore.getInstance();//Firebaseとの紐づけ DocumentReference isReported = db.collection("status").document(IdPref);//更新するドキュメントとの紐づけ - Map DEFAULT_ITEM = new HashMap<>();//mapの宣言 - DEFAULT_ITEM.put("isReported", false); //isReportedをfalseに更新 isReported.update("isReported", false).addOnSuccessListener(unused -> Log.d(TAG, "DocumentSnapshot successfully updated!")).addOnFailureListener(e -> Log.w(TAG, "Error updating document", e)); } From 368d2368baeea253e27b4d617795af4d2ac9f044 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=82=8D=E3=82=80=E3=81=AD=E3=81=93?= Date: Thu, 11 Jul 2024 14:45:42 +0900 Subject: [PATCH 09/72] =?UTF-8?q?=E3=83=A6=E3=83=BC=E3=82=B6=E3=83=BCID?= =?UTF-8?q?=E3=81=AE=E5=8F=96=E5=BE=97=E3=82=92=E5=85=B1=E9=80=9A=E5=8C=96?= =?UTF-8?q?=20+=20=E3=82=A4=E3=83=B3=E3=82=B9=E3=82=BF=E3=83=B3=E3=82=B9?= =?UTF-8?q?=E5=A4=89=E6=95=B0=E3=81=A7=E7=AE=A1=E7=90=86=E3=81=99=E3=82=8B?= =?UTF-8?q?=E3=82=88=E3=81=86=E3=81=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/example/childguard/TestService.java | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/com/example/childguard/TestService.java b/app/src/main/java/com/example/childguard/TestService.java index 6e128f6..f2c955b 100644 --- a/app/src/main/java/com/example/childguard/TestService.java +++ b/app/src/main/java/com/example/childguard/TestService.java @@ -37,26 +37,25 @@ public class TestService extends Service { public static final String TAG = "InspirationQuote"; private static final String CHANNEL_ID = "child_guard_emergency"; + // ユーザーID + private String userId = null; @Override public int onStartCommand(Intent intent, int flags, int startId) { - - //共有プリファレンス全体の準備 SharedPreferences sharedPreferences = getSharedPreferences("app_situation", MODE_PRIVATE); - String IdPref = sharedPreferences.getString("ID", null);//アプリに記録されているIDの取得 - if (IdPref == null) {//FireBaseのIDがアプリに登録されているとき + this.userId = sharedPreferences.getString("ID", null);//アプリに記録されているIDの取得 + if (this.userId == null) { Log.d("onResume", "ID not initialized."); + return flags; // IDが初期化されていない場合は何もしない } else { - mDocRef = FirebaseFirestore.getInstance().document("status/" + IdPref);//現在の位置を取得 + mDocRef = FirebaseFirestore.getInstance().document("status/" + this.userId);//現在の位置を取得 initNotification(mDocRef);//現在の位置を引数に initNotification()を処理 } Bluetooth_status(); return flags; - - } @Override @@ -121,11 +120,8 @@ public class TestService extends Service { } public void ResetReported() {//FireBaseのisReportedをfalseに初期化するメソッド - //共有プリファレンス全体の準備 - SharedPreferences sharedPreferences = getSharedPreferences("app_situation", MODE_PRIVATE); - String IdPref = sharedPreferences.getString("ID", null);//アプリに記録されているIDの取得 db = FirebaseFirestore.getInstance();//Firebaseとの紐づけ - DocumentReference isReported = db.collection("status").document(IdPref);//更新するドキュメントとの紐づけ + DocumentReference isReported = db.collection("status").document(this.userId); //isReportedをfalseに更新 isReported.update("isReported", false).addOnSuccessListener(unused -> Log.d(TAG, "DocumentSnapshot successfully updated!")).addOnFailureListener(e -> Log.w(TAG, "Error updating document", e)); } From 37dd6b630a933f53d676eff378e02c0ab85ad4eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=82=8D=E3=82=80=E3=81=AD=E3=81=93?= Date: Thu, 11 Jul 2024 14:46:12 +0900 Subject: [PATCH 10/72] =?UTF-8?q?=E6=94=B9=E8=A1=8C=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/com/example/childguard/TestService.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/example/childguard/TestService.java b/app/src/main/java/com/example/childguard/TestService.java index f2c955b..ac91fe7 100644 --- a/app/src/main/java/com/example/childguard/TestService.java +++ b/app/src/main/java/com/example/childguard/TestService.java @@ -123,7 +123,8 @@ public class TestService extends Service { db = FirebaseFirestore.getInstance();//Firebaseとの紐づけ DocumentReference isReported = db.collection("status").document(this.userId); //isReportedをfalseに更新 - isReported.update("isReported", false).addOnSuccessListener(unused -> Log.d(TAG, "DocumentSnapshot successfully updated!")).addOnFailureListener(e -> Log.w(TAG, "Error updating document", e)); + isReported.update("isReported", false).addOnSuccessListener(unused -> + Log.d(TAG, "DocumentSnapshot successfully updated!")).addOnFailureListener(e -> Log.w(TAG, "Error updating document", e)); } public void NotificationSetting() {//通知に関する設定の処理を行うメソッド @@ -134,7 +135,6 @@ public class TestService extends Service { NotificationManager notificationManager = getSystemService(NotificationManager.class); notificationManager.createNotificationChannel(channel); - } public void Notification(Context context) {//実際に通知を行うメソッド From 6a998d571854e6c814bf7fcd2b67a63d883fecc0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=82=8D=E3=82=80=E3=81=AD=E3=81=93?= Date: Thu, 11 Jul 2024 14:51:59 +0900 Subject: [PATCH 11/72] =?UTF-8?q?pendingIntent=E3=81=AE=E7=94=9F=E6=88=90?= =?UTF-8?q?=E5=87=A6=E7=90=86=E3=82=92=E7=B5=B1=E4=B8=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/example/childguard/TestService.java | 26 +++++++------------ 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/app/src/main/java/com/example/childguard/TestService.java b/app/src/main/java/com/example/childguard/TestService.java index ac91fe7..ee0a8cd 100644 --- a/app/src/main/java/com/example/childguard/TestService.java +++ b/app/src/main/java/com/example/childguard/TestService.java @@ -37,6 +37,8 @@ public class TestService extends Service { public static final String TAG = "InspirationQuote"; private static final String CHANNEL_ID = "child_guard_emergency"; + private static final int REQUEST_CODE = 100; + // ユーザーID private String userId = null; @@ -137,15 +139,13 @@ public class TestService extends Service { notificationManager.createNotificationChannel(channel); } - public void Notification(Context context) {//実際に通知を行うメソッド - final String CHANNEL_ID = "my_channel_id"; - // 通知がクリックされたときに送信されるIntent + private PendingIntent getPendingIntent(Context context, int requestCode, int flags) { Intent intent = new Intent(context, MainActivity.class); intent.setAction("OPEN_ACTIVITY"); - // PendingIntentの作成 - int requestCode = 100; - int flags = 0; - PendingIntent pendingIntent = PendingIntent.getActivity(context, requestCode, intent, flags | PendingIntent.FLAG_IMMUTABLE); + return PendingIntent.getActivity(context, requestCode, intent, flags | PendingIntent.FLAG_IMMUTABLE); + } + + public void Notification(Context context) {//実際に通知を行うメソッド ((Vibrator) getSystemService(Context.VIBRATOR_SERVICE)).vibrate(2000);//バイブレーション @@ -153,7 +153,7 @@ public class TestService extends Service { .setSmallIcon(android.R.drawable.ic_menu_info_details) .setContentTitle("子供の置き去りをしていませんか?")//通知のタイトル .setContentText("第三者からの通報が行われました。")//通知の本文 - .setContentIntent(pendingIntent)//通知をタップするとActivityへ移動する + .setContentIntent(getPendingIntent(context, REQUEST_CODE, 0))//通知をタップするとActivityへ移動する .setAutoCancel(true)//通知をタップすると削除する .setPriority(NotificationCompat.PRIORITY_HIGH) // プライオリティを高く設定 .setVisibility(NotificationCompat.VISIBILITY_PUBLIC); // ロック画面に表示する @@ -172,14 +172,6 @@ public class TestService extends Service { if (ActivityCompat.checkSelfPermission(this, android.Manifest.permission.POST_NOTIFICATIONS) != PackageManager.PERMISSION_GRANTED) return; - final String CHANNEL_ID = "my_channel_id"; - // 通知がクリックされたときに送信されるIntent - Intent intent = new Intent(context, MainActivity.class); - intent.setAction("OPEN_ACTIVITY"); - // PendingIntentの作成 - int requestCode = 100; - int flags = 0; - PendingIntent pendingIntent = PendingIntent.getActivity(context, requestCode, intent, flags | PendingIntent.FLAG_IMMUTABLE); Vibrator vibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE); if (vibrator.hasVibrator()) { @@ -190,7 +182,7 @@ public class TestService extends Service { .setSmallIcon(android.R.drawable.ic_menu_info_details) .setContentTitle("子供の置き去りをしていませんか?")//通知のタイトル .setContentText("Bluetoothと車の切断から5分が経過しました")//通知の本文 - .setContentIntent(pendingIntent)//通知をタップするとActivityへ移動する + .setContentIntent(getPendingIntent(context, REQUEST_CODE, 0))//通知をタップするとActivityへ移動する .setAutoCancel(true)//通知をタップすると削除する .setPriority(NotificationCompat.PRIORITY_HIGH) // プライオリティを高く設定 .setVisibility(NotificationCompat.VISIBILITY_PUBLIC); // ロック画面に表示する From aca3a15686ba093abe13ed6aa22fb76f79a7a40c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=82=8D=E3=82=80=E3=81=AD=E3=81=93?= Date: Thu, 11 Jul 2024 14:53:03 +0900 Subject: [PATCH 12/72] =?UTF-8?q?=E3=83=87=E3=83=90=E3=82=A4=E3=82=B9?= =?UTF-8?q?=E3=82=92=E3=83=90=E3=82=A4=E3=83=96=E3=83=AC=E3=83=BC=E3=82=B7?= =?UTF-8?q?=E3=83=A7=E3=83=B3=E3=81=95=E3=81=9B=E3=82=8B=E5=87=A6=E7=90=86?= =?UTF-8?q?=E3=82=92=E7=B5=B1=E4=B8=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/example/childguard/TestService.java | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/com/example/childguard/TestService.java b/app/src/main/java/com/example/childguard/TestService.java index ee0a8cd..4391c20 100644 --- a/app/src/main/java/com/example/childguard/TestService.java +++ b/app/src/main/java/com/example/childguard/TestService.java @@ -145,9 +145,16 @@ public class TestService extends Service { return PendingIntent.getActivity(context, requestCode, intent, flags | PendingIntent.FLAG_IMMUTABLE); } + private void vibrateDevice() { + Vibrator vibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE); + if (vibrator.hasVibrator()) { + vibrator.vibrate(VibrationEffect.createOneShot(2000, VibrationEffect.DEFAULT_AMPLITUDE)); + } + } + public void Notification(Context context) {//実際に通知を行うメソッド - ((Vibrator) getSystemService(Context.VIBRATOR_SERVICE)).vibrate(2000);//バイブレーション + vibrateDevice(); @SuppressLint("NotificationTrampoline") NotificationCompat.Builder builder = new NotificationCompat.Builder(context, CHANNEL_ID) .setSmallIcon(android.R.drawable.ic_menu_info_details) @@ -172,11 +179,7 @@ public class TestService extends Service { if (ActivityCompat.checkSelfPermission(this, android.Manifest.permission.POST_NOTIFICATIONS) != PackageManager.PERMISSION_GRANTED) return; - - Vibrator vibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE); - if (vibrator.hasVibrator()) { - vibrator.vibrate(VibrationEffect.createOneShot(2000, VibrationEffect.DEFAULT_AMPLITUDE)); - } + vibrateDevice(); NotificationCompat.Builder builder = new NotificationCompat.Builder(context, CHANNEL_ID) .setSmallIcon(android.R.drawable.ic_menu_info_details) From 207f551bad929b24ca69d4048ea7b1bb397927d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=82=8D=E3=82=80=E3=81=AD=E3=81=93?= Date: Thu, 11 Jul 2024 14:55:19 +0900 Subject: [PATCH 13/72] =?UTF-8?q?=E9=87=8D=E8=A4=87=E3=81=97=E3=81=9F?= =?UTF-8?q?=E5=87=A6=E7=90=86=E3=82=92=E5=89=8A=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/com/example/childguard/TestService.java | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/app/src/main/java/com/example/childguard/TestService.java b/app/src/main/java/com/example/childguard/TestService.java index 4391c20..cfc0330 100644 --- a/app/src/main/java/com/example/childguard/TestService.java +++ b/app/src/main/java/com/example/childguard/TestService.java @@ -110,7 +110,6 @@ public class TestService extends Service { if (documentSnapshot.getBoolean("isReported")) { //ここスタート(リサイクル) ResetReported();// ResetReported();を処理→FireBaseのisReportedをfalseにする - NotificationSetting();//通知に関する設定のメソッド Notification(getApplicationContext());//通知を行うメソッド } } else {//isReportedがfalse=サイト上で降車状態のとき @@ -129,16 +128,6 @@ public class TestService extends Service { Log.d(TAG, "DocumentSnapshot successfully updated!")).addOnFailureListener(e -> Log.w(TAG, "Error updating document", e)); } - public void NotificationSetting() {//通知に関する設定の処理を行うメソッド - int importance = NotificationManager.IMPORTANCE_DEFAULT; - //通知チャネルの実装 - NotificationChannel channel = new NotificationChannel("CHANNEL_ID", "通知", importance); - channel.setDescription("第三者により置き去りの通報が行われたときに通知します。"); - - NotificationManager notificationManager = getSystemService(NotificationManager.class); - notificationManager.createNotificationChannel(channel); - } - private PendingIntent getPendingIntent(Context context, int requestCode, int flags) { Intent intent = new Intent(context, MainActivity.class); intent.setAction("OPEN_ACTIVITY"); From 48c3bec004acf6e757a5e0222d926ee66cd7b77b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=82=8D=E3=82=80=E3=81=AD=E3=81=93?= Date: Thu, 11 Jul 2024 15:03:13 +0900 Subject: [PATCH 14/72] =?UTF-8?q?=E6=A8=A9=E9=99=90=E7=A2=BA=E8=AA=8D?= =?UTF-8?q?=E5=87=A6=E7=90=86=E3=82=92=E7=B5=B1=E4=B8=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/example/childguard/TestService.java | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/com/example/childguard/TestService.java b/app/src/main/java/com/example/childguard/TestService.java index cfc0330..7b36e45 100644 --- a/app/src/main/java/com/example/childguard/TestService.java +++ b/app/src/main/java/com/example/childguard/TestService.java @@ -24,6 +24,7 @@ import android.util.Log; import androidx.annotation.Nullable; import androidx.core.app.ActivityCompat; import androidx.core.app.NotificationCompat; +import androidx.core.app.NotificationManagerCompat; import com.google.firebase.firestore.DocumentReference; import com.google.firebase.firestore.FirebaseFirestore; @@ -42,7 +43,6 @@ public class TestService extends Service { // ユーザーID private String userId = null; - @Override public int onStartCommand(Intent intent, int flags, int startId) { //共有プリファレンス全体の準備 @@ -88,6 +88,15 @@ public class TestService extends Service { notificationManager.createNotificationChannel(channel); } + /** + * 通知が許可がされているかどうかを確認 + * @return 通知の許可の有無 true: 許可されている false: 許可されていない + */ + private boolean isNotificationEnabled() { + NotificationManagerCompat notificationManagerCompat = NotificationManagerCompat.from(this); + return notificationManagerCompat.areNotificationsEnabled(); + } + private void initNotification(DocumentReference mDocRef) {//サイト上で押されたボタンの管理 // PeriodicTaskManagerのインスタンス化 @@ -143,6 +152,9 @@ public class TestService extends Service { public void Notification(Context context) {//実際に通知を行うメソッド + // 権限の保有を確認 + if (!isNotificationEnabled()) return; + vibrateDevice(); @SuppressLint("NotificationTrampoline") NotificationCompat.Builder builder = new NotificationCompat.Builder(context, CHANNEL_ID) @@ -156,17 +168,13 @@ public class TestService extends Service { NotificationManager notificationManager = context.getSystemService(NotificationManager.class); - if (ActivityCompat.checkSelfPermission(this, android.Manifest.permission.POST_NOTIFICATIONS) != PackageManager.PERMISSION_GRANTED) { - return; - } notificationManager.notify(R.string.app_name, builder.build());//通知の表示 } public void NotificationBluetooth(Context context) {//実際に通知を行うメソッド // 権限の保有を確認 - if (ActivityCompat.checkSelfPermission(this, - android.Manifest.permission.POST_NOTIFICATIONS) != PackageManager.PERMISSION_GRANTED) return; + if (!isNotificationEnabled()) return; vibrateDevice(); From e53fdb04b963c5b4a168cb035d0903a8319d70ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=82=8D=E3=82=80=E3=81=AD=E3=81=93?= Date: Thu, 11 Jul 2024 15:05:46 +0900 Subject: [PATCH 15/72] =?UTF-8?q?Warn=E5=AF=BE=E5=87=A6(=E7=9C=9F=E5=81=BD?= =?UTF-8?q?=E5=8F=8D=E8=BB=A2)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/example/childguard/TestService.java | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/com/example/childguard/TestService.java b/app/src/main/java/com/example/childguard/TestService.java index 7b36e45..44cc156 100644 --- a/app/src/main/java/com/example/childguard/TestService.java +++ b/app/src/main/java/com/example/childguard/TestService.java @@ -12,8 +12,6 @@ import android.content.Intent; import android.content.IntentFilter; import android.content.SharedPreferences; import android.content.pm.PackageManager; -import android.graphics.Color; -import android.os.Build; import android.os.Handler; import android.os.IBinder; import android.os.VibrationEffect; @@ -29,9 +27,6 @@ import androidx.core.app.NotificationManagerCompat; import com.google.firebase.firestore.DocumentReference; import com.google.firebase.firestore.FirebaseFirestore; -import java.util.HashMap; -import java.util.Map; - public class TestService extends Service { FirebaseFirestore db; DocumentReference mDocRef; @@ -92,9 +87,15 @@ public class TestService extends Service { * 通知が許可がされているかどうかを確認 * @return 通知の許可の有無 true: 許可されている false: 許可されていない */ - private boolean isNotificationEnabled() { + private boolean isNotNotificationEnabled() { NotificationManagerCompat notificationManagerCompat = NotificationManagerCompat.from(this); - return notificationManagerCompat.areNotificationsEnabled(); + if (!notificationManagerCompat.areNotificationsEnabled()) { + Log.d(TAG, "通知が許可されていません"); + return true; + } else { + Log.d(TAG, "通知が許可されています"); + return false; + } } private void initNotification(DocumentReference mDocRef) {//サイト上で押されたボタンの管理 @@ -153,7 +154,7 @@ public class TestService extends Service { public void Notification(Context context) {//実際に通知を行うメソッド // 権限の保有を確認 - if (!isNotificationEnabled()) return; + if (isNotNotificationEnabled()) return; vibrateDevice(); @@ -174,7 +175,7 @@ public class TestService extends Service { public void NotificationBluetooth(Context context) {//実際に通知を行うメソッド // 権限の保有を確認 - if (!isNotificationEnabled()) return; + if (isNotNotificationEnabled()) return; vibrateDevice(); From 131fdf7d874c450fba72ea7c92226f5103cd515c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=82=8D=E3=82=80=E3=81=AD=E3=81=93?= Date: Thu, 11 Jul 2024 15:05:56 +0900 Subject: [PATCH 16/72] =?UTF-8?q?JavaDoc=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/com/example/childguard/TestService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/com/example/childguard/TestService.java b/app/src/main/java/com/example/childguard/TestService.java index 44cc156..11614a4 100644 --- a/app/src/main/java/com/example/childguard/TestService.java +++ b/app/src/main/java/com/example/childguard/TestService.java @@ -85,7 +85,7 @@ public class TestService extends Service { /** * 通知が許可がされているかどうかを確認 - * @return 通知の許可の有無 true: 許可されている false: 許可されていない + * @return 通知の許可の有無 true: 許可されていない false: 許可されている */ private boolean isNotNotificationEnabled() { NotificationManagerCompat notificationManagerCompat = NotificationManagerCompat.from(this); From 1d01e217b61af5431e2466440043607b239c3c9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=82=8D=E3=82=80=E3=81=AD=E3=81=93?= Date: Thu, 11 Jul 2024 15:06:24 +0900 Subject: [PATCH 17/72] =?UTF-8?q?JavaDoc=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/com/example/childguard/TestService.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/app/src/main/java/com/example/childguard/TestService.java b/app/src/main/java/com/example/childguard/TestService.java index 11614a4..337c98d 100644 --- a/app/src/main/java/com/example/childguard/TestService.java +++ b/app/src/main/java/com/example/childguard/TestService.java @@ -138,6 +138,13 @@ public class TestService extends Service { Log.d(TAG, "DocumentSnapshot successfully updated!")).addOnFailureListener(e -> Log.w(TAG, "Error updating document", e)); } + /** + * 通知をタップしたときにアプリを起動するPendingIntentを取得 + * @param context コンテキスト + * @param requestCode リクエストコード + * @param flags フラグ + * @return PendingIntent + */ private PendingIntent getPendingIntent(Context context, int requestCode, int flags) { Intent intent = new Intent(context, MainActivity.class); intent.setAction("OPEN_ACTIVITY"); From 712d33d607b03c64833689daf184a999cb60cdad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=82=8D=E3=82=80=E3=81=AD=E3=81=93?= Date: Thu, 11 Jul 2024 15:06:30 +0900 Subject: [PATCH 18/72] =?UTF-8?q?JavaDoc=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/com/example/childguard/TestService.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/src/main/java/com/example/childguard/TestService.java b/app/src/main/java/com/example/childguard/TestService.java index 337c98d..8db0f4d 100644 --- a/app/src/main/java/com/example/childguard/TestService.java +++ b/app/src/main/java/com/example/childguard/TestService.java @@ -151,6 +151,9 @@ public class TestService extends Service { return PendingIntent.getActivity(context, requestCode, intent, flags | PendingIntent.FLAG_IMMUTABLE); } + /** + * デバイスをバイブレーションさせる + */ private void vibrateDevice() { Vibrator vibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE); if (vibrator.hasVibrator()) { From 2b7b8b3e9d29d5c1e1135c98283996047be3dd4f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=82=8D=E3=82=80=E3=81=AD=E3=81=93?= Date: Thu, 11 Jul 2024 15:12:06 +0900 Subject: [PATCH 19/72] =?UTF-8?q?Bluetooth=E3=81=AE=E6=A8=A9=E9=99=90?= =?UTF-8?q?=E7=A2=BA=E8=AA=8D=E3=82=92=E9=9A=94=E9=9B=A2,=20=E3=83=A1?= =?UTF-8?q?=E3=82=BD=E3=83=83=E3=83=89=E6=94=B9=E5=90=8D=E3=81=AA=E3=81=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/example/childguard/TestService.java | 45 ++++++++++++------- 1 file changed, 29 insertions(+), 16 deletions(-) diff --git a/app/src/main/java/com/example/childguard/TestService.java b/app/src/main/java/com/example/childguard/TestService.java index 8db0f4d..1bc50ff 100644 --- a/app/src/main/java/com/example/childguard/TestService.java +++ b/app/src/main/java/com/example/childguard/TestService.java @@ -51,7 +51,9 @@ public class TestService extends Service { initNotification(mDocRef);//現在の位置を引数に initNotification()を処理 } - Bluetooth_status(); + if (isNotBluetoothGranted()) return flags; + + registerReceiver(receiver); return flags; } @@ -98,6 +100,32 @@ public class TestService extends Service { } } + /** + * Bluetoothの権限が許可されているかどうかを確認 + * @return Bluetoothの権限の有無 true: 許可されていない false: 許可されている + */ + private boolean isNotBluetoothGranted() { + if (ActivityCompat.checkSelfPermission(this, android.Manifest.permission.BLUETOOTH_CONNECT) != PackageManager.PERMISSION_GRANTED) { + Log.d(TAG, "Bluetoothの権限が許可されていません"); + return true; + } else { + Log.d(TAG, "Bluetoothの権限が許可されています"); + return false; + } + } + + /** + * ブロードキャストレシーバーを登録 + * @param receiver ブロードキャストレシーバー + */ + public void registerReceiver(BroadcastReceiver receiver) { + IntentFilter intentFilter = new IntentFilter(); + intentFilter.addAction(BluetoothDevice.ACTION_ACL_CONNECTED); + intentFilter.addAction(BluetoothDevice.ACTION_ACL_DISCONNECTED); + + registerReceiver(receiver, intentFilter); + } + private void initNotification(DocumentReference mDocRef) {//サイト上で押されたボタンの管理 // PeriodicTaskManagerのインスタンス化 @@ -205,21 +233,6 @@ public class TestService extends Service { } - public void Bluetooth_status() { - IntentFilter intentFilter = new IntentFilter(); - intentFilter.addAction(BluetoothDevice.ACTION_ACL_CONNECTED); - intentFilter.addAction(BluetoothDevice.ACTION_ACL_DISCONNECTED); - - if (ActivityCompat.checkSelfPermission(this, android.Manifest.permission.BLUETOOTH_CONNECT) != PackageManager.PERMISSION_GRANTED) { - Log.d("BT", "No permission to connect bluetooth devices"); - return; - } else { - Log.d("BT", "Permission to connect bluetooth devices granted"); - } - registerReceiver(receiver, intentFilter); - } - - private final BroadcastReceiver receiver = new BroadcastReceiver() { From 02f2c36735ea69fcc17ecfe43a15b180da7671e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=82=8D=E3=82=80=E3=81=AD=E3=81=93?= Date: Thu, 11 Jul 2024 15:15:49 +0900 Subject: [PATCH 20/72] =?UTF-8?q?=E5=89=8A=E9=99=A4=E6=BC=8F=E3=82=8C?= =?UTF-8?q?=E3=82=B3=E3=83=A1=E3=83=B3=E3=83=88=E5=89=8A=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/com/example/childguard/TestService.java | 1 - 1 file changed, 1 deletion(-) diff --git a/app/src/main/java/com/example/childguard/TestService.java b/app/src/main/java/com/example/childguard/TestService.java index 1bc50ff..908a70b 100644 --- a/app/src/main/java/com/example/childguard/TestService.java +++ b/app/src/main/java/com/example/childguard/TestService.java @@ -226,7 +226,6 @@ public class TestService extends Service { .setPriority(NotificationCompat.PRIORITY_HIGH) // プライオリティを高く設定 .setVisibility(NotificationCompat.VISIBILITY_PUBLIC); // ロック画面に表示する - // 通知チャンネルの作成 NotificationManager notificationManager = context.getSystemService(NotificationManager.class); notificationManager.notify(R.string.app_name, builder.build());//通知の表示 From fd7826af16afe9730d59b6b5ec42e6613536bb8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=82=8D=E3=82=80=E3=81=AD=E3=81=93?= Date: Thu, 11 Jul 2024 15:16:03 +0900 Subject: [PATCH 21/72] =?UTF-8?q?=E4=B8=8D=E8=A6=81=E3=81=AASuppress?= =?UTF-8?q?=E3=82=92=E5=89=8A=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/com/example/childguard/TestService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/com/example/childguard/TestService.java b/app/src/main/java/com/example/childguard/TestService.java index 908a70b..657e775 100644 --- a/app/src/main/java/com/example/childguard/TestService.java +++ b/app/src/main/java/com/example/childguard/TestService.java @@ -196,7 +196,7 @@ public class TestService extends Service { vibrateDevice(); - @SuppressLint("NotificationTrampoline") NotificationCompat.Builder builder = new NotificationCompat.Builder(context, CHANNEL_ID) + NotificationCompat.Builder builder = new NotificationCompat.Builder(context, CHANNEL_ID) .setSmallIcon(android.R.drawable.ic_menu_info_details) .setContentTitle("子供の置き去りをしていませんか?")//通知のタイトル .setContentText("第三者からの通報が行われました。")//通知の本文 From 40c84f40417218253ab343dba4726576129ca615 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=82=8D=E3=82=80=E3=81=AD=E3=81=93?= Date: Thu, 11 Jul 2024 15:24:02 +0900 Subject: [PATCH 22/72] =?UTF-8?q?WIP=20=E9=80=9A=E7=9F=A5=E4=BD=9C?= =?UTF-8?q?=E6=88=90=E5=87=A6=E7=90=86=E3=82=92=E7=B5=B1=E4=B8=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/example/childguard/TestService.java | 51 ++++++++++--------- 1 file changed, 26 insertions(+), 25 deletions(-) diff --git a/app/src/main/java/com/example/childguard/TestService.java b/app/src/main/java/com/example/childguard/TestService.java index 657e775..8d639e0 100644 --- a/app/src/main/java/com/example/childguard/TestService.java +++ b/app/src/main/java/com/example/childguard/TestService.java @@ -28,12 +28,35 @@ import com.google.firebase.firestore.DocumentReference; import com.google.firebase.firestore.FirebaseFirestore; public class TestService extends Service { + + public static class NotificationContent { + private final String title; + private final String description; + + public NotificationContent(String title, String description) { + this.title = title; + this.description = description; + } + + public String getTitle() { + return title; + } + + public String getDescription() { + return description; + } + } + FirebaseFirestore db; DocumentReference mDocRef; public static final String TAG = "InspirationQuote"; private static final String CHANNEL_ID = "child_guard_emergency"; private static final int REQUEST_CODE = 100; + private static final NotificationContent REPORTED_NOTIFICATION = + new NotificationContent("子供の置き去りをしていませんか?", "第三者からの通報が行われました。"); + private static final NotificationContent BLUETOOTH_NOTIFICATION = + new NotificationContent("子供の置き去りをしていませんか?", "Bluetoothと車の切断から5分が経過しました"); // ユーザーID private String userId = null; @@ -189,7 +212,7 @@ public class TestService extends Service { } } - public void Notification(Context context) {//実際に通知を行うメソッド + public void Notification(Context context, NotificationContent content) {//通知を行うメソッド // 権限の保有を確認 if (isNotNotificationEnabled()) return; @@ -198,8 +221,8 @@ public class TestService extends Service { NotificationCompat.Builder builder = new NotificationCompat.Builder(context, CHANNEL_ID) .setSmallIcon(android.R.drawable.ic_menu_info_details) - .setContentTitle("子供の置き去りをしていませんか?")//通知のタイトル - .setContentText("第三者からの通報が行われました。")//通知の本文 + .setContentTitle(content.getTitle())//通知のタイトル + .setContentText(content.getDescription())//通知の内容 .setContentIntent(getPendingIntent(context, REQUEST_CODE, 0))//通知をタップするとActivityへ移動する .setAutoCancel(true)//通知をタップすると削除する .setPriority(NotificationCompat.PRIORITY_HIGH) // プライオリティを高く設定 @@ -210,28 +233,6 @@ public class TestService extends Service { notificationManager.notify(R.string.app_name, builder.build());//通知の表示 } - public void NotificationBluetooth(Context context) {//実際に通知を行うメソッド - - // 権限の保有を確認 - if (isNotNotificationEnabled()) return; - - vibrateDevice(); - - NotificationCompat.Builder builder = new NotificationCompat.Builder(context, CHANNEL_ID) - .setSmallIcon(android.R.drawable.ic_menu_info_details) - .setContentTitle("子供の置き去りをしていませんか?")//通知のタイトル - .setContentText("Bluetoothと車の切断から5分が経過しました")//通知の本文 - .setContentIntent(getPendingIntent(context, REQUEST_CODE, 0))//通知をタップするとActivityへ移動する - .setAutoCancel(true)//通知をタップすると削除する - .setPriority(NotificationCompat.PRIORITY_HIGH) // プライオリティを高く設定 - .setVisibility(NotificationCompat.VISIBILITY_PUBLIC); // ロック画面に表示する - - NotificationManager notificationManager = context.getSystemService(NotificationManager.class); - - notificationManager.notify(R.string.app_name, builder.build());//通知の表示 - } - - private final BroadcastReceiver receiver = new BroadcastReceiver() { From 8164ce8bd653e05280eab1badcde6a19d374d17c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=82=8D=E3=82=80=E3=81=AD=E3=81=93?= Date: Thu, 11 Jul 2024 15:26:19 +0900 Subject: [PATCH 23/72] =?UTF-8?q?=E5=91=BC=E3=81=B3=E5=87=BA=E3=81=97?= =?UTF-8?q?=E7=AE=87=E6=89=80=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/com/example/childguard/TestService.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/example/childguard/TestService.java b/app/src/main/java/com/example/childguard/TestService.java index 8d639e0..590c0e4 100644 --- a/app/src/main/java/com/example/childguard/TestService.java +++ b/app/src/main/java/com/example/childguard/TestService.java @@ -171,7 +171,7 @@ public class TestService extends Service { if (documentSnapshot.getBoolean("isReported")) { //ここスタート(リサイクル) ResetReported();// ResetReported();を処理→FireBaseのisReportedをfalseにする - Notification(getApplicationContext());//通知を行うメソッド + Notification(getApplicationContext(), REPORTED_NOTIFICATION);//通知を行うメソッド } } else {//isReportedがfalse=サイト上で降車状態のとき ResetReported();//ResetReported();を処理→FireBaseのisReportedをfalseにする @@ -286,7 +286,7 @@ public class TestService extends Service { @Override public void run() { if (BluetoothDevice.ACTION_ACL_DISCONNECTED.equals(action) && !isInCar) {//その後bluetoothを再接続したり降車状態になったりしていない=置き去りが発生した可能性大 - NotificationBluetooth(getApplicationContext());//通知を行うメソッド + Notification(context, BLUETOOTH_NOTIFICATION); } } From f4f6dc0107eeec94438a197eec66a560c71e6869 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=82=8D=E3=82=80=E3=81=AD=E3=81=93?= Date: Thu, 11 Jul 2024 15:26:52 +0900 Subject: [PATCH 24/72] =?UTF-8?q?=E5=90=8D=E7=A7=B0=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/com/example/childguard/TestService.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/com/example/childguard/TestService.java b/app/src/main/java/com/example/childguard/TestService.java index 590c0e4..f9ab3ee 100644 --- a/app/src/main/java/com/example/childguard/TestService.java +++ b/app/src/main/java/com/example/childguard/TestService.java @@ -1,6 +1,5 @@ package com.example.childguard; -import android.annotation.SuppressLint; import android.app.NotificationChannel; import android.app.NotificationManager; import android.app.PendingIntent; @@ -170,18 +169,18 @@ public class TestService extends Service { if (isInCar) {//isReportedがtrue=サイト上で乗車状態のとき if (documentSnapshot.getBoolean("isReported")) { //ここスタート(リサイクル) - ResetReported();// ResetReported();を処理→FireBaseのisReportedをfalseにする + resetReported();// ResetReported();を処理→FireBaseのisReportedをfalseにする Notification(getApplicationContext(), REPORTED_NOTIFICATION);//通知を行うメソッド } } else {//isReportedがfalse=サイト上で降車状態のとき - ResetReported();//ResetReported();を処理→FireBaseのisReportedをfalseにする + resetReported();//ResetReported();を処理→FireBaseのisReportedをfalseにする } } }); } - public void ResetReported() {//FireBaseのisReportedをfalseに初期化するメソッド + public void resetReported() {//FireBaseのisReportedをfalseに初期化するメソッド db = FirebaseFirestore.getInstance();//Firebaseとの紐づけ DocumentReference isReported = db.collection("status").document(this.userId); //isReportedをfalseに更新 From d53691236f381fd8ed727a9631ef5b9debc1168c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=82=8D=E3=82=80=E3=81=AD=E3=81=93?= Date: Thu, 11 Jul 2024 15:33:51 +0900 Subject: [PATCH 25/72] =?UTF-8?q?=E5=BF=85=E8=A6=81=E3=81=AA=E3=83=87?= =?UTF-8?q?=E3=83=BC=E3=82=BF=E3=81=8C=E3=81=AA=E3=81=84=E5=A0=B4=E5=90=88?= =?UTF-8?q?=E3=81=AA=E3=81=A9=E3=81=AB=E3=81=A7=E3=81=8D=E3=82=8B=E3=81=A0?= =?UTF-8?q?=E3=81=91=E6=97=A9=E3=81=8F=E5=87=A6=E7=90=86=E3=82=92=E4=B8=AD?= =?UTF-8?q?=E6=96=AD=E3=81=99=E3=82=8B=E3=82=88=E3=81=86=E3=81=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/example/childguard/TestService.java | 28 +++++++++++++++++-- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/example/childguard/TestService.java b/app/src/main/java/com/example/childguard/TestService.java index f9ab3ee..453f390 100644 --- a/app/src/main/java/com/example/childguard/TestService.java +++ b/app/src/main/java/com/example/childguard/TestService.java @@ -239,10 +239,33 @@ public class TestService extends Service { @Override public void onReceive(Context context, Intent intent) { + + // 処理対象か確認 ---------------------------------------- + BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE); + if (device == null) { + Log.d("BT", "No device found"); + return; + } + String deviceHardwareAddress = device.getAddress(); // MAC address + if (deviceHardwareAddress == null) { + Log.d("BT", "No device address found"); + return; + } + String registeredId = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).getString("bluetooth_device_id", null); + if (registeredId == null) { + Log.d("BT_Judge", "No registered device"); + return; + } + if (!registeredId.equals(deviceHardwareAddress)) { + Log.d("BT_Judge", "Not registered device"); + return; + } + // ----------------------------------------------------- + SharedPreferences pref = getSharedPreferences("Bluetooth_situation", MODE_PRIVATE); SharedPreferences.Editor e = pref.edit(); String action = intent.getAction(); // may need to chain this to a recognizing function - BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE); + Boolean isInCar = pref.getBoolean("isInCarPref", false); @@ -250,9 +273,8 @@ public class TestService extends Service { Log.d("BT", "No permission to connect bluetooth devices"); return; } - String deviceHardwareAddress = device.getAddress(); // MAC address - String registeredId = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).getString("bluetooth_device_id", "none"); + if (BluetoothDevice.ACTION_ACL_CONNECTED.equals(action)) { //Do something if connected From 66fdb0455651a515134fe7c3d8d85c3370a2bb9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=82=8D=E3=82=80=E3=81=AD=E3=81=93?= Date: Thu, 11 Jul 2024 15:34:47 +0900 Subject: [PATCH 26/72] =?UTF-8?q?Bluetooth=E6=A8=A9=E9=99=90=E3=81=AE?= =?UTF-8?q?=E3=83=81=E3=82=A7=E3=83=83=E3=82=AF=E3=82=92=E5=89=8A=E9=99=A4?= =?UTF-8?q?(=E6=97=A2=E3=81=AB=E3=83=81=E3=82=A7=E3=83=83=E3=82=AF?= =?UTF-8?q?=E3=81=95=E3=82=8C=E3=81=A6=E3=81=84=E3=82=8B=E3=81=9F=E3=82=81?= =?UTF-8?q?)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/com/example/childguard/TestService.java | 8 -------- 1 file changed, 8 deletions(-) diff --git a/app/src/main/java/com/example/childguard/TestService.java b/app/src/main/java/com/example/childguard/TestService.java index 453f390..48f1e54 100644 --- a/app/src/main/java/com/example/childguard/TestService.java +++ b/app/src/main/java/com/example/childguard/TestService.java @@ -268,14 +268,6 @@ public class TestService extends Service { Boolean isInCar = pref.getBoolean("isInCarPref", false); - - if (ActivityCompat.checkSelfPermission(context, android.Manifest.permission.BLUETOOTH_CONNECT) != PackageManager.PERMISSION_GRANTED) { - Log.d("BT", "No permission to connect bluetooth devices"); - return; - } - - - if (BluetoothDevice.ACTION_ACL_CONNECTED.equals(action)) { //Do something if connected //Bluetoothデバイスが接続されたときの処理 From fb1faa6d56f3e67664be2e2c1597f29654dff07e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=82=8D=E3=82=80=E3=81=AD=E3=81=93?= Date: Thu, 11 Jul 2024 15:35:00 +0900 Subject: [PATCH 27/72] =?UTF-8?q?=E3=83=97=E3=83=AA=E3=83=9F=E3=83=86?= =?UTF-8?q?=E3=82=A3=E3=83=96=E5=9E=8B=E3=81=AB=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/com/example/childguard/TestService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/com/example/childguard/TestService.java b/app/src/main/java/com/example/childguard/TestService.java index 48f1e54..2cab77f 100644 --- a/app/src/main/java/com/example/childguard/TestService.java +++ b/app/src/main/java/com/example/childguard/TestService.java @@ -266,7 +266,7 @@ public class TestService extends Service { SharedPreferences.Editor e = pref.edit(); String action = intent.getAction(); // may need to chain this to a recognizing function - Boolean isInCar = pref.getBoolean("isInCarPref", false); + boolean isInCar = pref.getBoolean("isInCarPref", false); if (BluetoothDevice.ACTION_ACL_CONNECTED.equals(action)) { //Do something if connected From f4e3db81585540b8a5932a894da07519de44cc4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=82=8D=E3=82=80=E3=81=AD=E3=81=93?= Date: Thu, 11 Jul 2024 15:36:57 +0900 Subject: [PATCH 28/72] =?UTF-8?q?=E8=A8=AD=E5=AE=9A=E3=81=97=E3=81=A6?= =?UTF-8?q?=E3=81=84=E3=82=8B=E3=81=A0=E3=81=91=E3=81=A7=E6=9C=AA=E4=BD=BF?= =?UTF-8?q?=E7=94=A8=E3=81=AE=E5=87=A6=E7=90=86=E3=82=92=E5=89=8A=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/com/example/childguard/TestService.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/app/src/main/java/com/example/childguard/TestService.java b/app/src/main/java/com/example/childguard/TestService.java index 2cab77f..772ad36 100644 --- a/app/src/main/java/com/example/childguard/TestService.java +++ b/app/src/main/java/com/example/childguard/TestService.java @@ -279,12 +279,10 @@ public class TestService extends Service { if (deviceHardwareAddress.equals(registeredId)) { //登録済みのデバイスだったときの処理 Log.d("BT_Judge", "登録済み"); - e.putBoolean("connection_status", true); } else { //登録していないデバイスだったときの処理 Log.d("BT_Judge", "未登録"); - e.putBoolean("connection_status", false); } e.apply(); From 3692e0cbd3d5473b2bda06eb0d8c36d5a4a29262 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=82=8D=E3=82=80=E3=81=AD=E3=81=93?= Date: Thu, 11 Jul 2024 15:37:50 +0900 Subject: [PATCH 29/72] =?UTF-8?q?=E4=B8=8D=E8=A6=81=E3=81=AA=E5=87=A6?= =?UTF-8?q?=E7=90=86=E3=82=92=E5=89=8A=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/example/childguard/TestService.java | 21 +------------------ 1 file changed, 1 insertion(+), 20 deletions(-) diff --git a/app/src/main/java/com/example/childguard/TestService.java b/app/src/main/java/com/example/childguard/TestService.java index 772ad36..f0b22dc 100644 --- a/app/src/main/java/com/example/childguard/TestService.java +++ b/app/src/main/java/com/example/childguard/TestService.java @@ -267,26 +267,7 @@ public class TestService extends Service { String action = intent.getAction(); // may need to chain this to a recognizing function boolean isInCar = pref.getBoolean("isInCarPref", false); - - if (BluetoothDevice.ACTION_ACL_CONNECTED.equals(action)) { - //Do something if connected - //Bluetoothデバイスが接続されたときの処理 - Log.d("BT", "Device connected"); - - - Log.d("BT_Judge", "Registered: " + registeredId); - - if (deviceHardwareAddress.equals(registeredId)) { - //登録済みのデバイスだったときの処理 - Log.d("BT_Judge", "登録済み"); - - } else { - //登録していないデバイスだったときの処理 - Log.d("BT_Judge", "未登録"); - } - e.apply(); - - } else if (BluetoothDevice.ACTION_ACL_DISCONNECTED.equals(action) && !isInCar) {//bluetoothが切断されたときに乗車状態のとき + if (BluetoothDevice.ACTION_ACL_DISCONNECTED.equals(action) && !isInCar) {//bluetoothが切断されたときに乗車状態のとき //Do something if disconnected //デバイスが切断されたときの処理 From 32538a43d96a3c5072affe201369cf688913baf2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=82=8D=E3=82=80=E3=81=AD=E3=81=93?= Date: Thu, 11 Jul 2024 15:38:33 +0900 Subject: [PATCH 30/72] =?UTF-8?q?=E4=B8=8D=E8=A6=81=E3=81=AA=E6=AF=94?= =?UTF-8?q?=E8=BC=83=E3=82=92=E5=89=8A=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/example/childguard/TestService.java | 26 +++++++------------ 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/app/src/main/java/com/example/childguard/TestService.java b/app/src/main/java/com/example/childguard/TestService.java index f0b22dc..654a6bd 100644 --- a/app/src/main/java/com/example/childguard/TestService.java +++ b/app/src/main/java/com/example/childguard/TestService.java @@ -265,27 +265,19 @@ public class TestService extends Service { SharedPreferences pref = getSharedPreferences("Bluetooth_situation", MODE_PRIVATE); SharedPreferences.Editor e = pref.edit(); String action = intent.getAction(); // may need to chain this to a recognizing function - boolean isInCar = pref.getBoolean("isInCarPref", false); if (BluetoothDevice.ACTION_ACL_DISCONNECTED.equals(action) && !isInCar) {//bluetoothが切断されたときに乗車状態のとき - - //Do something if disconnected - //デバイスが切断されたときの処理 - if (deviceHardwareAddress.equals(registeredId)) { - // 5分待機する - Handler handler = new Handler(); - handler.postDelayed(new Runnable() { - @Override - public void run() { - if (BluetoothDevice.ACTION_ACL_DISCONNECTED.equals(action) && !isInCar) {//その後bluetoothを再接続したり降車状態になったりしていない=置き去りが発生した可能性大 - Notification(context, BLUETOOTH_NOTIFICATION); - } + // 5分待機する + Handler handler = new Handler(); + handler.postDelayed(new Runnable() { + @Override + public void run() { + if (BluetoothDevice.ACTION_ACL_DISCONNECTED.equals(action) && !isInCar) {//その後bluetoothを再接続したり降車状態になったりしていない=置き去りが発生した可能性大 + Notification(context, BLUETOOTH_NOTIFICATION); } + } - }, 5 * 60 * 1000); // 5分をミリ秒に変換 - } - } else { - Log.d("BT", "Device disconnected"); + }, 5 * 60 * 1000); // 5分をミリ秒に変換 } } }; From 286c178f7fed081cee60c1af650a6920380423bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=82=8D=E3=82=80=E3=81=AD=E3=81=93?= Date: Thu, 11 Jul 2024 15:39:52 +0900 Subject: [PATCH 31/72] =?UTF-8?q?=E4=B8=8D=E8=A6=81=E3=81=AA=E5=87=A6?= =?UTF-8?q?=E7=90=86=E3=82=92=E5=89=8A=E9=99=A4(=E5=90=8C=E3=81=98?= =?UTF-8?q?=E5=80=A4=E3=82=925=E5=88=86=E5=BE=8C=E3=81=AB=E6=AF=94?= =?UTF-8?q?=E8=BC=83=E3=81=97=E3=81=A6=E3=82=82=E7=B5=90=E6=9E=9C=E3=81=AF?= =?UTF-8?q?=E5=A4=89=E3=82=8F=E3=82=89=E3=81=AA=E3=81=84=E3=81=9F=E3=82=81?= =?UTF-8?q?)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/com/example/childguard/TestService.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/app/src/main/java/com/example/childguard/TestService.java b/app/src/main/java/com/example/childguard/TestService.java index 654a6bd..300a3c1 100644 --- a/app/src/main/java/com/example/childguard/TestService.java +++ b/app/src/main/java/com/example/childguard/TestService.java @@ -272,9 +272,7 @@ public class TestService extends Service { handler.postDelayed(new Runnable() { @Override public void run() { - if (BluetoothDevice.ACTION_ACL_DISCONNECTED.equals(action) && !isInCar) {//その後bluetoothを再接続したり降車状態になったりしていない=置き去りが発生した可能性大 - Notification(context, BLUETOOTH_NOTIFICATION); - } + Notification(context, BLUETOOTH_NOTIFICATION); } }, 5 * 60 * 1000); // 5分をミリ秒に変換 From da545e4a5eff3434b9a0cd46c0fe2315968a5a31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=82=8D=E3=82=80=E3=81=AD=E3=81=93?= Date: Thu, 11 Jul 2024 15:47:02 +0900 Subject: [PATCH 32/72] =?UTF-8?q?5=E5=88=86=E4=BB=A5=E5=86=85=E3=81=AB?= =?UTF-8?q?=E5=86=8D=E6=8E=A5=E7=B6=9A=E3=81=95=E3=82=8C=E3=81=9F=E3=81=A8?= =?UTF-8?q?=E3=81=8D=EF=BC=8C=E9=80=9A=E7=9F=A5=E3=82=92=E3=82=AD=E3=83=A3?= =?UTF-8?q?=E3=83=B3=E3=82=BB=E3=83=AB=E3=81=99=E3=82=8B=E3=82=88=E3=81=86?= =?UTF-8?q?=E3=81=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/example/childguard/TestService.java | 21 ++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/com/example/childguard/TestService.java b/app/src/main/java/com/example/childguard/TestService.java index 300a3c1..b9df826 100644 --- a/app/src/main/java/com/example/childguard/TestService.java +++ b/app/src/main/java/com/example/childguard/TestService.java @@ -28,6 +28,9 @@ import com.google.firebase.firestore.FirebaseFirestore; public class TestService extends Service { + private Handler handler = new Handler(); + private Runnable notificationRunnable; + public static class NotificationContent { private final String title; private final String description; @@ -266,16 +269,24 @@ public class TestService extends Service { SharedPreferences.Editor e = pref.edit(); String action = intent.getAction(); // may need to chain this to a recognizing function boolean isInCar = pref.getBoolean("isInCarPref", false); - if (BluetoothDevice.ACTION_ACL_DISCONNECTED.equals(action) && !isInCar) {//bluetoothが切断されたときに乗車状態のとき - // 5分待機する - Handler handler = new Handler(); - handler.postDelayed(new Runnable() { + if (BluetoothDevice.ACTION_ACL_DISCONNECTED.equals(action) && !isInCar) { + // bluetoothが切断されたときに乗車状態のとき + notificationRunnable = new Runnable() { @Override public void run() { + // 5分経過した時点でも車に乗っていない場合 Notification(context, BLUETOOTH_NOTIFICATION); } + }; - }, 5 * 60 * 1000); // 5分をミリ秒に変換 + handler.postDelayed(notificationRunnable, 5 * 60 * 1000); // 5分をミリ秒に変換 + } else if (BluetoothDevice.ACTION_ACL_CONNECTED.equals(action)) { + // 再接続された場合、通知をキャンセルする + if (notificationRunnable != null) { + handler.removeCallbacks(notificationRunnable); + notificationRunnable = null; + Log.d("BT", "Notification canceled due to reconnection"); + } } } }; From 0a2cabd0af5a47821a070a5df1456c06bc3a3b33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=82=8D=E3=82=80=E3=81=AD=E3=81=93?= Date: Thu, 11 Jul 2024 15:47:14 +0900 Subject: [PATCH 33/72] =?UTF-8?q?=E4=B8=8D=E8=A6=81=E3=81=AA=E3=82=A4?= =?UTF-8?q?=E3=83=B3=E3=82=B9=E3=82=BF=E3=83=B3=E3=82=B9=E3=82=92=E4=BD=9C?= =?UTF-8?q?=E6=88=90=E3=81=97=E3=81=AA=E3=81=84=E3=82=88=E3=81=86=E3=81=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/com/example/childguard/TestService.java | 1 - 1 file changed, 1 deletion(-) diff --git a/app/src/main/java/com/example/childguard/TestService.java b/app/src/main/java/com/example/childguard/TestService.java index b9df826..6b4c307 100644 --- a/app/src/main/java/com/example/childguard/TestService.java +++ b/app/src/main/java/com/example/childguard/TestService.java @@ -266,7 +266,6 @@ public class TestService extends Service { // ----------------------------------------------------- SharedPreferences pref = getSharedPreferences("Bluetooth_situation", MODE_PRIVATE); - SharedPreferences.Editor e = pref.edit(); String action = intent.getAction(); // may need to chain this to a recognizing function boolean isInCar = pref.getBoolean("isInCarPref", false); if (BluetoothDevice.ACTION_ACL_DISCONNECTED.equals(action) && !isInCar) { From cff730b60a5203926063fe7a6be5c8954a0ab1f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=82=8D=E3=82=80=E3=81=AD=E3=81=93?= Date: Thu, 11 Jul 2024 15:47:24 +0900 Subject: [PATCH 34/72] =?UTF-8?q?=E7=B0=A1=E7=B4=A0=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/com/example/childguard/TestService.java | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/com/example/childguard/TestService.java b/app/src/main/java/com/example/childguard/TestService.java index 6b4c307..25d9e24 100644 --- a/app/src/main/java/com/example/childguard/TestService.java +++ b/app/src/main/java/com/example/childguard/TestService.java @@ -270,12 +270,9 @@ public class TestService extends Service { boolean isInCar = pref.getBoolean("isInCarPref", false); if (BluetoothDevice.ACTION_ACL_DISCONNECTED.equals(action) && !isInCar) { // bluetoothが切断されたときに乗車状態のとき - notificationRunnable = new Runnable() { - @Override - public void run() { - // 5分経過した時点でも車に乗っていない場合 - Notification(context, BLUETOOTH_NOTIFICATION); - } + notificationRunnable = () -> { + // 5分経過した時点でも車に乗っていない場合 + Notification(context, BLUETOOTH_NOTIFICATION); }; handler.postDelayed(notificationRunnable, 5 * 60 * 1000); // 5分をミリ秒に変換 From 1231748f76d72a8171c29395e86f2049b7149dbc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=82=8D=E3=82=80=E3=81=AD=E3=81=93?= Date: Thu, 11 Jul 2024 15:47:51 +0900 Subject: [PATCH 35/72] =?UTF-8?q?=E4=B8=8D=E8=A6=81=E3=81=AA=E3=82=A4?= =?UTF-8?q?=E3=83=B3=E3=82=B9=E3=82=BF=E3=83=B3=E3=82=B9=E3=82=92=E4=BD=9C?= =?UTF-8?q?=E6=88=90=E3=81=97=E3=81=AA=E3=81=84=E3=82=88=E3=81=86=E3=81=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/com/example/childguard/TestService.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/src/main/java/com/example/childguard/TestService.java b/app/src/main/java/com/example/childguard/TestService.java index 25d9e24..1a66e62 100644 --- a/app/src/main/java/com/example/childguard/TestService.java +++ b/app/src/main/java/com/example/childguard/TestService.java @@ -265,9 +265,8 @@ public class TestService extends Service { } // ----------------------------------------------------- - SharedPreferences pref = getSharedPreferences("Bluetooth_situation", MODE_PRIVATE); String action = intent.getAction(); // may need to chain this to a recognizing function - boolean isInCar = pref.getBoolean("isInCarPref", false); + boolean isInCar = getSharedPreferences("Bluetooth_situation", MODE_PRIVATE).getBoolean("isInCarPref", false); if (BluetoothDevice.ACTION_ACL_DISCONNECTED.equals(action) && !isInCar) { // bluetoothが切断されたときに乗車状態のとき notificationRunnable = () -> { From e19ee4d623e047d84b03c9616e3ea17c82c0e518 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=82=8D=E3=82=80=E3=81=AD=E3=81=93?= Date: Thu, 11 Jul 2024 15:48:06 +0900 Subject: [PATCH 36/72] =?UTF-8?q?=E6=95=B4=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/com/example/childguard/TestService.java | 7 ------- 1 file changed, 7 deletions(-) diff --git a/app/src/main/java/com/example/childguard/TestService.java b/app/src/main/java/com/example/childguard/TestService.java index 1a66e62..0b4817f 100644 --- a/app/src/main/java/com/example/childguard/TestService.java +++ b/app/src/main/java/com/example/childguard/TestService.java @@ -236,13 +236,8 @@ public class TestService extends Service { } private final BroadcastReceiver receiver = new BroadcastReceiver() { - - - //PreferenceManager.getDefaultSharedPreferences("myPreferences",Context.MODE_PRIVATE); - @Override public void onReceive(Context context, Intent intent) { - // 処理対象か確認 ---------------------------------------- BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE); if (device == null) { @@ -264,7 +259,6 @@ public class TestService extends Service { return; } // ----------------------------------------------------- - String action = intent.getAction(); // may need to chain this to a recognizing function boolean isInCar = getSharedPreferences("Bluetooth_situation", MODE_PRIVATE).getBoolean("isInCarPref", false); if (BluetoothDevice.ACTION_ACL_DISCONNECTED.equals(action) && !isInCar) { @@ -273,7 +267,6 @@ public class TestService extends Service { // 5分経過した時点でも車に乗っていない場合 Notification(context, BLUETOOTH_NOTIFICATION); }; - handler.postDelayed(notificationRunnable, 5 * 60 * 1000); // 5分をミリ秒に変換 } else if (BluetoothDevice.ACTION_ACL_CONNECTED.equals(action)) { // 再接続された場合、通知をキャンセルする From 4f808579c50e4cb5d25ba04736a5186f7e26f217 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=82=8D=E3=82=80=E3=81=AD=E3=81=93?= Date: Thu, 11 Jul 2024 15:49:02 +0900 Subject: [PATCH 37/72] =?UTF-8?q?=E4=B8=8D=E8=A6=81=E3=81=AA=E5=BC=95?= =?UTF-8?q?=E6=95=B0=E3=81=AF=E5=9B=BA=E5=AE=9A=E5=80=A4=E3=82=92=E7=94=A8?= =?UTF-8?q?=E3=81=84=E3=82=8B=E3=82=88=E3=81=86=E3=81=AB=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/com/example/childguard/TestService.java | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/com/example/childguard/TestService.java b/app/src/main/java/com/example/childguard/TestService.java index 0b4817f..2f47448 100644 --- a/app/src/main/java/com/example/childguard/TestService.java +++ b/app/src/main/java/com/example/childguard/TestService.java @@ -193,15 +193,14 @@ public class TestService extends Service { /** * 通知をタップしたときにアプリを起動するPendingIntentを取得 + * * @param context コンテキスト - * @param requestCode リクエストコード - * @param flags フラグ * @return PendingIntent */ - private PendingIntent getPendingIntent(Context context, int requestCode, int flags) { + private PendingIntent getPendingIntent(Context context) { Intent intent = new Intent(context, MainActivity.class); intent.setAction("OPEN_ACTIVITY"); - return PendingIntent.getActivity(context, requestCode, intent, flags | PendingIntent.FLAG_IMMUTABLE); + return PendingIntent.getActivity(context, TestService.REQUEST_CODE, intent, 0 | PendingIntent.FLAG_IMMUTABLE); } /** @@ -225,7 +224,7 @@ public class TestService extends Service { .setSmallIcon(android.R.drawable.ic_menu_info_details) .setContentTitle(content.getTitle())//通知のタイトル .setContentText(content.getDescription())//通知の内容 - .setContentIntent(getPendingIntent(context, REQUEST_CODE, 0))//通知をタップするとActivityへ移動する + .setContentIntent(getPendingIntent(context))//通知をタップするとActivityへ移動する .setAutoCancel(true)//通知をタップすると削除する .setPriority(NotificationCompat.PRIORITY_HIGH) // プライオリティを高く設定 .setVisibility(NotificationCompat.VISIBILITY_PUBLIC); // ロック画面に表示する From 523f1019094bb427587d9304ba7b353c600d256c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=82=8D=E3=82=80=E3=81=AD=E3=81=93?= Date: Thu, 11 Jul 2024 15:49:42 +0900 Subject: [PATCH 38/72] =?UTF-8?q?=E3=83=AA=E3=83=8D=E3=83=BC=E3=83=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/com/example/childguard/TestService.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/example/childguard/TestService.java b/app/src/main/java/com/example/childguard/TestService.java index 2f47448..1d2d53f 100644 --- a/app/src/main/java/com/example/childguard/TestService.java +++ b/app/src/main/java/com/example/childguard/TestService.java @@ -173,7 +173,7 @@ public class TestService extends Service { if (documentSnapshot.getBoolean("isReported")) { //ここスタート(リサイクル) resetReported();// ResetReported();を処理→FireBaseのisReportedをfalseにする - Notification(getApplicationContext(), REPORTED_NOTIFICATION);//通知を行うメソッド + sendNotification(getApplicationContext(), REPORTED_NOTIFICATION);//通知を行うメソッド } } else {//isReportedがfalse=サイト上で降車状態のとき resetReported();//ResetReported();を処理→FireBaseのisReportedをfalseにする @@ -213,7 +213,7 @@ public class TestService extends Service { } } - public void Notification(Context context, NotificationContent content) {//通知を行うメソッド + public void sendNotification(Context context, NotificationContent content) {//通知を行うメソッド // 権限の保有を確認 if (isNotNotificationEnabled()) return; @@ -264,7 +264,7 @@ public class TestService extends Service { // bluetoothが切断されたときに乗車状態のとき notificationRunnable = () -> { // 5分経過した時点でも車に乗っていない場合 - Notification(context, BLUETOOTH_NOTIFICATION); + sendNotification(context, BLUETOOTH_NOTIFICATION); }; handler.postDelayed(notificationRunnable, 5 * 60 * 1000); // 5分をミリ秒に変換 } else if (BluetoothDevice.ACTION_ACL_CONNECTED.equals(action)) { From f0e99893380662498e1fc119fb84fe884ebe0747 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=82=8D=E3=82=80=E3=81=AD=E3=81=93?= Date: Thu, 11 Jul 2024 15:49:55 +0900 Subject: [PATCH 39/72] Simplify --- app/src/main/java/com/example/childguard/TestService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/com/example/childguard/TestService.java b/app/src/main/java/com/example/childguard/TestService.java index 1d2d53f..a0101b7 100644 --- a/app/src/main/java/com/example/childguard/TestService.java +++ b/app/src/main/java/com/example/childguard/TestService.java @@ -200,7 +200,7 @@ public class TestService extends Service { private PendingIntent getPendingIntent(Context context) { Intent intent = new Intent(context, MainActivity.class); intent.setAction("OPEN_ACTIVITY"); - return PendingIntent.getActivity(context, TestService.REQUEST_CODE, intent, 0 | PendingIntent.FLAG_IMMUTABLE); + return PendingIntent.getActivity(context, TestService.REQUEST_CODE, intent, PendingIntent.FLAG_IMMUTABLE); } /** From 2fd61f5d551e9408f75d2ff90b9f858540e2f64c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=82=8D=E3=82=80=E3=81=AD=E3=81=93?= Date: Thu, 11 Jul 2024 15:50:13 +0900 Subject: [PATCH 40/72] =?UTF-8?q?final=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/com/example/childguard/TestService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/com/example/childguard/TestService.java b/app/src/main/java/com/example/childguard/TestService.java index a0101b7..6dd855a 100644 --- a/app/src/main/java/com/example/childguard/TestService.java +++ b/app/src/main/java/com/example/childguard/TestService.java @@ -28,7 +28,7 @@ import com.google.firebase.firestore.FirebaseFirestore; public class TestService extends Service { - private Handler handler = new Handler(); + private final Handler handler = new Handler(); private Runnable notificationRunnable; public static class NotificationContent { From dfb6649a3b59017869fbc86822eb95c9dceb9ae1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=82=8D=E3=82=80=E3=81=AD=E3=81=93?= Date: Thu, 11 Jul 2024 15:55:34 +0900 Subject: [PATCH 41/72] =?UTF-8?q?WIP=20=E3=83=AA=E3=83=95=E3=82=A1?= =?UTF-8?q?=E3=82=AF=E3=82=BF=E3=83=AA=E3=83=B3=E3=82=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/example/childguard/TestService.java | 58 +++++++++++-------- 1 file changed, 34 insertions(+), 24 deletions(-) diff --git a/app/src/main/java/com/example/childguard/TestService.java b/app/src/main/java/com/example/childguard/TestService.java index 6dd855a..0af0418 100644 --- a/app/src/main/java/com/example/childguard/TestService.java +++ b/app/src/main/java/com/example/childguard/TestService.java @@ -24,6 +24,7 @@ import androidx.core.app.NotificationCompat; import androidx.core.app.NotificationManagerCompat; import com.google.firebase.firestore.DocumentReference; +import com.google.firebase.firestore.DocumentSnapshot; import com.google.firebase.firestore.FirebaseFirestore; public class TestService extends Service { @@ -151,35 +152,44 @@ public class TestService extends Service { registerReceiver(receiver, intentFilter); } - private void initNotification(DocumentReference mDocRef) {//サイト上で押されたボタンの管理 - // PeriodicTaskManagerのインスタンス化 + private void initNotification(DocumentReference mDocRef) { + // Initialize the PeriodicTaskManager + // (Assuming it's done elsewhere as it's not shown in the original code) - // 共有プリファレンス全体の準備 + // Prepare SharedPreferences SharedPreferences sharedPreferences = getSharedPreferences("app_situation", MODE_PRIVATE); - //車の乗り降りを管理するtrue=乗車、false=降車 - //exists()でdocumentSnapshotの中のファイルの存在の確認 - mDocRef.addSnapshotListener((documentSnapshot, e) -> { - Log.d("nt", "イベント開始"); - //共有プリファレンス 書き込みの準備 - SharedPreferences.Editor E = sharedPreferences.edit(); - //車の乗り降りを管理するtrue=乗車、false=降車 - if (documentSnapshot.exists()) {//exists()でdocumentSnapshotの中のファイルの存在の確認 - Boolean isInCar = sharedPreferences.getBoolean("isInCarPref", false);//現在の乗降状態を保存する共有プリファレンス - E.putBoolean("isInCarPref", documentSnapshot.getBoolean("isInCar"));//乗降状態の判定 - E.apply();//確定処理 - Log.d("nt", "レスポンスを検知しました1"); - if (isInCar) {//isReportedがtrue=サイト上で乗車状態のとき - if (documentSnapshot.getBoolean("isReported")) { - //ここスタート(リサイクル) - resetReported();// ResetReported();を処理→FireBaseのisReportedをfalseにする - sendNotification(getApplicationContext(), REPORTED_NOTIFICATION);//通知を行うメソッド - } - } else {//isReportedがfalse=サイト上で降車状態のとき - resetReported();//ResetReported();を処理→FireBaseのisReportedをfalseにする - } + // Add a snapshot listener to the document reference + mDocRef.addSnapshotListener((documentSnapshot, e) -> { + if (e != null) { + Log.w("nt", "Listen failed.", e); + return; } + if (documentSnapshot != null && documentSnapshot.exists()) { + Log.d("nt", "イベント開始"); + + // Handle document snapshot + SharedPreferences.Editor editor = sharedPreferences.edit(); + boolean isInCar = sharedPreferences.getBoolean("isInCarPref", false); + boolean newIsInCarState = Boolean.TRUE.equals(documentSnapshot.getBoolean("isInCar")); + + editor.putBoolean("isInCarPref", newIsInCarState); + editor.apply(); + + Log.d("nt", "レスポンスを検知しました1"); + + if (isInCar) { + if (Boolean.TRUE.equals(documentSnapshot.getBoolean("isReported"))) { + resetReported(); + sendNotification(getApplicationContext(), REPORTED_NOTIFICATION); + } + } else { + resetReported(); + } + } else { + Log.d("nt", "Current data: null"); + } }); } From d2e633b3874822679e11cb893d573fc243644c13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=82=8D=E3=82=80=E3=81=AD=E3=81=93?= Date: Thu, 11 Jul 2024 15:56:46 +0900 Subject: [PATCH 42/72] =?UTF-8?q?=E3=83=AA=E3=83=8D=E3=83=BC=E3=83=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/com/example/childguard/TestService.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/example/childguard/TestService.java b/app/src/main/java/com/example/childguard/TestService.java index 0af0418..3b8c702 100644 --- a/app/src/main/java/com/example/childguard/TestService.java +++ b/app/src/main/java/com/example/childguard/TestService.java @@ -24,7 +24,6 @@ import androidx.core.app.NotificationCompat; import androidx.core.app.NotificationManagerCompat; import com.google.firebase.firestore.DocumentReference; -import com.google.firebase.firestore.DocumentSnapshot; import com.google.firebase.firestore.FirebaseFirestore; public class TestService extends Service { @@ -74,7 +73,7 @@ public class TestService extends Service { return flags; // IDが初期化されていない場合は何もしない } else { mDocRef = FirebaseFirestore.getInstance().document("status/" + this.userId);//現在の位置を取得 - initNotification(mDocRef);//現在の位置を引数に initNotification()を処理 + setSnapshotListener(mDocRef);//現在の位置を引数に initNotification()を処理 } if (isNotBluetoothGranted()) return flags; @@ -152,7 +151,7 @@ public class TestService extends Service { registerReceiver(receiver, intentFilter); } - private void initNotification(DocumentReference mDocRef) { + private void setSnapshotListener(DocumentReference mDocRef) { // Initialize the PeriodicTaskManager // (Assuming it's done elsewhere as it's not shown in the original code) From 36cbb5975a2ba56457b37513f589f306e3e801a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=82=8D=E3=82=80=E3=81=AD=E3=81=93?= Date: Thu, 11 Jul 2024 15:57:30 +0900 Subject: [PATCH 43/72] =?UTF-8?q?=E3=82=B7=E3=83=B3=E3=83=97=E3=83=AB?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/com/example/childguard/TestService.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/src/main/java/com/example/childguard/TestService.java b/app/src/main/java/com/example/childguard/TestService.java index 3b8c702..fd6cc28 100644 --- a/app/src/main/java/com/example/childguard/TestService.java +++ b/app/src/main/java/com/example/childguard/TestService.java @@ -72,8 +72,7 @@ public class TestService extends Service { Log.d("onResume", "ID not initialized."); return flags; // IDが初期化されていない場合は何もしない } else { - mDocRef = FirebaseFirestore.getInstance().document("status/" + this.userId);//現在の位置を取得 - setSnapshotListener(mDocRef);//現在の位置を引数に initNotification()を処理 + setSnapshotListener(FirebaseFirestore.getInstance().document("status/" + this.userId)); } if (isNotBluetoothGranted()) return flags; From a928641410814b9b91f37e4db5934a44af4a8414 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=82=8D=E3=82=80=E3=81=AD=E3=81=93?= Date: Thu, 11 Jul 2024 15:58:59 +0900 Subject: [PATCH 44/72] =?UTF-8?q?=E4=B8=8D=E8=A6=81=E3=81=AA=E3=82=A4?= =?UTF-8?q?=E3=83=B3=E3=82=B9=E3=82=BF=E3=83=B3=E3=82=B9=E3=82=92=E4=BF=9D?= =?UTF-8?q?=E6=8C=81=E3=81=97=E3=81=AA=E3=81=84=E3=82=88=E3=81=86=E3=81=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/com/example/childguard/TestService.java | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/com/example/childguard/TestService.java b/app/src/main/java/com/example/childguard/TestService.java index fd6cc28..eca70f9 100644 --- a/app/src/main/java/com/example/childguard/TestService.java +++ b/app/src/main/java/com/example/childguard/TestService.java @@ -65,18 +65,13 @@ public class TestService extends Service { @Override public int onStartCommand(Intent intent, int flags, int startId) { - //共有プリファレンス全体の準備 - SharedPreferences sharedPreferences = getSharedPreferences("app_situation", MODE_PRIVATE); - this.userId = sharedPreferences.getString("ID", null);//アプリに記録されているIDの取得 - if (this.userId == null) { + if (getSharedPreferences("app_situation", MODE_PRIVATE).getString("ID", null) == null) { Log.d("onResume", "ID not initialized."); return flags; // IDが初期化されていない場合は何もしない - } else { - setSnapshotListener(FirebaseFirestore.getInstance().document("status/" + this.userId)); } + setSnapshotListener(FirebaseFirestore.getInstance().document("status/" + this.userId)); if (isNotBluetoothGranted()) return flags; - registerReceiver(receiver); return flags; } From dc7b45436c3883779ccfb7f880c00b0e66c7760e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=82=8D=E3=82=80=E3=81=AD=E3=81=93?= Date: Thu, 11 Jul 2024 15:59:50 +0900 Subject: [PATCH 45/72] fix --- app/src/main/java/com/example/childguard/TestService.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/src/main/java/com/example/childguard/TestService.java b/app/src/main/java/com/example/childguard/TestService.java index eca70f9..2d9f11d 100644 --- a/app/src/main/java/com/example/childguard/TestService.java +++ b/app/src/main/java/com/example/childguard/TestService.java @@ -65,13 +65,16 @@ public class TestService extends Service { @Override public int onStartCommand(Intent intent, int flags, int startId) { + this.userId = getSharedPreferences("app_situation", MODE_PRIVATE).getString("ID", null); if (getSharedPreferences("app_situation", MODE_PRIVATE).getString("ID", null) == null) { Log.d("onResume", "ID not initialized."); return flags; // IDが初期化されていない場合は何もしない } + setSnapshotListener(FirebaseFirestore.getInstance().document("status/" + this.userId)); if (isNotBluetoothGranted()) return flags; + registerReceiver(receiver); return flags; } From 9cdfc6bc70d8fe8f8c6f8170992a574748eda1a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=82=8D=E3=82=80=E3=81=AD=E3=81=93?= Date: Thu, 11 Jul 2024 16:00:05 +0900 Subject: [PATCH 46/72] =?UTF-8?q?=E3=83=AA=E3=83=95=E3=82=A1=E3=82=AF?= =?UTF-8?q?=E3=82=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/com/example/childguard/TestService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/com/example/childguard/TestService.java b/app/src/main/java/com/example/childguard/TestService.java index 2d9f11d..69b1546 100644 --- a/app/src/main/java/com/example/childguard/TestService.java +++ b/app/src/main/java/com/example/childguard/TestService.java @@ -66,7 +66,7 @@ public class TestService extends Service { @Override public int onStartCommand(Intent intent, int flags, int startId) { this.userId = getSharedPreferences("app_situation", MODE_PRIVATE).getString("ID", null); - if (getSharedPreferences("app_situation", MODE_PRIVATE).getString("ID", null) == null) { + if (this.userId == null) { Log.d("onResume", "ID not initialized."); return flags; // IDが初期化されていない場合は何もしない } From c299696b8dd501cf014da57de5c7261bb2a00952 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=82=8D=E3=82=80=E3=81=AD=E3=81=93?= Date: Thu, 11 Jul 2024 16:00:21 +0900 Subject: [PATCH 47/72] =?UTF-8?q?=E3=82=B3=E3=83=A1=E3=83=B3=E3=83=88?= =?UTF-8?q?=E5=89=8A=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/com/example/childguard/TestService.java | 1 - 1 file changed, 1 deletion(-) diff --git a/app/src/main/java/com/example/childguard/TestService.java b/app/src/main/java/com/example/childguard/TestService.java index 69b1546..e9ff41a 100644 --- a/app/src/main/java/com/example/childguard/TestService.java +++ b/app/src/main/java/com/example/childguard/TestService.java @@ -60,7 +60,6 @@ public class TestService extends Service { private static final NotificationContent BLUETOOTH_NOTIFICATION = new NotificationContent("子供の置き去りをしていませんか?", "Bluetoothと車の切断から5分が経過しました"); - // ユーザーID private String userId = null; @Override From 2bf618a3f2a5fb609fbd06ba1dc8189fb254c029 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=82=8D=E3=82=80=E3=81=AD=E3=81=93?= Date: Thu, 11 Jul 2024 16:01:02 +0900 Subject: [PATCH 48/72] =?UTF-8?q?JavaDoc=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/com/example/childguard/TestService.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/example/childguard/TestService.java b/app/src/main/java/com/example/childguard/TestService.java index e9ff41a..abce10e 100644 --- a/app/src/main/java/com/example/childguard/TestService.java +++ b/app/src/main/java/com/example/childguard/TestService.java @@ -218,6 +218,11 @@ public class TestService extends Service { } } + /** + * 通知を送信する + * @param context コンテキスト + * @param content NotificationContent 通知内容 + */ public void sendNotification(Context context, NotificationContent content) {//通知を行うメソッド // 権限の保有を確認 @@ -283,7 +288,6 @@ public class TestService extends Service { } }; - @Nullable @Override public IBinder onBind(Intent intent) { From d08eab2b15bef6d88aaa958b94a9449384199d9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=82=8D=E3=82=80=E3=81=AD=E3=81=93?= Date: Thu, 11 Jul 2024 16:01:33 +0900 Subject: [PATCH 49/72] =?UTF-8?q?JavaDoc=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/com/example/childguard/TestService.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/example/childguard/TestService.java b/app/src/main/java/com/example/childguard/TestService.java index abce10e..732baba 100644 --- a/app/src/main/java/com/example/childguard/TestService.java +++ b/app/src/main/java/com/example/childguard/TestService.java @@ -188,7 +188,10 @@ public class TestService extends Service { }); } - public void resetReported() {//FireBaseのisReportedをfalseに初期化するメソッド + /** + * 通報フラグをリセットする + */ + public void resetReported() { db = FirebaseFirestore.getInstance();//Firebaseとの紐づけ DocumentReference isReported = db.collection("status").document(this.userId); //isReportedをfalseに更新 From 021bf814a9ff09a22b12c9ce778d98dd69e8b8bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=82=8D=E3=82=80=E3=81=AD=E3=81=93?= Date: Thu, 11 Jul 2024 16:01:52 +0900 Subject: [PATCH 50/72] =?UTF-8?q?JavaDoc=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/com/example/childguard/TestService.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/src/main/java/com/example/childguard/TestService.java b/app/src/main/java/com/example/childguard/TestService.java index 732baba..926410c 100644 --- a/app/src/main/java/com/example/childguard/TestService.java +++ b/app/src/main/java/com/example/childguard/TestService.java @@ -147,6 +147,10 @@ public class TestService extends Service { registerReceiver(receiver, intentFilter); } + /** + * Firestoreのスナップショットリスナーを設定 + * @param mDocRef Firestoreのドキュメントリファレンス + */ private void setSnapshotListener(DocumentReference mDocRef) { // Initialize the PeriodicTaskManager // (Assuming it's done elsewhere as it's not shown in the original code) From 496c3fe934af2846531f7db25e860dba7a636edd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=82=8D=E3=82=80=E3=81=AD=E3=81=93?= Date: Thu, 11 Jul 2024 16:03:54 +0900 Subject: [PATCH 51/72] =?UTF-8?q?=E3=82=B9=E3=82=B3=E3=83=BC=E3=83=97?= =?UTF-8?q?=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/com/example/childguard/TestService.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/example/childguard/TestService.java b/app/src/main/java/com/example/childguard/TestService.java index 926410c..9a82289 100644 --- a/app/src/main/java/com/example/childguard/TestService.java +++ b/app/src/main/java/com/example/childguard/TestService.java @@ -139,7 +139,7 @@ public class TestService extends Service { * ブロードキャストレシーバーを登録 * @param receiver ブロードキャストレシーバー */ - public void registerReceiver(BroadcastReceiver receiver) { + private void registerReceiver(BroadcastReceiver receiver) { IntentFilter intentFilter = new IntentFilter(); intentFilter.addAction(BluetoothDevice.ACTION_ACL_CONNECTED); intentFilter.addAction(BluetoothDevice.ACTION_ACL_DISCONNECTED); @@ -195,7 +195,7 @@ public class TestService extends Service { /** * 通報フラグをリセットする */ - public void resetReported() { + private void resetReported() { db = FirebaseFirestore.getInstance();//Firebaseとの紐づけ DocumentReference isReported = db.collection("status").document(this.userId); //isReportedをfalseに更新 @@ -230,7 +230,7 @@ public class TestService extends Service { * @param context コンテキスト * @param content NotificationContent 通知内容 */ - public void sendNotification(Context context, NotificationContent content) {//通知を行うメソッド + private void sendNotification(Context context, NotificationContent content) {//通知を行うメソッド // 権限の保有を確認 if (isNotNotificationEnabled()) return; From 8a8ac211ef28d97fe229c54bd101a9771bf3a192 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=82=8D=E3=82=80=E3=81=AD=E3=81=93?= Date: Thu, 11 Jul 2024 16:04:28 +0900 Subject: [PATCH 52/72] =?UTF-8?q?=E4=B8=8D=E8=A6=81=E3=81=AA=E3=82=B0?= =?UTF-8?q?=E3=83=AD=E3=83=BC=E3=83=90=E3=83=AB=E5=A4=89=E6=95=B0=E3=82=92?= =?UTF-8?q?=E5=89=8A=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/com/example/childguard/TestService.java | 1 - 1 file changed, 1 deletion(-) diff --git a/app/src/main/java/com/example/childguard/TestService.java b/app/src/main/java/com/example/childguard/TestService.java index 9a82289..48b6530 100644 --- a/app/src/main/java/com/example/childguard/TestService.java +++ b/app/src/main/java/com/example/childguard/TestService.java @@ -50,7 +50,6 @@ public class TestService extends Service { } FirebaseFirestore db; - DocumentReference mDocRef; public static final String TAG = "InspirationQuote"; private static final String CHANNEL_ID = "child_guard_emergency"; From 85811b7bd039b92be539b0129d62794e020620c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=82=8D=E3=82=80=E3=81=AD=E3=81=93?= Date: Thu, 11 Jul 2024 16:05:10 +0900 Subject: [PATCH 53/72] =?UTF-8?q?=E3=82=A4=E3=83=B3=E3=82=B9=E3=82=BF?= =?UTF-8?q?=E3=83=B3=E3=82=B9=E5=A4=89=E6=95=B0=E3=81=A7=E3=81=82=E3=82=8B?= =?UTF-8?q?=E5=BF=85=E8=A6=81=E3=81=8C=E3=81=AA=E3=81=84=E3=82=82=E3=81=AE?= =?UTF-8?q?=E3=82=92=E5=89=8A=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/com/example/childguard/TestService.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/app/src/main/java/com/example/childguard/TestService.java b/app/src/main/java/com/example/childguard/TestService.java index 48b6530..eae449c 100644 --- a/app/src/main/java/com/example/childguard/TestService.java +++ b/app/src/main/java/com/example/childguard/TestService.java @@ -49,8 +49,6 @@ public class TestService extends Service { } } - FirebaseFirestore db; - public static final String TAG = "InspirationQuote"; private static final String CHANNEL_ID = "child_guard_emergency"; private static final int REQUEST_CODE = 100; @@ -195,7 +193,7 @@ public class TestService extends Service { * 通報フラグをリセットする */ private void resetReported() { - db = FirebaseFirestore.getInstance();//Firebaseとの紐づけ + FirebaseFirestore db = FirebaseFirestore.getInstance();//Firebaseとの紐づけ DocumentReference isReported = db.collection("status").document(this.userId); //isReportedをfalseに更新 isReported.update("isReported", false).addOnSuccessListener(unused -> From 7cf0bde8d1ac11261693629e1bc4190e68c9bf99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=82=8D=E3=82=80=E3=81=AD=E3=81=93?= Date: Thu, 11 Jul 2024 16:06:07 +0900 Subject: [PATCH 54/72] =?UTF-8?q?=E5=BE=85=E6=A9=9F=E6=99=82=E9=96=93?= =?UTF-8?q?=E3=82=92=E5=AE=9A=E6=95=B0=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/com/example/childguard/TestService.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/example/childguard/TestService.java b/app/src/main/java/com/example/childguard/TestService.java index eae449c..029507b 100644 --- a/app/src/main/java/com/example/childguard/TestService.java +++ b/app/src/main/java/com/example/childguard/TestService.java @@ -52,6 +52,7 @@ public class TestService extends Service { public static final String TAG = "InspirationQuote"; private static final String CHANNEL_ID = "child_guard_emergency"; private static final int REQUEST_CODE = 100; + private static final int NOTIFICATION_DELAY = 5 * 60 * 1000; // 5 minutes private static final NotificationContent REPORTED_NOTIFICATION = new NotificationContent("子供の置き去りをしていませんか?", "第三者からの通報が行われました。"); private static final NotificationContent BLUETOOTH_NOTIFICATION = @@ -280,7 +281,7 @@ public class TestService extends Service { // 5分経過した時点でも車に乗っていない場合 sendNotification(context, BLUETOOTH_NOTIFICATION); }; - handler.postDelayed(notificationRunnable, 5 * 60 * 1000); // 5分をミリ秒に変換 + handler.postDelayed(notificationRunnable, NOTIFICATION_DELAY); } else if (BluetoothDevice.ACTION_ACL_CONNECTED.equals(action)) { // 再接続された場合、通知をキャンセルする if (notificationRunnable != null) { From 04ea92e8ae47fee5be89694811853b7c8c7d5016 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=82=8D=E3=82=80=E3=81=AD=E3=81=93?= Date: Thu, 11 Jul 2024 16:06:29 +0900 Subject: [PATCH 55/72] =?UTF-8?q?=E8=A1=8C=E6=95=B0=E3=81=AE=E5=89=8A?= =?UTF-8?q?=E6=B8=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/com/example/childguard/TestService.java | 1 - 1 file changed, 1 deletion(-) diff --git a/app/src/main/java/com/example/childguard/TestService.java b/app/src/main/java/com/example/childguard/TestService.java index 029507b..4aca545 100644 --- a/app/src/main/java/com/example/childguard/TestService.java +++ b/app/src/main/java/com/example/childguard/TestService.java @@ -229,7 +229,6 @@ public class TestService extends Service { * @param content NotificationContent 通知内容 */ private void sendNotification(Context context, NotificationContent content) {//通知を行うメソッド - // 権限の保有を確認 if (isNotNotificationEnabled()) return; From 4265b69a83925b2e72852e523c676483c9f908fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=82=8D=E3=82=80=E3=81=AD=E3=81=93?= Date: Thu, 11 Jul 2024 16:08:06 +0900 Subject: [PATCH 56/72] Debug --- app/src/main/java/com/example/childguard/TestService.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/example/childguard/TestService.java b/app/src/main/java/com/example/childguard/TestService.java index 4aca545..7f488ee 100644 --- a/app/src/main/java/com/example/childguard/TestService.java +++ b/app/src/main/java/com/example/childguard/TestService.java @@ -52,7 +52,9 @@ public class TestService extends Service { public static final String TAG = "InspirationQuote"; private static final String CHANNEL_ID = "child_guard_emergency"; private static final int REQUEST_CODE = 100; - private static final int NOTIFICATION_DELAY = 5 * 60 * 1000; // 5 minutes +// private static final int NOTIFICATION_DELAY = 5 * 60 * 1000; // 5 minutes + // DEBUG + private static final int NOTIFICATION_DELAY = 15 * 1000; // 15 seconds private static final NotificationContent REPORTED_NOTIFICATION = new NotificationContent("子供の置き去りをしていませんか?", "第三者からの通報が行われました。"); private static final NotificationContent BLUETOOTH_NOTIFICATION = From 72b4a01018d8762432552206928da91d1f41a8d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=82=8D=E3=82=80=E3=81=AD=E3=81=93?= Date: Thu, 11 Jul 2024 16:26:04 +0900 Subject: [PATCH 57/72] Debug --- .../com/example/childguard/TestService.java | 31 +++++++++++++++++-- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/example/childguard/TestService.java b/app/src/main/java/com/example/childguard/TestService.java index 7f488ee..e1bb01b 100644 --- a/app/src/main/java/com/example/childguard/TestService.java +++ b/app/src/main/java/com/example/childguard/TestService.java @@ -1,5 +1,6 @@ package com.example.childguard; +import android.app.Notification; import android.app.NotificationChannel; import android.app.NotificationManager; import android.app.PendingIntent; @@ -51,6 +52,7 @@ public class TestService extends Service { public static final String TAG = "InspirationQuote"; private static final String CHANNEL_ID = "child_guard_emergency"; + private static final String BACKGROUND_CHANNEL_ID = "child_guard_background"; private static final int REQUEST_CODE = 100; // private static final int NOTIFICATION_DELAY = 5 * 60 * 1000; // 5 minutes // DEBUG @@ -70,19 +72,30 @@ public class TestService extends Service { return flags; // IDが初期化されていない場合は何もしない } + createRunningNotificationChannel(); + Intent notificationIntent = new Intent(this, MainActivity.class); + PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, PendingIntent.FLAG_IMMUTABLE); + Notification notification = new NotificationCompat.Builder(this, BACKGROUND_CHANNEL_ID) + .setContentTitle("Test Service Running") + .setContentText("This service is running in the foreground") + .setSmallIcon(android.R.drawable.ic_menu_info_details) + .setContentIntent(pendingIntent) + .build(); + startForeground(1, notification); + setSnapshotListener(FirebaseFirestore.getInstance().document("status/" + this.userId)); if (isNotBluetoothGranted()) return flags; registerReceiver(receiver); - return flags; + return START_STICKY; } @Override public void onCreate() { super.onCreate(); if (!isNotificationChannelCreated()) { - createNotificationChannel(); + createAlertNotificationChannel(); } } @@ -98,7 +111,7 @@ public class TestService extends Service { /** * 通知チャネルの作成 */ - private void createNotificationChannel() { + private void createAlertNotificationChannel() { int importance = NotificationManager.IMPORTANCE_DEFAULT; NotificationChannel channel = new NotificationChannel(CHANNEL_ID, "通知", importance); channel.setDescription("第三者により置き去りの通報が行われたときに通知します。"); @@ -106,6 +119,18 @@ public class TestService extends Service { notificationManager.createNotificationChannel(channel); } + private void createRunningNotificationChannel() { + NotificationChannel serviceChannel = new NotificationChannel( + CHANNEL_ID, + "Foreground Service Channel", + NotificationManager.IMPORTANCE_DEFAULT + ); + NotificationManager manager = getSystemService(NotificationManager.class); + if (manager != null) { + manager.createNotificationChannel(serviceChannel); + } + } + /** * 通知が許可がされているかどうかを確認 * @return 通知の許可の有無 true: 許可されていない false: 許可されている From efaefe4da3846dd4d891da18eac34af3f5d478ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=82=8D=E3=82=80=E3=81=AD=E3=81=93?= Date: Thu, 11 Jul 2024 16:26:39 +0900 Subject: [PATCH 58/72] fix --- .../main/java/com/example/childguard/TestService.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/com/example/childguard/TestService.java b/app/src/main/java/com/example/childguard/TestService.java index e1bb01b..fc5eec6 100644 --- a/app/src/main/java/com/example/childguard/TestService.java +++ b/app/src/main/java/com/example/childguard/TestService.java @@ -72,7 +72,9 @@ public class TestService extends Service { return flags; // IDが初期化されていない場合は何もしない } - createRunningNotificationChannel(); + if (!isNotificationChannelCreated(BACKGROUND_CHANNEL_ID)) { + createRunningNotificationChannel(); + } Intent notificationIntent = new Intent(this, MainActivity.class); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, PendingIntent.FLAG_IMMUTABLE); Notification notification = new NotificationCompat.Builder(this, BACKGROUND_CHANNEL_ID) @@ -94,7 +96,7 @@ public class TestService extends Service { @Override public void onCreate() { super.onCreate(); - if (!isNotificationChannelCreated()) { + if (!isNotificationChannelCreated(CHANNEL_ID)) { createAlertNotificationChannel(); } } @@ -103,9 +105,9 @@ public class TestService extends Service { * 通知チャネルが作成されているか確認 * @return 通知チャンネルの有無 true: 作成済み false: 未作成 */ - private boolean isNotificationChannelCreated() { + private boolean isNotificationChannelCreated(String channelId) { NotificationManager notificationManager = getSystemService(NotificationManager.class); - return notificationManager.getNotificationChannel(CHANNEL_ID) != null; + return notificationManager.getNotificationChannel(channelId) != null; } /** From 5f3e2c0e940debb426d9a5e299100c0738e4ffd2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=82=8D=E3=82=80=E3=81=AD=E3=81=93?= Date: Thu, 11 Jul 2024 16:29:09 +0900 Subject: [PATCH 59/72] fix miss --- app/src/main/java/com/example/childguard/TestService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/com/example/childguard/TestService.java b/app/src/main/java/com/example/childguard/TestService.java index fc5eec6..af18d72 100644 --- a/app/src/main/java/com/example/childguard/TestService.java +++ b/app/src/main/java/com/example/childguard/TestService.java @@ -123,7 +123,7 @@ public class TestService extends Service { private void createRunningNotificationChannel() { NotificationChannel serviceChannel = new NotificationChannel( - CHANNEL_ID, + BACKGROUND_CHANNEL_ID, "Foreground Service Channel", NotificationManager.IMPORTANCE_DEFAULT ); From e257038e40dc7d7b88d1358bf0eaf2d6e12abd10 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=82=8D=E3=82=80=E3=81=AD=E3=81=93?= Date: Thu, 11 Jul 2024 16:31:14 +0900 Subject: [PATCH 60/72] =?UTF-8?q?=E3=83=95=E3=82=A9=E3=82=A2=E3=82=B0?= =?UTF-8?q?=E3=83=A9=E3=82=A6=E3=83=B3=E3=83=89=E3=82=B5=E3=83=BC=E3=83=93?= =?UTF-8?q?=E3=82=B9=E3=81=A8=E3=81=97=E3=81=A6=E9=96=8B=E5=A7=8B=E3=81=99?= =?UTF-8?q?=E3=82=8B=E3=82=88=E3=81=86=E3=81=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/com/example/childguard/MainActivity.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/example/childguard/MainActivity.java b/app/src/main/java/com/example/childguard/MainActivity.java index c67c8ea..6947e3b 100644 --- a/app/src/main/java/com/example/childguard/MainActivity.java +++ b/app/src/main/java/com/example/childguard/MainActivity.java @@ -136,6 +136,8 @@ public class MainActivity extends AppCompatActivity { } registerReceiver(receiver, intentFilter); + startForegroundService(new Intent(this, TestService.class)); + } @@ -334,8 +336,8 @@ public class MainActivity extends AppCompatActivity { @Override public void onStop() {//アプリをバックグラウンドにした時のメソッド super.onStop(); - Intent intent = new Intent(getApplication(), TestService.class); - startService(intent);//TestServiceを起動 +// Intent intent = new Intent(getApplication(), TestService.class); +// startService(intent);//TestServiceを起動 } public void NotificationBluetooth(Context context) {//実際に通知を行うメソッド From e9b08942c48174ee40699ed16ddc5b547f6a963b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=82=8D=E3=82=80=E3=81=AD=E3=81=93?= Date: Thu, 11 Jul 2024 16:35:02 +0900 Subject: [PATCH 61/72] =?UTF-8?q?=E9=80=9A=E7=9F=A5=E3=81=AE=E9=87=8D?= =?UTF-8?q?=E8=A6=81=E5=BA=A6=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/com/example/childguard/TestService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/com/example/childguard/TestService.java b/app/src/main/java/com/example/childguard/TestService.java index af18d72..fb2d6d5 100644 --- a/app/src/main/java/com/example/childguard/TestService.java +++ b/app/src/main/java/com/example/childguard/TestService.java @@ -125,7 +125,7 @@ public class TestService extends Service { NotificationChannel serviceChannel = new NotificationChannel( BACKGROUND_CHANNEL_ID, "Foreground Service Channel", - NotificationManager.IMPORTANCE_DEFAULT + NotificationManager.IMPORTANCE_NONE ); NotificationManager manager = getSystemService(NotificationManager.class); if (manager != null) { From 92f3cf1e0ffb8213917f62e59c893c64468b631f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=82=8D=E3=82=80=E3=81=AD=E3=81=93?= Date: Thu, 11 Jul 2024 16:36:21 +0900 Subject: [PATCH 62/72] =?UTF-8?q?=E6=96=87=E8=A8=80=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/com/example/childguard/TestService.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/example/childguard/TestService.java b/app/src/main/java/com/example/childguard/TestService.java index fb2d6d5..51f3ca0 100644 --- a/app/src/main/java/com/example/childguard/TestService.java +++ b/app/src/main/java/com/example/childguard/TestService.java @@ -78,8 +78,8 @@ public class TestService extends Service { Intent notificationIntent = new Intent(this, MainActivity.class); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, PendingIntent.FLAG_IMMUTABLE); Notification notification = new NotificationCompat.Builder(this, BACKGROUND_CHANNEL_ID) - .setContentTitle("Test Service Running") - .setContentText("This service is running in the foreground") + .setContentTitle("ChildGuardバックグラウンドサービス") + .setContentText("接続/通報監視サービスがバックグラウンドで実行されています") .setSmallIcon(android.R.drawable.ic_menu_info_details) .setContentIntent(pendingIntent) .build(); From bc59f98e3da7cb881d73009127e125b2b4c1f835 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=82=8D=E3=82=80=E3=81=AD=E3=81=93?= Date: Thu, 11 Jul 2024 16:36:33 +0900 Subject: [PATCH 63/72] debug --- app/src/main/java/com/example/childguard/TestService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/com/example/childguard/TestService.java b/app/src/main/java/com/example/childguard/TestService.java index 51f3ca0..6364860 100644 --- a/app/src/main/java/com/example/childguard/TestService.java +++ b/app/src/main/java/com/example/childguard/TestService.java @@ -56,7 +56,7 @@ public class TestService extends Service { private static final int REQUEST_CODE = 100; // private static final int NOTIFICATION_DELAY = 5 * 60 * 1000; // 5 minutes // DEBUG - private static final int NOTIFICATION_DELAY = 15 * 1000; // 15 seconds + private static final int NOTIFICATION_DELAY = 5 * 1000; // 15 seconds private static final NotificationContent REPORTED_NOTIFICATION = new NotificationContent("子供の置き去りをしていませんか?", "第三者からの通報が行われました。"); private static final NotificationContent BLUETOOTH_NOTIFICATION = From dbbe4b2f1e51c928a00257892f717480eebc00b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=82=8D=E3=82=80=E3=81=AD=E3=81=93?= Date: Thu, 11 Jul 2024 16:48:29 +0900 Subject: [PATCH 64/72] =?UTF-8?q?Bluetooth=E9=A7=86=E5=8B=95=E3=81=AE?= =?UTF-8?q?=E9=80=9A=E7=9F=A5=E3=81=A8=E9=80=9A=E5=A0=B1=E3=82=92=E5=88=A5?= =?UTF-8?q?=E3=83=81=E3=83=A3=E3=83=B3=E3=83=8D=E3=83=AB=E3=81=AB(?= =?UTF-8?q?=E9=80=9A=E7=9F=A5=E3=81=AE=E4=B8=8A=E6=9B=B8=E3=81=8D=E3=81=8C?= =?UTF-8?q?=E8=B5=B7=E3=81=93=E3=82=89=E3=81=AA=E3=81=84=E3=82=88=E3=81=86?= =?UTF-8?q?=E3=81=AB)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/example/childguard/TestService.java | 26 ++++++++++++------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/com/example/childguard/TestService.java b/app/src/main/java/com/example/childguard/TestService.java index 6364860..48f0ac3 100644 --- a/app/src/main/java/com/example/childguard/TestService.java +++ b/app/src/main/java/com/example/childguard/TestService.java @@ -35,10 +35,12 @@ public class TestService extends Service { public static class NotificationContent { private final String title; private final String description; + private final String channelId; - public NotificationContent(String title, String description) { + public NotificationContent(String title, String description, String channelId) { this.title = title; this.description = description; + this.channelId = channelId; } public String getTitle() { @@ -48,19 +50,24 @@ public class TestService extends Service { public String getDescription() { return description; } + + public String getChannelId() { + return channelId; + } } public static final String TAG = "InspirationQuote"; - private static final String CHANNEL_ID = "child_guard_emergency"; + private static final String BT_ALERT_CHANNEL_ID = "child_guard_bt_alert"; + private static final String REPORTED_CHANNEL_ID = "child_guard_reported"; private static final String BACKGROUND_CHANNEL_ID = "child_guard_background"; private static final int REQUEST_CODE = 100; // private static final int NOTIFICATION_DELAY = 5 * 60 * 1000; // 5 minutes // DEBUG private static final int NOTIFICATION_DELAY = 5 * 1000; // 15 seconds private static final NotificationContent REPORTED_NOTIFICATION = - new NotificationContent("子供の置き去りをしていませんか?", "第三者からの通報が行われました。"); + new NotificationContent("子供の置き去りをしていませんか?", "第三者からの通報が行われました。", REPORTED_CHANNEL_ID); private static final NotificationContent BLUETOOTH_NOTIFICATION = - new NotificationContent("子供の置き去りをしていませんか?", "Bluetoothと車の切断から5分が経過しました"); + new NotificationContent("子供の置き去りをしていませんか?", "Bluetoothと車の切断から5分が経過しました", BT_ALERT_CHANNEL_ID); private String userId = null; @@ -96,9 +103,8 @@ public class TestService extends Service { @Override public void onCreate() { super.onCreate(); - if (!isNotificationChannelCreated(CHANNEL_ID)) { - createAlertNotificationChannel(); - } + if (!isNotificationChannelCreated(BT_ALERT_CHANNEL_ID)) createAlertNotificationChannel(BT_ALERT_CHANNEL_ID); + if (!isNotificationChannelCreated(REPORTED_CHANNEL_ID)) createAlertNotificationChannel(REPORTED_CHANNEL_ID); } /** @@ -113,9 +119,9 @@ public class TestService extends Service { /** * 通知チャネルの作成 */ - private void createAlertNotificationChannel() { + private void createAlertNotificationChannel(String channelId) { int importance = NotificationManager.IMPORTANCE_DEFAULT; - NotificationChannel channel = new NotificationChannel(CHANNEL_ID, "通知", importance); + NotificationChannel channel = new NotificationChannel(channelId, "通知", importance); channel.setDescription("第三者により置き去りの通報が行われたときに通知します。"); NotificationManager notificationManager = getSystemService(NotificationManager.class); notificationManager.createNotificationChannel(channel); @@ -263,7 +269,7 @@ public class TestService extends Service { vibrateDevice(); - NotificationCompat.Builder builder = new NotificationCompat.Builder(context, CHANNEL_ID) + NotificationCompat.Builder builder = new NotificationCompat.Builder(context, content.getChannelId()) .setSmallIcon(android.R.drawable.ic_menu_info_details) .setContentTitle(content.getTitle())//通知のタイトル .setContentText(content.getDescription())//通知の内容 From b6c1bbd213169732661d19b6ebe4f8f8a48c81bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=82=8D=E3=82=80=E3=81=AD=E3=81=93?= Date: Thu, 11 Jul 2024 16:53:22 +0900 Subject: [PATCH 65/72] =?UTF-8?q?=E9=80=9A=E7=9F=A5ID=E3=82=92=E4=BF=AE?= =?UTF-8?q?=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/example/childguard/TestService.java | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/com/example/childguard/TestService.java b/app/src/main/java/com/example/childguard/TestService.java index 48f0ac3..6794147 100644 --- a/app/src/main/java/com/example/childguard/TestService.java +++ b/app/src/main/java/com/example/childguard/TestService.java @@ -36,8 +36,9 @@ public class TestService extends Service { private final String title; private final String description; private final String channelId; + private final int notificationId; - public NotificationContent(String title, String description, String channelId) { + public NotificationContent(String title, String description, String channelId, int notificationId) { this.title = title; this.description = description; this.channelId = channelId; @@ -54,6 +55,10 @@ public class TestService extends Service { public String getChannelId() { return channelId; } + + public int getNotificationId() { + return notificationId; + } } public static final String TAG = "InspirationQuote"; @@ -65,9 +70,9 @@ public class TestService extends Service { // DEBUG private static final int NOTIFICATION_DELAY = 5 * 1000; // 15 seconds private static final NotificationContent REPORTED_NOTIFICATION = - new NotificationContent("子供の置き去りをしていませんか?", "第三者からの通報が行われました。", REPORTED_CHANNEL_ID); + new NotificationContent("子供の置き去りをしていませんか?", "第三者からの通報が行われました。", REPORTED_CHANNEL_ID, 1); private static final NotificationContent BLUETOOTH_NOTIFICATION = - new NotificationContent("子供の置き去りをしていませんか?", "Bluetoothと車の切断から5分が経過しました", BT_ALERT_CHANNEL_ID); + new NotificationContent("子供の置き去りをしていませんか?", "Bluetoothと車の切断から5分が経過しました", BT_ALERT_CHANNEL_ID, 2); private String userId = null; @@ -280,7 +285,7 @@ public class TestService extends Service { NotificationManager notificationManager = context.getSystemService(NotificationManager.class); - notificationManager.notify(R.string.app_name, builder.build());//通知の表示 + notificationManager.notify(content.getNotificationId(), builder.build()); } private final BroadcastReceiver receiver = new BroadcastReceiver() { From 7653efa4e3d73761b9f220f4bd488bae851ffdb0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=82=8D=E3=82=80=E3=81=AD=E3=81=93?= Date: Thu, 11 Jul 2024 16:53:41 +0900 Subject: [PATCH 66/72] =?UTF-8?q?=E3=83=9F=E3=82=B9=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/com/example/childguard/TestService.java | 1 + 1 file changed, 1 insertion(+) diff --git a/app/src/main/java/com/example/childguard/TestService.java b/app/src/main/java/com/example/childguard/TestService.java index 6794147..5a70e43 100644 --- a/app/src/main/java/com/example/childguard/TestService.java +++ b/app/src/main/java/com/example/childguard/TestService.java @@ -42,6 +42,7 @@ public class TestService extends Service { this.title = title; this.description = description; this.channelId = channelId; + this.notificationId = notificationId; } public String getTitle() { From cf8260bdb30f29c906b6589d373ddc3e4c298db1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=82=8D=E3=82=80=E3=81=AD=E3=81=93?= Date: Thu, 11 Jul 2024 16:55:11 +0900 Subject: [PATCH 67/72] fix dup --- app/src/main/java/com/example/childguard/TestService.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/example/childguard/TestService.java b/app/src/main/java/com/example/childguard/TestService.java index 5a70e43..c5a455a 100644 --- a/app/src/main/java/com/example/childguard/TestService.java +++ b/app/src/main/java/com/example/childguard/TestService.java @@ -71,9 +71,9 @@ public class TestService extends Service { // DEBUG private static final int NOTIFICATION_DELAY = 5 * 1000; // 15 seconds private static final NotificationContent REPORTED_NOTIFICATION = - new NotificationContent("子供の置き去りをしていませんか?", "第三者からの通報が行われました。", REPORTED_CHANNEL_ID, 1); + new NotificationContent("子供の置き去りをしていませんか?", "第三者からの通報が行われました。", REPORTED_CHANNEL_ID, 2); private static final NotificationContent BLUETOOTH_NOTIFICATION = - new NotificationContent("子供の置き去りをしていませんか?", "Bluetoothと車の切断から5分が経過しました", BT_ALERT_CHANNEL_ID, 2); + new NotificationContent("子供の置き去りをしていませんか?", "Bluetoothと車の切断から5分が経過しました", BT_ALERT_CHANNEL_ID, 3); private String userId = null; From ebceb27c996aa688c2460f633fe294c8a949f7de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=82=8D=E3=82=80=E3=81=AD=E3=81=93?= Date: Thu, 11 Jul 2024 17:01:10 +0900 Subject: [PATCH 68/72] invert --- app/src/main/java/com/example/childguard/TestService.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/com/example/childguard/TestService.java b/app/src/main/java/com/example/childguard/TestService.java index c5a455a..900cf7a 100644 --- a/app/src/main/java/com/example/childguard/TestService.java +++ b/app/src/main/java/com/example/childguard/TestService.java @@ -85,7 +85,7 @@ public class TestService extends Service { return flags; // IDが初期化されていない場合は何もしない } - if (!isNotificationChannelCreated(BACKGROUND_CHANNEL_ID)) { + if (isNotificationChannelCreated(BACKGROUND_CHANNEL_ID)) { createRunningNotificationChannel(); } Intent notificationIntent = new Intent(this, MainActivity.class); @@ -109,8 +109,8 @@ public class TestService extends Service { @Override public void onCreate() { super.onCreate(); - if (!isNotificationChannelCreated(BT_ALERT_CHANNEL_ID)) createAlertNotificationChannel(BT_ALERT_CHANNEL_ID); - if (!isNotificationChannelCreated(REPORTED_CHANNEL_ID)) createAlertNotificationChannel(REPORTED_CHANNEL_ID); + if (isNotificationChannelCreated(BT_ALERT_CHANNEL_ID)) createAlertNotificationChannel(BT_ALERT_CHANNEL_ID); + if (isNotificationChannelCreated(REPORTED_CHANNEL_ID)) createAlertNotificationChannel(REPORTED_CHANNEL_ID); } /** @@ -119,7 +119,7 @@ public class TestService extends Service { */ private boolean isNotificationChannelCreated(String channelId) { NotificationManager notificationManager = getSystemService(NotificationManager.class); - return notificationManager.getNotificationChannel(channelId) != null; + return notificationManager.getNotificationChannel(channelId) == null; } /** From 2dcf6808f4b2bbce92bf5aa47350fda85e54692a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=82=8D=E3=82=80=E3=81=AD=E3=81=93?= Date: Thu, 11 Jul 2024 17:01:56 +0900 Subject: [PATCH 69/72] JavaDoc --- app/src/main/java/com/example/childguard/TestService.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/src/main/java/com/example/childguard/TestService.java b/app/src/main/java/com/example/childguard/TestService.java index 900cf7a..8d1898a 100644 --- a/app/src/main/java/com/example/childguard/TestService.java +++ b/app/src/main/java/com/example/childguard/TestService.java @@ -133,6 +133,9 @@ public class TestService extends Service { notificationManager.createNotificationChannel(channel); } + /** + * バックグラウンドで実行中の通知チャネルを作成 + */ private void createRunningNotificationChannel() { NotificationChannel serviceChannel = new NotificationChannel( BACKGROUND_CHANNEL_ID, From 54cf93769d180df60d908bf41f9de985526172bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=82=8D=E3=82=80=E3=81=AD=E3=81=93?= Date: Fri, 12 Jul 2024 09:41:21 +0900 Subject: [PATCH 70/72] =?UTF-8?q?=E6=9D=A1=E4=BB=B6=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/com/example/childguard/TestService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/com/example/childguard/TestService.java b/app/src/main/java/com/example/childguard/TestService.java index 8d1898a..f897d29 100644 --- a/app/src/main/java/com/example/childguard/TestService.java +++ b/app/src/main/java/com/example/childguard/TestService.java @@ -318,7 +318,7 @@ public class TestService extends Service { // ----------------------------------------------------- String action = intent.getAction(); // may need to chain this to a recognizing function boolean isInCar = getSharedPreferences("Bluetooth_situation", MODE_PRIVATE).getBoolean("isInCarPref", false); - if (BluetoothDevice.ACTION_ACL_DISCONNECTED.equals(action) && !isInCar) { + if (BluetoothDevice.ACTION_ACL_DISCONNECTED.equals(action) && isInCar) { // bluetoothが切断されたときに乗車状態のとき notificationRunnable = () -> { // 5分経過した時点でも車に乗っていない場合 From 5e15040c561b9da10f15eb0d7d33a91f2bbebc69 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=82=8D=E3=82=80=E3=81=AD=E3=81=93?= Date: Fri, 12 Jul 2024 09:42:24 +0900 Subject: [PATCH 71/72] =?UTF-8?q?=E6=9D=A1=E4=BB=B6=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/com/example/childguard/TestService.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/example/childguard/TestService.java b/app/src/main/java/com/example/childguard/TestService.java index f897d29..e8091c5 100644 --- a/app/src/main/java/com/example/childguard/TestService.java +++ b/app/src/main/java/com/example/childguard/TestService.java @@ -315,10 +315,15 @@ public class TestService extends Service { Log.d("BT_Judge", "Not registered device"); return; } - // ----------------------------------------------------- String action = intent.getAction(); // may need to chain this to a recognizing function boolean isInCar = getSharedPreferences("Bluetooth_situation", MODE_PRIVATE).getBoolean("isInCarPref", false); - if (BluetoothDevice.ACTION_ACL_DISCONNECTED.equals(action) && isInCar) { + if (!isInCar) { + Log.d("BT_Judge", "Not in car"); + return; + } + // ----------------------------------------------------- + + if (BluetoothDevice.ACTION_ACL_DISCONNECTED.equals(action)) { // bluetoothが切断されたときに乗車状態のとき notificationRunnable = () -> { // 5分経過した時点でも車に乗っていない場合 From 3d54953110c8eab2485baeb6e77f99db608e64b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=82=8D=E3=82=80=E3=81=AD=E3=81=93?= Date: Fri, 12 Jul 2024 10:13:01 +0900 Subject: [PATCH 72/72] =?UTF-8?q?=E5=BE=AE=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/com/example/childguard/TestService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/com/example/childguard/TestService.java b/app/src/main/java/com/example/childguard/TestService.java index e8091c5..996e8ed 100644 --- a/app/src/main/java/com/example/childguard/TestService.java +++ b/app/src/main/java/com/example/childguard/TestService.java @@ -315,7 +315,6 @@ public class TestService extends Service { Log.d("BT_Judge", "Not registered device"); return; } - String action = intent.getAction(); // may need to chain this to a recognizing function boolean isInCar = getSharedPreferences("Bluetooth_situation", MODE_PRIVATE).getBoolean("isInCarPref", false); if (!isInCar) { Log.d("BT_Judge", "Not in car"); @@ -323,6 +322,7 @@ public class TestService extends Service { } // ----------------------------------------------------- + String action = intent.getAction(); // may need to chain this to a recognizing function if (BluetoothDevice.ACTION_ACL_DISCONNECTED.equals(action)) { // bluetoothが切断されたときに乗車状態のとき notificationRunnable = () -> {