diff --git a/.idea/misc.xml b/.idea/misc.xml index 773fe0f..0ad17cb 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,6 +1,7 @@ + - + diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index cbdd641..a13ea4a 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -10,6 +10,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 f33c9e3..0f9c8d4 100644 --- a/app/src/main/java/com/example/childguard/MainActivity.java +++ b/app/src/main/java/com/example/childguard/MainActivity.java @@ -241,6 +241,15 @@ public class MainActivity extends AppCompatActivity { notificationManager.notify(R.string.app_name, builder.build()); + } + + @Override + public void onStop() { + super.onStop(); + Intent intent = new Intent(getApplication(), TestService.class); + startService(intent); + + } //Bluetooth_setupの戻るボタン diff --git a/app/src/main/java/com/example/childguard/TestService.java b/app/src/main/java/com/example/childguard/TestService.java new file mode 100644 index 0000000..00c9c31 --- /dev/null +++ b/app/src/main/java/com/example/childguard/TestService.java @@ -0,0 +1,74 @@ +package com.example.childguard; + +import android.app.NotificationChannel; +import android.app.NotificationManager; +import android.app.Service; +import android.content.Context; +import android.content.Intent; +import android.content.pm.PackageManager; +import android.os.IBinder; +import android.os.Vibrator; +import android.util.Log; + +import androidx.annotation.Nullable; +import androidx.core.app.ActivityCompat; +import androidx.core.app.NotificationCompat; +import androidx.core.app.NotificationManagerCompat; + +public class TestService extends Service { + + public int onStartCommand(Intent intent, int flags, int startId) { + + + audioStart(); + + return START_NOT_STICKY; + + } + + private void audioStart(){ + //↓通知をする際に起動するバイブレーション + ((Vibrator) getSystemService(Context.VIBRATOR_SERVICE)).vibrate(1000); + //通知のやつ↓ + 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"); + //↓通知の詳細設定的な奴 + NotificationCompat.Builder builder = new NotificationCompat + + .Builder(this, "CHANNEL_ID") + .setSmallIcon(android.R.drawable.ic_menu_info_details) + .setContentTitle("通報検知") + .setContentText("子供の置き去りを検知しました。") + .setPriority(NotificationCompat.PRIORITY_DEFAULT); + + + if (ActivityCompat.checkSelfPermission(this, android.Manifest.permission.POST_NOTIFICATIONS) != PackageManager.PERMISSION_GRANTED) { + // TODO: Consider calling + // ActivityCompat#requestPermissions + // here to request the missing permissions, and then overriding + // public void onRequestPermissionsResult(int requestCode, String[] permissions, + // int[] grantResults) + // to handle the case where the user grants the permission. See the documentation + // for ActivityCompat#requestPermissions for more details. + return; + } + notificationManager.notify(R.string.app_name, builder.build()); + + } + + @Nullable + @Override + public IBinder onBind(Intent intent) { + + + return null; + } +} \ No newline at end of file