Skip to content

Instantly share code, notes, and snippets.

@qamarelsafadi
Created May 12, 2023 08:42
Show Gist options
  • Save qamarelsafadi/76bd7b52f835e09193a96a366d4bc82a to your computer and use it in GitHub Desktop.
Save qamarelsafadi/76bd7b52f835e09193a96a366d4bc82a to your computer and use it in GitHub Desktop.
// update your activity version
implementation 'androidx.activity:activity-ktx:1.7.1'
val pickMedia = registerForActivityResult(ActivityResultContracts.PickVisualMedia()) { uri ->
// Callback is invoked after the user selects a media item or closes the
// photo picker.
if (uri != null) {
// do what you want with pic
} else {
Log.d("PhotoPicker", "No media selected")
}
}
private fun pickImageFromGallery() {
pickMedia.launch(PickVisualMediaRequest(ActivityResultContracts.PickVisualMedia.ImageOnly))
}
// to support all version put this in your Manifest file
<service
android:name=".data.notification.Controller"
android:exported="false">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
@mubarakaali
Copy link

Is Photo picker is only worked android 13 and above.

    <service android:name="com.google.android.gms.metadata.ModuleDependencies"
        android:enabled="false"
        android:exported="false"
        tools:ignore="MissingClass">
        <intent-filter>
            <action android:name="com.google.android.gms.metadata.MODULE_DEPENDENCIES" />
        </intent-filter>
        <meta-data android:name="photopicker_activity:0:required" android:value="" />
    </service>
     below 12  we should used it in the manifest but it seems not working . have any idea why it not working ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment