Skip to content

Commit

Permalink
Update example gradle and AndroiManifest to support newest android
Browse files Browse the repository at this point in the history
  • Loading branch information
LucJosin committed Mar 4, 2023
1 parent 52dba06 commit d74493d
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@ class OnAudioQueryPlugin : FlutterPlugin, MethodCallHandler, ActivityAware,
private val onPermission = arrayOf(
Manifest.permission.READ_EXTERNAL_STORAGE,
Manifest.permission.WRITE_EXTERNAL_STORAGE,

)

@RequiresApi(Build.VERSION_CODES.TIRAMISU)
private val tiramisuPermission = arrayOf(
private val tiramisuPermission = arrayOf(
Manifest.permission.READ_MEDIA_AUDIO,
Manifest.permission.READ_MEDIA_IMAGES,
Manifest.permission.READ_MEDIA_VIDEO
Expand Down Expand Up @@ -134,47 +134,45 @@ class OnAudioQueryPlugin : FlutterPlugin, MethodCallHandler, ActivityAware,
override fun onPermissionStatus(context: Context?): Boolean{
// After "leaving" this class, context will be null so, we need this context argument to
// call the [checkSelfPermission].
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU){
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU){
return tiramisuPermission.all {
ContextCompat.checkSelfPermission(
context ?: pContext,
it
) == PackageManager.PERMISSION_GRANTED
}
}
else{
else {
return onPermission.all {
ContextCompat.checkSelfPermission(
context ?: pContext,
it
) == PackageManager.PERMISSION_GRANTED
}
}

}

override fun onRequestPermission() {
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU){
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU){
ActivityCompat.requestPermissions(pActivity, tiramisuPermission, onRequestCode)
}
else{
else {
ActivityCompat.requestPermissions(pActivity, onPermission, onRequestCode)
}

}

// Second requestPermission, this one with the option "Never Ask Again".
@RequiresApi(Build.VERSION_CODES.TIRAMISU)
override fun onRetryRequestPermission() {
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU){
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU){
if (ActivityCompat.shouldShowRequestPermissionRationale(pActivity, onPermission[0])
|| ActivityCompat.shouldShowRequestPermissionRationale(pActivity, onPermission[1])
) {
retryRequest = false
onRequestPermission()
}
}
else{
else {
if (ActivityCompat.shouldShowRequestPermissionRationale(pActivity, tiramisuPermission[0])
|| ActivityCompat.shouldShowRequestPermissionRationale(pActivity, tiramisuPermission[1])
|| ActivityCompat.shouldShowRequestPermissionRationale(pActivity,tiramisuPermission[2])
Expand Down
4 changes: 2 additions & 2 deletions on_audio_query/example/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {
compileSdkVersion 31
compileSdkVersion 33

sourceSets {
main.java.srcDirs += 'src/main/kotlin'
Expand All @@ -36,7 +36,7 @@ android {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.lucasjosino.on_audio_query_example"
minSdkVersion 16
targetSdkVersion 30
targetSdkVersion 33
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
}
Expand Down
11 changes: 9 additions & 2 deletions on_audio_query/example/android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.lucasjosino.on_audio_query_example">

<uses-permission android:name="android.permission.INTERNET"/>

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.INTERNET"/>

<!-- Android >= 13 | API >= 33 -->
<uses-permission android:name="android.permission.READ_MEDIA_IMAGES" />
<uses-permission android:name="android.permission.READ_MEDIA_VIDEO" />
<uses-permission android:name="android.permission.READ_MEDIA_AUDIO" />

<application
android:label="on_audio_query_example"
Expand All @@ -15,7 +21,8 @@
android:theme="@style/LaunchTheme"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
android:hardwareAccelerated="true"
android:windowSoftInputMode="adjustResize">
android:windowSoftInputMode="adjustResize"
android:exported="true">
<!-- Specifies an Android theme to apply to this Activity as soon as
the Android process has started. This theme is visible to the user
while the Flutter UI initializes. After that, this theme continues
Expand Down

0 comments on commit d74493d

Please sign in to comment.