提出段階のver
This commit is contained in:
parent
75b4be9ff1
commit
235afb92cb
|
@ -408,7 +408,7 @@ public class MainActivity extends AppCompatActivity {
|
||||||
NotificationBluetooth(getApplicationContext());//通知を行うメソッド
|
NotificationBluetooth(getApplicationContext());//通知を行うメソッド
|
||||||
}}
|
}}
|
||||||
|
|
||||||
}, 5 *60 *1000); // 5分をミリ秒に変換
|
}, 5 *60*1000); // 5分をミリ秒に変換
|
||||||
}
|
}
|
||||||
}else {
|
}else {
|
||||||
Log.d("BT", "Device disconnected");
|
Log.d("BT", "Device disconnected");
|
||||||
|
|
|
@ -102,18 +102,18 @@ public class TestService extends Service {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void NotificationSetting() {//通知に関する設定の処理を行うメソッド
|
public void NotificationSetting() {//通知に関する設定の処理を行うメソッド
|
||||||
int importance = NotificationManager.IMPORTANCE_DEFAULT;
|
int importance = NotificationManager.IMPORTANCE_DEFAULT;
|
||||||
//通知チャネルの実装
|
//通知チャネルの実装
|
||||||
NotificationChannel channel = new NotificationChannel("CHANNEL_ID", "通知", importance);
|
NotificationChannel channel = new NotificationChannel("CHANNEL_ID", "通知", importance);
|
||||||
channel.setDescription("第三者により置き去りの通報が行われたときに通知します。");
|
channel.setDescription("第三者により置き去りの通報が行われたときに通知します。");
|
||||||
|
|
||||||
NotificationManager notificationManager = getSystemService(NotificationManager.class);
|
NotificationManager notificationManager = getSystemService(NotificationManager.class);
|
||||||
notificationManager.createNotificationChannel(channel);
|
notificationManager.createNotificationChannel(channel);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Notification(Context context) {//実際に通知を行うメソッド
|
public void Notification(Context context) {//実際に通知を行うメソッド
|
||||||
final String CHANNEL_ID = "my_channel_id";
|
final String CHANNEL_ID = "my_channel_id";
|
||||||
// 通知がクリックされたときに送信されるIntent
|
// 通知がクリックされたときに送信されるIntent
|
||||||
Intent intent = new Intent(context, MainActivity.class);
|
Intent intent = new Intent(context, MainActivity.class);
|
||||||
intent.setAction("OPEN_ACTIVITY");
|
intent.setAction("OPEN_ACTIVITY");
|
||||||
|
@ -152,12 +152,13 @@ public class TestService extends Service {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
NotificationManager notificationManager = (NotificationManager)context.getSystemService(context.NOTIFICATION_SERVICE);
|
NotificationManager notificationManager = (NotificationManager) context.getSystemService(context.NOTIFICATION_SERVICE);
|
||||||
if (ActivityCompat.checkSelfPermission(this, android.Manifest.permission.POST_NOTIFICATIONS) != PackageManager.PERMISSION_GRANTED) {
|
if (ActivityCompat.checkSelfPermission(this, android.Manifest.permission.POST_NOTIFICATIONS) != PackageManager.PERMISSION_GRANTED) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
notificationManager.notify(R.string.app_name, builder.build());//通知の表示
|
notificationManager.notify(R.string.app_name, builder.build());//通知の表示
|
||||||
}
|
}
|
||||||
|
|
||||||
public void NotificationBluetooth(Context context) {//実際に通知を行うメソッド
|
public void NotificationBluetooth(Context context) {//実際に通知を行うメソッド
|
||||||
final String CHANNEL_ID = "my_channel_id";
|
final String CHANNEL_ID = "my_channel_id";
|
||||||
// 通知がクリックされたときに送信されるIntent
|
// 通知がクリックされたときに送信されるIntent
|
||||||
|
@ -198,7 +199,7 @@ public class TestService extends Service {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
NotificationManager notificationManager = (NotificationManager)context.getSystemService(context.NOTIFICATION_SERVICE);
|
NotificationManager notificationManager = (NotificationManager) context.getSystemService(context.NOTIFICATION_SERVICE);
|
||||||
if (ActivityCompat.checkSelfPermission(this, android.Manifest.permission.POST_NOTIFICATIONS) != PackageManager.PERMISSION_GRANTED) {
|
if (ActivityCompat.checkSelfPermission(this, android.Manifest.permission.POST_NOTIFICATIONS) != PackageManager.PERMISSION_GRANTED) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -206,10 +207,6 @@ public class TestService extends Service {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public void Bluetooth_status() {
|
public void Bluetooth_status() {
|
||||||
IntentFilter intentFilter = new IntentFilter();
|
IntentFilter intentFilter = new IntentFilter();
|
||||||
intentFilter.addAction(BluetoothDevice.ACTION_ACL_CONNECTED);
|
intentFilter.addAction(BluetoothDevice.ACTION_ACL_CONNECTED);
|
||||||
|
@ -232,8 +229,8 @@ public class TestService extends Service {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onReceive(Context context, Intent intent) {
|
public void onReceive(Context context, Intent intent) {
|
||||||
SharedPreferences pref=getSharedPreferences("Bluetooth_situation",MODE_PRIVATE);
|
SharedPreferences pref = getSharedPreferences("Bluetooth_situation", MODE_PRIVATE);
|
||||||
SharedPreferences.Editor e=pref.edit();
|
SharedPreferences.Editor e = pref.edit();
|
||||||
String action = intent.getAction(); // may need to chain this to a recognizing function
|
String action = intent.getAction(); // may need to chain this to a recognizing function
|
||||||
BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
|
BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
|
||||||
Boolean isInCar = pref.getBoolean("isInCarPref", false);
|
Boolean isInCar = pref.getBoolean("isInCarPref", false);
|
||||||
|
@ -253,22 +250,21 @@ public class TestService extends Service {
|
||||||
Log.d("BT", "Device connected");
|
Log.d("BT", "Device connected");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Log.d("BT_Judge", "Registered: " + registeredId);
|
Log.d("BT_Judge", "Registered: " + registeredId);
|
||||||
|
|
||||||
if (deviceHardwareAddress.equals(registeredId)) {
|
if (deviceHardwareAddress.equals(registeredId)) {
|
||||||
//登録済みのデバイスだったときの処理
|
//登録済みのデバイスだったときの処理
|
||||||
Log.d("BT_Judge", "登録済み");
|
Log.d("BT_Judge", "登録済み");
|
||||||
e.putBoolean("connection_status",true);
|
e.putBoolean("connection_status", true);
|
||||||
|
|
||||||
} else{
|
} else {
|
||||||
//登録していないデバイスだったときの処理
|
//登録していないデバイスだったときの処理
|
||||||
Log.d("BT_Judge", "未登録");
|
Log.d("BT_Judge", "未登録");
|
||||||
e.putBoolean("connection_status",false);
|
e.putBoolean("connection_status", false);
|
||||||
}
|
}
|
||||||
e.apply();
|
e.apply();
|
||||||
|
|
||||||
} else if (BluetoothDevice.ACTION_ACL_DISCONNECTED.equals(action)&&!isInCar) {//bluetoothが切断されたときに乗車状態のとき
|
} else if (BluetoothDevice.ACTION_ACL_DISCONNECTED.equals(action) && !isInCar) {//bluetoothが切断されたときに乗車状態のとき
|
||||||
|
|
||||||
//Do something if disconnected
|
//Do something if disconnected
|
||||||
//デバイスが切断されたときの処理
|
//デバイスが切断されたときの処理
|
||||||
|
@ -278,22 +274,20 @@ public class TestService extends Service {
|
||||||
handler.postDelayed(new Runnable() {
|
handler.postDelayed(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
if (BluetoothDevice.ACTION_ACL_DISCONNECTED.equals(action)&&!isInCar) {//その後bluetoothを再接続したり降車状態になったりしていない=置き去りが発生した可能性大
|
if (BluetoothDevice.ACTION_ACL_DISCONNECTED.equals(action) && !isInCar) {//その後bluetoothを再接続したり降車状態になったりしていない=置き去りが発生した可能性大
|
||||||
NotificationBluetooth(getApplicationContext());//通知を行うメソッド
|
NotificationBluetooth(getApplicationContext());//通知を行うメソッド
|
||||||
}}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}, 5 *60 *1000); // 5分をミリ秒に変換
|
}, 5 * 60 * 1000); // 5分をミリ秒に変換
|
||||||
}
|
}
|
||||||
}else {
|
} else {
|
||||||
Log.d("BT", "Device disconnected");
|
Log.d("BT", "Device disconnected");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public IBinder onBind(Intent intent) {
|
public IBinder onBind(Intent intent) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user