Commit 94d4266c by Takatoshi Miura

Task #49379【Android12】API31対応 Android12で機器連携するとアプリが落ちる

parent 4e5ddf88
......@@ -126,6 +126,7 @@ public class Constant {
int AccessFineLocation = 1;
int Camera = 2;
int Audio =3;
int Bluetooth = 4;
}
public interface TaskReportLevel {
......
......@@ -19,8 +19,10 @@
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /><!-- an app to access precise location from location sources such as GPS, cell towers, and Wi-Fi -->
<uses-permission android:name="android.permission.RECORD_AUDIO" /><!-- AudioPlayView -->
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.BLUETOOTH" android:maxSdkVersion="30" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" android:maxSdkVersion="30" />
<uses-permission android:name="android.permission.BLUETOOTH_SCAN" />
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
<uses-permission android:name="android.permission.NFC" />
<!-- QRCode -->
......
......@@ -1452,4 +1452,6 @@
<!-- OZコンポーネント削除後 -->
<string name="msg_error_open_ozd_content">OZフォームで作成されているため、表示することができません。</string>
<!-- API31対応後 -->
<string name="msg_permission_dialog_bluetooth">Bluetooth利用権限が必要です。\nアプリ設定画面へ遷移します。</string>
</resources>
......@@ -1460,4 +1460,6 @@
<!-- OZコンポーネント削除後 -->
<string name="msg_error_open_ozd_content">OZ 서식으로 작성되었으므로 표시할 수 없습니다.</string>
<!-- API31対応後 -->
<string name="msg_permission_dialog_bluetooth">Bluetooth 이용권한이 필요합니다. \n앱설정화면으로 이동합니다.</string>
</resources>
\ No newline at end of file
......@@ -1458,4 +1458,6 @@
<!-- OZコンポーネント削除後 -->
<string name="msg_error_open_ozd_content">Since it is created with an OZ form, it cannot be displayed.</string>
<!-- API31対応後 -->
<string name="msg_permission_dialog_bluetooth">Bluetooth usage authority is required. \n To transition to the application setting screen.</string>
</resources>
\ No newline at end of file
......@@ -476,6 +476,11 @@ public class ABookSettingFragment extends PreferenceFragment {
chinoDevicePairing.setOnPreferenceClickListener(new OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
// アプリ側のBluetooth許可チェック
ABookPermissionHelper helper = new ABookPermissionHelper(getActivity(), Constant.ABookPermissionType.Bluetooth, null);
if (!helper.checkMultiPermissions(true)) {
return true;
}
try {
// ペアリング設定画面(BLE通信)
Intent intent = new Intent();
......@@ -494,6 +499,11 @@ public class ABookSettingFragment extends PreferenceFragment {
sppDevicePairing.setOnPreferenceClickListener(new OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
// アプリ側のBluetooth許可チェック
ABookPermissionHelper helper = new ABookPermissionHelper(getActivity(), Constant.ABookPermissionType.Bluetooth, null);
if (!helper.checkMultiPermissions(true)) {
return true;
}
try {
// ペアリング設定画面(SPP通信)
Intent intent = new Intent();
......
......@@ -82,9 +82,22 @@ public class ABookPermissionHelper {
reqPermissions.add(android.Manifest.permission.RECORD_AUDIO);
}
// Bluetooth
if (ContextCompat.checkSelfPermission(mContext,
android.Manifest.permission.BLUETOOTH) != PackageManager.PERMISSION_GRANTED) {
reqPermissions.add(android.Manifest.permission.BLUETOOTH);
if (Build.VERSION.SDK_INT > 30) {
// Android12以上の場合
if (ContextCompat.checkSelfPermission(mContext,
android.Manifest.permission.BLUETOOTH_CONNECT) != PackageManager.PERMISSION_GRANTED) {
reqPermissions.add(android.Manifest.permission.BLUETOOTH_CONNECT);
}
if (ContextCompat.checkSelfPermission(mContext ,
android.Manifest.permission.BLUETOOTH_SCAN) != PackageManager.PERMISSION_GRANTED) {
reqPermissions.add(android.Manifest.permission.BLUETOOTH_SCAN);
}
} else {
// Android12未満の場合
if (ContextCompat.checkSelfPermission(mContext,
android.Manifest.permission.BLUETOOTH) != PackageManager.PERMISSION_GRANTED) {
reqPermissions.add(android.Manifest.permission.BLUETOOTH);
}
}
return reqPermissions;
}
......@@ -153,6 +166,27 @@ public class ABookPermissionHelper {
getUserPref(mContext, AppDefType.UserPrefKey.RESOURCE_PATTERN_TYPE, 0));
}
break;
case Constant.ABookPermissionType.Bluetooth:
// Android12未満では実施しない
if (Build.VERSION.SDK_INT < 31) {
break;
}
// Bluetooth
if (ContextCompat.checkSelfPermission(mContext,
android.Manifest.permission.BLUETOOTH_CONNECT) != PERMISSION_GRANTED) {
// リソースパターンの適用
permitionTextResourceId = PatternStringUtil.patternToInt(mContext,
R.string.msg_permission_dialog_bluetooth,
getUserPref(mContext, AppDefType.UserPrefKey.RESOURCE_PATTERN_TYPE, 0));
}
if (ContextCompat.checkSelfPermission(mContext,
android.Manifest.permission.BLUETOOTH_SCAN) != PERMISSION_GRANTED) {
// リソースパターンの適用
permitionTextResourceId = PatternStringUtil.patternToInt(mContext,
R.string.msg_permission_dialog_bluetooth,
getUserPref(mContext, AppDefType.UserPrefKey.RESOURCE_PATTERN_TYPE, 0));
}
break;
}
if (permitionTextResourceId > 0) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment