iOS Question Select photo from library using B4xPages

mcorbeel

Active Member
Licensed User
Longtime User
I am using B4xPages and am struggeling with how to select a photo from the phone's album.
In a previous non-B4xPages project that I made I used:
B4X:
Camera1.Initialize("Camera1", oPage)
Camera1.SelectFromPhotoLibrary(Sender, Camera1.TYPE_ALL)
But "oPage" is a Page object in B4i and I cannot use that with B4xPages.
So how can I solve this? Thanks for the help!
 

mcorbeel

Active Member
Licensed User
Longtime User
Think I found it...
B4X:
Dim p As Page = B4XPages.GetNativeParent(B4XPages.MainPage.Page_GaleryB4i)
Camera1.Initialize("Camera1", p)
Camera1.SelectFromPhotoLibrary(Sender, Camera1.TYPE_ALL)
 
Upvote 0

mcorbeel

Active Member
Licensed User
Longtime User
But when I use (in the B4XPage_Created section):
B4X:
Dim p As Page = B4XPages.GetNativeParent(B4XPages.MainPage.Page_GaleryB4i)
Camera1.Initialize("Camera1", p)
Camera1.SelectFromPhotoLibrary(Sender, Camera1.TYPE_ALL)
I get:
Warning: Attempt to present <UIImagePickerController: 0x180ace00> on Page (vc): Foto kiezen whose view is not in the window hierarchy!
 
Upvote 0

mcorbeel

Active Member
Licensed User
Longtime User
Check this example: https://www.b4x.com/android/forum/threads/b4x-b4xpages-intent-based-camera.120721/

Note that the discussed fix related to the pages stack is no longer needed with the latest version of B4XPages (it will do no harm).
Thank you Erel.
I did examine the suggested solution (https://www.b4x.com/android/forum/threads/b4x-b4xpages-intent-based-camera.120721/) but when I try to install the sample project that is provided on that page I cannot install it. My android phone just says "App not installed" without any other error logging. What could be the resaon for this?
 
Upvote 0

mcorbeel

Active Member
Licensed User
Longtime User
I now copied the code from the sample project in my own project and there it works fine... Nice solution btw...
 
Upvote 0

mcorbeel

Active Member
Licensed User
Longtime User
I have just noticed that I mixed 2 things together in this post, (1) taking a picture and (2) selecting a picture from the galery. Sorry for that. The Intent-based camera sample was indeed a nice solution for the 1st issue, but my post originally was created for the selection of a picture from the galery in B4i. So can we revert to this issue?
I have made this in the past using the "ALAssets" library that I found on this forum, but a lot of users reported problems with that. So I want to do this with the camera SelectFromPhotoLibrary function but I cannot get this to work. I use:
B4X:
Dim p As Page = B4XPages.GetNativeParent(B4XPages.MainPage.Page_GaleryB4i)
Camera1.Initialize("Camera1", p)
Camera1.SelectFromPhotoLibrary(Sender, Camera1.TYPE_ALL)
but all I get is a black screen.
 
Upvote 0

mcorbeel

Active Member
Licensed User
Longtime User
I didn't realize that the Intent-based sample was also the solution for selecting an image from library, hence the confusion. I tried your suggestion and it works perfectly!
 
Upvote 0
Top