Created
April 20, 2021 14:39
-
-
Save anshajkhare/76fd187dcd3b7deb6203e23d423ef7ac to your computer and use it in GitHub Desktop.
Check for audio permissions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class MainActivity : AppCompatActivity() { | |
| companion object { | |
| // This constant is needed to verify the audio permission result | |
| private const val ASR_PERMISSION_REQUEST_CODE = 0 | |
| } | |
| override fun onCreate(savedInstanceState: Bundle?) { | |
| super.onCreate(savedInstanceState) | |
| setContentView(R.layout.activity_main) | |
| verifyAudioPermissions() | |
| // ... | |
| } | |
| private fun verifyAudioPermissions() { | |
| if (checkCallingOrSelfPermission(Manifest.permission.RECORD_AUDIO) != PackageManager.PERMISSION_GRANTED) { | |
| ActivityCompat.requestPermissions( | |
| this, | |
| arrayOf(Manifest.permission.RECORD_AUDIO), | |
| ASR_PERMISSION_REQUEST_CODE | |
| ) | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment