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] =?UTF-8?q?=E3=83=A6=E3=83=BC=E3=82=B6=E3=83=BCID=E3=81=AE?= =?UTF-8?q?=E5=8F=96=E5=BE=97=E3=82=92=E5=85=B1=E9=80=9A=E5=8C=96=20+=20?= =?UTF-8?q?=E3=82=A4=E3=83=B3=E3=82=B9=E3=82=BF=E3=83=B3=E3=82=B9=E5=A4=89?= =?UTF-8?q?=E6=95=B0=E3=81=A7=E7=AE=A1=E7=90=86=E3=81=99=E3=82=8B=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 --- .../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)); }