0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Android permission システムパーミッション

Last updated at Posted at 2018-10-06

はじめに

作成したAndroidアプリを実機デバッグするたびに同じエラーに引っかかってしまうので備忘録。

エラー内容

permissionに関するエラー。
実行するとこのようなエラーが出る。

09-27 17:42:33.276 10821-10821/com.example.xxxx.peakdetection E/AudioRecord: AudioFlinger could not create record track, status: -1
09-27 17:42:33.278 10821-10821/com.example.xxxx.peakdetection E/AudioRecord-JNI: Error creating AudioRecord instance: initialization check failed with status -1.
09-27 17:42:33.278 10821-10821/com.example.xxxx.peakdetection E/android.media.AudioRecord: Error code -20 when initializing native AudioRecord object.
09-27 17:42:33.279 10821-10821/com.example.xxxx.peakdetection D/AndroidRuntime: Shutting down VM
09-27 17:42:33.284 10821-10821/com.example.xxxx.peakdetection E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example.xxxx.peakdetection, PID: 10821
    java.lang.IllegalStateException: startRecording() called on an uninitialized AudioRecord.
        at android.media.AudioRecord.startRecording(AudioRecord.java:1016)
        at com.example.xxxx.peakdetection.MainActivity.onCheckedChanged(MainActivity.java:66)
        at android.widget.CompoundButton.setChecked(CompoundButton.java:156)
        at android.widget.Switch.setChecked(Switch.java:1076)
        at android.widget.Switch.toggle(Switch.java:1071)
        at android.widget.CompoundButton.performClick(CompoundButton.java:120)
        at android.view.View$PerformClick.run(View.java:22277)
        at android.os.Handler.handleCallback(Handler.java:751)
        at android.os.Handler.dispatchMessage(Handler.java:95)
        at android.os.Looper.loop(Looper.java:159)
        at android.app.ActivityThread.main(ActivityThread.java:6097)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)

原因

AndroidManifest.xmlにpermissionを記述するだけでなく、実機でも許可が必要。
「設定」→「アプリ」→「アプリ名」→「権限」

さいごに

実機での許可が必要なのはわかるがわざわざ設定からアクセスするのが面倒でわかりにくい。
アプリ開始画面でダイアログを出すことで実機のpermissionを出す方法を今後検討。

追記 (2019/07/07)

Permission Request、やってみた。
Androidのパーミッションリクエスト(複数)

0
2
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
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?