diff --git a/app/build.gradle b/app/build.gradle index 6150f78..71a9f46 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,6 +1,7 @@ plugins { id 'com.android.application' id 'org.jetbrains.kotlin.android' + id 'com.google.gms.google-services' } android { @@ -58,6 +59,7 @@ dependencies { implementation 'androidx.compose.ui:ui-graphics' implementation 'androidx.compose.ui:ui-tooling-preview' implementation 'androidx.compose.material3:material3' + implementation 'com.google.firebase:firebase-firestore:24.4.1' testImplementation 'junit:junit:4.13.2' diff --git a/app/src/main/java/com/example/childguard/MainActivity.java b/app/src/main/java/com/example/childguard/MainActivity.java index 4de4695..9d01fb7 100644 --- a/app/src/main/java/com/example/childguard/MainActivity.java +++ b/app/src/main/java/com/example/childguard/MainActivity.java @@ -24,11 +24,25 @@ import java.util.Date; import java.util.Random; import java.util.UUID; +import android.util.Log; +import android.widget.Toast; +import androidx.annotation.Nullable; +import androidx.appcompat.app.AppCompatActivity; +import com.google.firebase.firestore.DocumentReference; +import com.google.firebase.firestore.DocumentSnapshot; +import com.google.firebase.firestore.EventListener; +import com.google.firebase.firestore.FirebaseFirestore; +import com.google.firebase.firestore.FirebaseFirestoreException; + public class MainActivity extends AppCompatActivity { BluetoothManager bluetoothManager; BluetoothAdapter bluetoothAdapter; + public static final String TAG = "InspirationQuote"; + private DocumentReference mDocRef = FirebaseFirestore.getInstance().document("users/q6t702C8nsXyehckByrr");//現在の位置を取得 + boolean flg = false; + //↓日付を取得するやつ public static String getNowDate() { @SuppressLint("SimpleDateFormat") final DateFormat df = new SimpleDateFormat("yyy/MM/dd HH:mm:ss"); @@ -40,23 +54,13 @@ public class MainActivity extends AppCompatActivity { protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); - - - //通知のやつ↓ - int importance = NotificationManager.IMPORTANCE_DEFAULT; - - NotificationChannel channel = new NotificationChannel("CHANNEL_ID", "通報通知", importance); - //説明・説明 ここに通知の説明を書くことができる↓ - channel.setDescription("第3者からの通報を検知しました"); - - NotificationManager notificationManager = getSystemService(NotificationManager.class); - notificationManager.createNotificationChannel(channel); - //通知のやつ↑ - + super.onStart(); BottomNavigationView bottomNavigationView = findViewById(R.id.nav_view); - bottomNavigationView.setOnNavigationItemSelectedListener(v -> { + bottomNavigationView.setOnNavigationItemSelectedListener(v -> + + { if (v.getItemId() == findViewById(R.id.navigation_home).getId()) { getSupportFragmentManager().beginTransaction() .replace(findViewById(R.id.fragmentContainerView).getId(), HomeFragment.newInstance("test", "tset")) @@ -73,6 +77,39 @@ public class MainActivity extends AppCompatActivity { return true; + + }); + mDocRef.addSnapshotListener(this, new EventListener() { + @Override + public void onEvent(@Nullable DocumentSnapshot documentSnapshot, @Nullable FirebaseFirestoreException e) { + Log.d("nt","イベント開始"); + if (flg && documentSnapshot != null && documentSnapshot.exists()) { + + String parent = documentSnapshot.getString("parent"); + Log.d("nt","レスポンスを検知しました1"); + if (parent.equals("s")) { + + //通知のやつ↓ + int importance = NotificationManager.IMPORTANCE_DEFAULT; + + NotificationChannel channel = new NotificationChannel("CHANNEL_ID", "通報通知", importance); + //説明・説明 ここに通知の説明を書くことができる↓ + channel.setDescription("第3者からの通報を検知しました"); + + NotificationManager notificationManager = getSystemService(NotificationManager.class); + notificationManager.createNotificationChannel(channel); + //通知のやつ↑ + Log.d("nt","レスポンスを検知しました2"); + + + notifyMain(); + } else if (e != null) { + Log.w(TAG, "Got an exceptiion!", e); + } + + } + flg = true; + } }); } @@ -110,4 +147,4 @@ public class MainActivity extends AppCompatActivity { ActionBar actionBar = getSupportActionBar(); actionBar.setDisplayHomeAsUpEnabled(enableBackButton); } -} \ No newline at end of file +} diff --git a/build.gradle b/build.gradle index 4314313..e8491f3 100644 --- a/build.gradle +++ b/build.gradle @@ -1,4 +1,8 @@ -// Top-level build file where you can add configuration options common to all sub-projects/modules. +buildscript { + dependencies { + classpath 'com.google.gms:google-services:4.3.14' + } +}// Top-level build file where you can add configuration options common to all sub-projects/modules. plugins { id 'com.android.application' version '8.0.2' apply false id 'com.android.library' version '8.0.2' apply false