So as I read in the developer.android site the Android 13
brings new changes in the Permission field.
I have a Chat application where I need to make calls, open the camera, record audio, read and write in the external storage. So in the SplashScreen I request those permissions to the user. However some of them are not granted but without even the system ask me for those.
Here is what I have declared in the AndroidManifest.xml
file
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.USE_FULL_SCREEN_INTENT" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="com.google.android.gms.permission.AD_ID"/>
<uses-permission android:name="android.permission.POST_NOTIFICATIONS"/>
<uses-feature
android:name="android.hardware.camera"
android:required="true" />
<uses-feature android:name="android.hardware.camera.autofocus" />
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<application
android:name=".ChatApplication"
android:allowBackup="false"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="false"
android:hardwareAccelerated="true"
android:icon="@mipmap/logo"
android:label="@string/app_name"
android:largeHeap="true"
android:networkSecurityConfig="@xml/network_security_config"
android:requestLegacyExternalStorage="true"
android:roundIcon="@mipmap/logo"
android:supportsRtl="true"
android:theme="@style/AppTheme"
tools:ignore="AllowBackup,GoogleAppIndexingWarning,UnusedAttribute"
tools:replace="android:allowBackup, android:label">
And here is what i have in the Splashscreen Activity
class SplashActivity : BaseActivity() {
private val splashViewModel: SplashViewModel by viewModels()
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_splash)
if (!hasPermissions(this, *REQUIRED_PERMISSIONS))
ActivityCompat.requestPermissions(this, REQUIRED_PERMISSIONS, ALL_PERMISSIONS)
else
Handler(Looper.getMainLooper()).postDelayed ({ startUi() }, 1000)
}
private fun hasPermissions(context: Context, vararg permissions: String): Boolean =
permissions.all {
ActivityCompat.checkSelfPermission(context, it) == PackageManager.PERMISSION_GRANTED
}
private fun startUi() {
// navigate to main application
}
private fun finishActivity() {
toast("You must grant all required permissions to continue")
finish()
}
override fun onRequestPermissionsResult(
requestCode: Int,
permissions: Array<out String>,
grantResults: IntArray
) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults)
when (requestCode) {
ALL_PERMISSIONS -> {
if (grantResults.all { it == PackageManager.PERMISSION_GRANTED }) startUi()
else finishActivity()
}
}
}
companion object {
const val ALL_PERMISSIONS = 10
private val REQUIRED_PERMISSIONS =
mutableListOf (
Manifest.permission.READ_PHONE_STATE,
Manifest.permission.RECORD_AUDIO,
Manifest.permission.CAMERA
).apply {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
add(Manifest.permission.READ_MEDIA_IMAGES)
add(Manifest.permission.READ_MEDIA_VIDEO)
add(Manifest.permission.READ_MEDIA_AUDIO)
add(Manifest.permission.POST_NOTIFICATIONS)
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q)
add(Manifest.permission.WRITE_EXTERNAL_STORAGE)
}.toTypedArray()
}
}
When i put a breakPoint to the onRequestPermissionsResult
i see this
The Permission prompts that I see in the screen are for Camera, Record audio, and Phone State. After those the application exits by calling the finishActivity()
I'm running the app in a Pixel 6 Pro API 33
Emulator
What is the proper way of doing that? How can i solve that?
According to log, may be you are missing 3 permission these are
- READ_MEDIA_IMAGES
- READ_MEDIA_VIDEO
- READ_MEDIA_AUDIO
add instead of the above 3 permission in manifest
<uses-permission android:name="android.permission.READ_MEDIA_*"/>
for getting all of the above three permission has taken only the external storage permission.
In the android documentation on the link below, only these three permissions are provided
READ_MEDIA_IMAGES
, READ_MEDIA_VIDEO
, READ_MEDIA_AUDIO
instead of using READ_EXTERNAL_STORAGE
.
link :https://developer.android.com/about/versions/13/behavior-changes-13#granular-media-permissions