Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[@nativescript/imagepicker]: Migrate to Android photo picker #605

Open
asharghi opened this issue Oct 23, 2024 · 6 comments
Open

[@nativescript/imagepicker]: Migrate to Android photo picker #605

asharghi opened this issue Oct 23, 2024 · 6 comments
Labels
enhancement New feature or request

Comments

@asharghi
Copy link
Contributor

This is the warning im getting on every playstore release now:

"If your app has a one-time or infrequent need to access photos and videos, migrate to the Android photo picker"

Skjermbilde_2024-10-21_kl _10 34 31
@tujlaky
Copy link

tujlaky commented Dec 5, 2024

The deadline is January 22 2025 for this migration. Any idea how can we fix this easily?

@tujlaky
Copy link

tujlaky commented Dec 9, 2024

Here it the original blog post about this change from Android:

https://medium.com/androiddevelopers/permissionless-is-the-future-of-storage-on-android-3fbceeb3d70a

@triniwiz triniwiz added the enhancement New feature or request label Dec 10, 2024
@felixkrautschuk
Copy link
Contributor

I gave it a short try to show this newer Android PhotoPicker, but as I have not much experience in native Android app development, I am not familiar with the newer "registerForActivityResult" approach.

I was already failing during the first step of creating the imageLauncher.

java.lang.IllegalStateException: LifecycleOwner com.tns.NativeScriptActivity@8d1df04 is attempting to register while current state is RESUMED. LifecycleOwners must call register before they are STARTED

So I tried to move that into the activityCreatedEvent

//app.js
if(application.android) {
    application.android.on(application.AndroidApplication.activityCreatedEvent, function (args) {
        const pickImageLauncher = args.activity.registerForActivityResult(
                new androidx.activity.result.contract.ActivityResultContracts.PickVisualMedia(),
                new androidx.activity.result.ActivityResultCallback({
                    onActivityResult: function(uri) {
                        alert(uri);
                    }
                })
        );

        //just show the PhotoPicker directly after some delay
        setTimeout(() => {
            pickImageLauncher.launch(args.activity, new androidx.activity.result.PickVisualMediaRequest.Builder()
                .setMediaType(androidx.activity.result.contract.ActivityResultContracts.PickVisualMedia.ImageOnly.INSTANCE)
                .build());
        }, 5000);
    });
}

But this crashes with the following message:

java.lang.Exception: Failed resolving method launch on class androidx.activity.result.ActivityResultRegistry$3

Actually registerForActivityResult should return an instance of ActivityResultLauncher, but for some reason I get an instance of ActivityResultRegistry

Maybe somebody with more experience in Android development can help out here.

@asharghi
Copy link
Contributor Author

@triniwiz Is this something you want to tackle?

@BriceFab
Copy link

I'm still experiencing the same issue and haven't found an alternative solution or any open PR addressing this fix.
Any updates on this?

@asharghi
Copy link
Contributor Author

I have just written a short explanation in the description form seen in the screenshot. Haven't been a problem and not getting any warnings for now, but this plugin should definitely be migrated to the new api

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

5 participants