From 16265d5d31ee3e35b44591e61afb532fe33176ea Mon Sep 17 00:00:00 2001 From: Asura146 Date: Mon, 5 Aug 2024 01:11:34 +0900 Subject: [PATCH] =?UTF-8?q?ID=E3=81=8C=E7=94=9F=E6=88=90=E3=81=95=E3=82=8C?= =?UTF-8?q?=E3=81=9F=E3=81=A8=E3=81=8D=E3=81=AB=E3=80=81=E3=82=B5=E3=83=BC?= =?UTF-8?q?=E3=83=93=E3=82=B9=E3=81=AE=E8=B5=B7=E5=8B=95=E3=82=92=E8=A1=8C?= =?UTF-8?q?=E3=81=86=E3=82=88=E3=81=86=E3=81=AB=E3=81=97=E3=81=9F=20?= =?UTF-8?q?=E3=81=A4=E3=81=84=E3=81=A7=E3=81=AB=E3=80=81=E3=82=B5=E3=83=BC?= =?UTF-8?q?=E3=83=93=E3=82=B9=E3=81=AE=E5=90=8D=E5=89=8D=E3=82=82=E5=A4=89?= =?UTF-8?q?=E3=81=88=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/AndroidManifest.xml | 2 +- .../main/java/com/example/childguard/MainActivity.java | 3 +-- .../java/com/example/childguard/SettingFragment.java | 10 ++++++++++ .../{TestService.java => SurveillanceService.java} | 7 +++---- 4 files changed, 15 insertions(+), 7 deletions(-) rename app/src/main/java/com/example/childguard/{TestService.java => SurveillanceService.java} (98%) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index a13ea4a..2b3de96 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -35,7 +35,7 @@ - + \ No newline at end of file diff --git a/app/src/main/java/com/example/childguard/MainActivity.java b/app/src/main/java/com/example/childguard/MainActivity.java index ec2e48d..c60deed 100644 --- a/app/src/main/java/com/example/childguard/MainActivity.java +++ b/app/src/main/java/com/example/childguard/MainActivity.java @@ -14,7 +14,6 @@ import android.content.pm.PackageManager; import android.graphics.Color; import android.os.Build; import android.os.Bundle; -import android.os.Handler; import android.os.Vibrator; import android.preference.PreferenceManager; import android.util.Log; @@ -134,7 +133,7 @@ public class MainActivity extends AppCompatActivity { } registerReceiver(receiver, intentFilter); - startForegroundService(new Intent(this, TestService.class)); + startForegroundService(new Intent(this, SurveillanceService.class)); } diff --git a/app/src/main/java/com/example/childguard/SettingFragment.java b/app/src/main/java/com/example/childguard/SettingFragment.java index 81de482..0f74795 100644 --- a/app/src/main/java/com/example/childguard/SettingFragment.java +++ b/app/src/main/java/com/example/childguard/SettingFragment.java @@ -3,6 +3,8 @@ package com.example.childguard; import static android.content.ContentValues.TAG; import static android.content.Context.MODE_PRIVATE; +import android.content.Context; +import android.content.Intent; import android.content.SharedPreferences; import android.os.Bundle; import android.util.Log; @@ -95,6 +97,7 @@ public class SettingFragment extends Fragment { SharedPreferences.Editor editor = sharedPreferences1.edit(); editor.putString("ID", documentReference.getId()); editor.apply(); + startTestService(); Toast.makeText(getActivity(), "初回登録", Toast.LENGTH_SHORT).show(); getParentFragmentManager().beginTransaction().addToBackStack(null).replace(R.id.fragmentContainerView, GenerateQrFragment.newInstance(documentReference.getId())).commit(); @@ -106,4 +109,11 @@ public class SettingFragment extends Fragment { } }); } + private void startTestService() { + Context context = getContext(); + if (context != null) { + Intent serviceIntent = new Intent(context, SurveillanceService.class); + context.startForegroundService(serviceIntent); + } + } } \ No newline at end of file diff --git a/app/src/main/java/com/example/childguard/TestService.java b/app/src/main/java/com/example/childguard/SurveillanceService.java similarity index 98% rename from app/src/main/java/com/example/childguard/TestService.java rename to app/src/main/java/com/example/childguard/SurveillanceService.java index 1b3244e..db1b96c 100644 --- a/app/src/main/java/com/example/childguard/TestService.java +++ b/app/src/main/java/com/example/childguard/SurveillanceService.java @@ -27,9 +27,7 @@ import androidx.core.app.NotificationManagerCompat; import com.google.firebase.firestore.DocumentReference; import com.google.firebase.firestore.FirebaseFirestore; -import org.checkerframework.checker.index.qual.LengthOf; - -public class TestService extends Service { +public class SurveillanceService extends Service { private final Handler handler = new Handler(); private Runnable notificationRunnable; @@ -81,6 +79,7 @@ public class TestService extends Service { @Override public int onStartCommand(Intent intent, int flags, int startId) { + Log.d(TAG, "onStartCommand: "); this.userId = getSharedPreferences("app_situation", MODE_PRIVATE).getString("ID", null); if (this.userId == null) { Log.d("onResume", "ID not initialized."); @@ -256,7 +255,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, PendingIntent.FLAG_IMMUTABLE); + return PendingIntent.getActivity(context, SurveillanceService.REQUEST_CODE, intent, PendingIntent.FLAG_IMMUTABLE); } /** -- 2.45.1