LoginSignup
0
0

More than 1 year has passed since last update.

Androidアプリ開発での音声認識の権限でハマった話

Last updated at Posted at 2022-02-05

ハマったエラー

System.err: java.lang.SecurityException: Not allowed to change Do Not Disturb state

解決法

いろいろ調べた結果,海外サイトしかなかったが頑張って読んで解決した.
なぜかわからないが,サイレントモード系の権限が関係しているらしい.

AndroidMainifest.xml
<uses-permission android:name="android.permission.ACCESS_NOTIFICATION_POLICY" />

で,下のやつをエラー発生箇所(僕の場合は,音声認識開始ボタンを押したところでエラーが発生したので,そこらへんの動作付近)に入力.

NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
                    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && !notificationManager.isNotificationPolicyAccessGranted()) {
                        Intent intent = new Intent(android.provider.Settings.ACTION_NOTIFICATION_POLICY_ACCESS_SETTINGS);
                        startActivity(intent);
                    }

import等は適当に頑張ってください.

ハマったエラー(2回目)

これでなんとか動くだろうと思ったらまた違うエラーが出た.

'Bind to recognition service failed' on android device

解決法(2回目)

AndroidMainifest.xml
<queries> <package android:name="com.google.android.googlequicksearchbox"/> </queries>

issueに上がってた.

ようやく,これで正常に動き出した...よかった.

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0