From 19a4765bf064a48374367ffc76804bc877706d7e Mon Sep 17 00:00:00 2001 From: it232115 Date: Fri, 19 Jan 2024 06:19:04 +0900 Subject: [PATCH] =?UTF-8?q?=E7=94=BB=E9=9D=A2=E9=81=B7=E7=A7=BB=E3=82=92?= =?UTF-8?q?=E5=8E=9F=E5=9B=A0=E3=81=A8=E3=81=99=E3=82=8BFirebase=E3=81=A8?= =?UTF-8?q?=E3=81=AE=E5=90=8C=E6=9C=9F=E3=82=BA=E3=83=AC=E3=82=92=E6=94=B9?= =?UTF-8?q?=E5=96=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/example/childguard/HomeFragment.java | 2 ++ .../com/example/childguard/MainActivity.java | 28 ++++++++++++------- .../com/example/childguard/TestService.java | 2 ++ 3 files changed, 22 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/com/example/childguard/HomeFragment.java b/app/src/main/java/com/example/childguard/HomeFragment.java index 59efc75..1a35983 100644 --- a/app/src/main/java/com/example/childguard/HomeFragment.java +++ b/app/src/main/java/com/example/childguard/HomeFragment.java @@ -75,10 +75,12 @@ public class HomeFragment extends Fragment implements OnEventListener{ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); + if (getArguments() != null) { // mParam1 = getArguments().getString(ARG_PARAM1); mParam2 = getArguments().getString(ARG_PARAM2); } + } @Override diff --git a/app/src/main/java/com/example/childguard/MainActivity.java b/app/src/main/java/com/example/childguard/MainActivity.java index 7ca75f1..606f74a 100644 --- a/app/src/main/java/com/example/childguard/MainActivity.java +++ b/app/src/main/java/com/example/childguard/MainActivity.java @@ -101,6 +101,8 @@ public class MainActivity extends AppCompatActivity { .replace(findViewById(R.id.fragmentContainerView).getId(), this.homeFragment) .addToBackStack(null) .commit(); + firebaselink(); + } else if (v.getItemId() == findViewById(R.id.navigation_notification).getId()) { findViewById(R.id.fab_scan_qr_code).setVisibility(FrameLayout.VISIBLE); getSupportFragmentManager().beginTransaction() @@ -123,6 +125,7 @@ public class MainActivity extends AppCompatActivity { ScanOptions options = new ScanOptions(); options.setPrompt("QRコードを読み取ってください"); QrLauncher.launch(options); + }); //Bluetooth検知機能 @@ -138,7 +141,7 @@ public class MainActivity extends AppCompatActivity { Log.d("BT", "Permission to connect bluetooth devices granted"); } registerReceiver(receiver, intentFilter); - + changessituation(); } @Override @@ -147,15 +150,7 @@ public class MainActivity extends AppCompatActivity { changessituation(); Log.d("onResume", "called"); Log.d("onResume", "mDocRef is null"); - //共有プリファレンス全体の準備 - SharedPreferences sharedPreferences = getSharedPreferences("app_situation", MODE_PRIVATE); - String IdPref = sharedPreferences.getString("ID", null);////アプリに記録されているIDの取得 - if (IdPref == null) {//FireBaseのIDがアプリに登録されているとき - Log.d("onResume", "ID not initialized."); - } else { - mDocRef = FirebaseFirestore.getInstance().document("status/" + IdPref);//現在の位置を取得 - initNotification(mDocRef);//現在の位置を引数に initNotification()を処理 - } + firebaselink(); } private void initNotification(DocumentReference mDocRef) {//サイト上で押されたボタンの管理 @@ -240,6 +235,19 @@ public class MainActivity extends AppCompatActivity { } }; + + public void firebaselink(){//Firebaseのドキュメントの取得 + //共有プリファレンス全体の準備 + SharedPreferences sharedPreferences = getSharedPreferences("app_situation", MODE_PRIVATE); + String IdPref = sharedPreferences.getString("ID", null);////アプリに記録されているIDの取得 + if (IdPref == null) {//FireBaseのIDがアプリに登録されているとき + Log.d("onResume", "ID not initialized."); + } else { + mDocRef = FirebaseFirestore.getInstance().document("status/" + IdPref);//現在の位置を取得 + initNotification(mDocRef);//現在の位置を引数に initNotification()を処理 + + } + } public void ResetReported(){//FireBaseのisReportedをfalseに初期化するメソッド //共有プリファレンス全体の準備 SharedPreferences sharedPreferences = MainActivity.this.getSharedPreferences("app_situation", MODE_PRIVATE); diff --git a/app/src/main/java/com/example/childguard/TestService.java b/app/src/main/java/com/example/childguard/TestService.java index f897f58..5838fc1 100644 --- a/app/src/main/java/com/example/childguard/TestService.java +++ b/app/src/main/java/com/example/childguard/TestService.java @@ -101,6 +101,7 @@ public class TestService extends Service { } + public void ResetReported() {//FireBaseのisReportedをfalseに初期化するメソッド //共有プリファレンス全体の準備 SharedPreferences sharedPreferences = getSharedPreferences("app_situation", MODE_PRIVATE); @@ -122,6 +123,7 @@ public class TestService extends Service { }); } + public void NotificationSetting() {//通知に関する設定の処理を行うメソッド int importance = NotificationManager.IMPORTANCE_DEFAULT; //通知チャネルの実装