Android Studio Sample Code
I'm new to Android and Java.
I'm using the latest Android Studio on my windows 10.
I simply created an empty activity and pasted the code from
to my MainActivity.
Following its comments, I also added uses-permission in my manifest.
I've read all Q&As, I believe the manifest is good.
However I keep getting setAudioSource failed with the callstack in the end of post.
The error is the same on both my Nexus 5 and my Nexus 5 Virtual device.
Could you help me, please? Thanks!
My code is below:
Output in Android Monitor Verbose mode:
2 Answers
Yes there is! You can call requestPermissions() from your Activity or Fragment. This example fits for a call from an Activity
Then you can check in onRequestPermissionResult if permission was granted:
For good practice, you should check if a permission was already granted (to avoid annoying the user by asking every time..)
Finally found i need to go to Setting->App->Permission-> slide on the Microphone and Storage manually. Why didn't I finding anything mentioning this.
Is there a way to explicitly prompt the user to give these permissions, instead of silently crashing with the settings hidden so deep in the phone??