codelab-android-workmanager
codelab-android-workmanager copied to clipboard
The `resolveActivity` doesn't work for Android 11 like this
The lint says It needs @SuppressLint("QueryPermissionsNeeded"). Also, it doesn't open the activity.
Code lab page number: https://developer.android.com/codelabs/android-workmanager#8
override fun onCreate(savedInstanceState: Bundle?) {
// Setup view output image file button
binding.seeFileButton.setOnClickListener {
viewModel.outputUri?.let { currentUri ->
val actionView = Intent(Intent.ACTION_VIEW, currentUri)
actionView.resolveActivity(packageManager)?.run {
startActivity(actionView)
}
}
}
}
Reviewing the final code, i see a missing <query> tag in AndroidManifest.xml. Maybe this is the solution and, after add this code, the @SuppressLint("QueryPermissionsNeeded") is not suggested anymore.
<queries>
<package android:name="com.example.background" />
<intent>
<action android:name="android.intent.action.VIEW" />
<data android:mimeType="image/png"/>
</intent>
</queries>
Thanks! This was exactly my issue on my Android 12 Device. I added @AlveZs's <queries> code in the AndroidManifest.xml right under the <uses-permission> section and it worked.
+1 @AlveZs solution works.
Since we're running the default handler, a simple startActivity(Intent(Intent.ACTION_VIEW, currentUri)) call would work without a need for resolution and hence, a need for the queries permission.