Compare commits

...

3 Commits

Author SHA1 Message Date
rca
b720877fa5 fix 2025-01-29 16:23:30 +09:00
rca
0a4680e7b8 test 2025-01-29 16:23:18 +09:00
rca
89f51e1b38 fix permission check 2025-01-29 16:20:59 +09:00
2 changed files with 18 additions and 4 deletions

View File

@ -130,10 +130,11 @@ public class MainActivity extends AppCompatActivity {
return;
} else {
Log.d("BT", "Permission to connect bluetooth devices granted");
}
registerReceiver(receiver, intentFilter);
//startForegroundService(new Intent(this, SurveillanceService.class));
registerReceiver(receiver, intentFilter);
startForegroundService(new Intent(this, SurveillanceService.class));
}
}

View File

@ -1,5 +1,6 @@
package com.example.childguard;
import android.Manifest;
import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationManager;
@ -12,6 +13,7 @@ import android.content.Intent;
import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.os.Build;
import android.os.Handler;
import android.os.IBinder;
import android.os.VibrationEffect;
@ -169,7 +171,8 @@ public class SurveillanceService extends Service {
* @return Bluetoothの権限の有無 true: 許可されていない false: 許可されている
*/
private boolean isNotBluetoothGranted() {
if (ActivityCompat.checkSelfPermission(this, android.Manifest.permission.BLUETOOTH_CONNECT) != PackageManager.PERMISSION_GRANTED) {
String btPermission = getBluetoothConnectPermission();
if (ActivityCompat.checkSelfPermission(this, btPermission) != PackageManager.PERMISSION_GRANTED) {
Log.d(TAG, "Bluetoothの権限が許可されていません");
return true;
} else {
@ -190,6 +193,16 @@ public class SurveillanceService extends Service {
registerReceiver(receiver, intentFilter);
}
/**
* Bluetoothの接続権限を取得
* @return Bluetoothの接続権限
*/
private String getBluetoothConnectPermission() {
return (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) ?
android.Manifest.permission.BLUETOOTH_CONNECT :
Manifest.permission.BLUETOOTH;
}
/**
* Firestoreのスナップショットリスナーを設定
* @param mDocRef Firestoreのドキュメントリファレンス