Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Native Gallery for Android & iOS [Open Source]

Discussion in 'Assets and Asset Store' started by yasirkula, Feb 28, 2018.

  1. amp3670

    amp3670

    Joined:
    Apr 1, 2020
    Posts:
    10
    Thank you for your help a lot. your plugin is very helpful and useful to me!
     
  2. GameArt

    GameArt

    Joined:
    Feb 24, 2013
    Posts:
    86
    Awesome package, worked for saving images to the gallery right out of the box on iOS with no setup.
    One question I have is, can this package emulate the 'capture screenshot' function built into the OS? With the latest iOS when you press the two side buttons to capture a system screenshot it brings up a preview of the image in the bottom left hand corner, you can then edit this preview or upload it somewhere else before saving. This functionality is what I'm after.
     
  3. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,783
    I don't think this plugin would help with that. A quick google search didn't yield a result for taking a previewable screenshot programmatically, instead of using the two side buttons.
     
  4. GameArt

    GameArt

    Joined:
    Feb 24, 2013
    Posts:
    86
    I saw the new google AR animal preview feature does it, so it must be possible. But I also came up empty searching for how to do it.
     
  5. makaka-org

    makaka-org

    Joined:
    Dec 1, 2013
    Posts:
    873
    Try to add opportunity to load your package from git with Unity Package Manager.

    I got this :
    Cannot perform upm operation: Unable to add package [https://github.com/yasirkula/UnityNativeGallery.git]:
    [https://github.com/yasirkula/UnityNativeGallery.git] does not point to a valid package repository. No package manifest was found. Verify the repository URL and make sure the package is located in the root folder of the repository. [NotFound]
    UnityEditor.EditorApplication:Internal_CallUpdateFunctions() (at /Users/builduser/buildslave/unity/build/Editor/Mono/EditorApplication.cs:310)
     
    yasirkula likes this.
  6. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,783
    Yes, my plugins currently don't support UPM but as you suggested, I'm planning to support UPM as soon as possible.
     
    makaka-org likes this.
  7. naagi

    naagi

    Joined:
    Nov 27, 2014
    Posts:
    13
    @yasirkula thank you very much for your plug in sir, this one help me alot on my project
     
    yasirkula and makaka-org like this.
  8. swifter14

    swifter14

    Joined:
    Mar 2, 2017
    Posts:
    165
    Hey there, I use your example code to upload images from the gallery to my cloud,
    Texture2D texture = NativeGallery.LoadImageAtPath( path, maxSize );
    The saved texture I upload to my cloud, very simple.
    But what about videos?
    In the example code there's only one option to play the video from the path, but how do we actually get the video file?
    What's the equivalent function of LoadImageAtPath with a video?
    I want to get the video reference and upload it to my cloud like I do with textures
    Thanks!
     
  9. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,783
    GetImageFromGallery and GetVideoFromGallery return the path of the selected media file. So you can upload that file directly. I don't think you need to call LoadImageAtPath beforehand, simply uploading the file itself should be sufficient.
     
  10. ryujm

    ryujm

    Joined:
    Mar 17, 2020
    Posts:
    3
    Hello, first thank you for your asset. It's amazing!!
    I want to do the same thing as the one in this article.
    But I don't know well about modifying the Android source code..
    I saw the post, but I didn't understand it ...
    Can you tell me more specifically how to change the source code and rebuild the library??
    Thank you!!
     
    Last edited: Apr 23, 2020
  11. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,783
  12. ryujm

    ryujm

    Joined:
    Mar 17, 2020
    Posts:
    3
    Thank you for your reply!!
    I follow the tutorial you told me, and there is a problem.
    As you can see in the picture, there are many errors....
    Do you know what the problem is?
    I'd appreciate it if you could help me one more time.
    Thank you so much..
     

    Attached Files:

  13. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,783
    Hmm, you can try Android Library then. After building the library, you can find the .jar file at
    PROJECT_PATH\app\build\intermediates\bundles\debug\classes.jar
    , simply rename it as NativeGallery.jar and replace the original one. If it doesn't work, I'd recommend you to create a thread here or google "unity android studio jar" since I don't really give support for building an Android library.
     
    jmyoo555 likes this.
  14. ryujm

    ryujm

    Joined:
    Mar 17, 2020
    Posts:
    3
    Thank you for your answer again.
    I tried Android Library and the way you told me, and I succeeded!!
    Thank you very much:):)
     
  15. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,783
    Glad it worked :)
     
  16. AcuityCraig

    AcuityCraig

    Joined:
    Jun 24, 2019
    Posts:
    55
    Hello,
    This plugin seems to cause Unity Cloud build to fail iOS builds. See error below -
    Code (CSharp):
    1. ;️  /BUILD_PATH/acuitycraig.augmented-reality-experience.dqa9msju6/temp20200428-6174-1uch447/Libraries/Plugins/NativeGallery/iOS/NativeGallery.mm:555:40: 'requestImageDataAndOrientationForAsset:options:resultHandler:' is only available on iOS 13 or newer [-Wunguarded-availability-new]
    2. 3371:                                                 [[PHImageManager defaultManager] requestImageDataAndOrientationForAsset:asset options:options resultHandler:^(NSData *imageData, NSString *dataUTI, CGImagePropertyOrientation orientation, NSDictionary *imageInfo) {
    3. 3372: ▸ Linking UnityFramework
    4. 3373:;  ld: could not reparse object file in bitcode bundle: 'Invalid bitcode version (Producer: '1103.0.32.29.0_0' Reader: '1100.0.33.12_0')', using libLTO version 'LLVM version 11.0.0, (clang-1100.0.33.12)' for architecture arm64
    5. 3374:;  clang: error: linker command failed with exit code 1 (use -v to see invocation)
    6. 3375: ** ARCHIVE FAILED **
    Any idea how i could fix this?
     
  17. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,783
  18. AcuityCraig

    AcuityCraig

    Joined:
    Jun 24, 2019
    Posts:
    55
    As this is an ARFoundation project I'd hate to target iOS 13 instead of 11. I'll try removing those lines and see if it works. If not I'll try to target 13. Thank you so much for the help!
     
    yasirkula likes this.
  19. AcuityCraig

    AcuityCraig

    Joined:
    Jun 24, 2019
    Posts:
    55
    I removed the lines you mentioned and still no luck. Full log view below. Any other thoughts?

    Code (CSharp):
    1.  
    2. 3066: ▸ ⚠;️  /BUILD_PATH/acuitycraig.augmented-reality-experience.dqa9msju6/temp20200428-3908-s59tdh/Libraries/Plugins/NativeGallery/iOS/NativeGallery.mm:328:13: 'UIPopoverController' is deprecated: first deprecated in iOS 9.0 - UIPopoverController is deprecated. Popovers are now implemented as UIViewController presentations. Use a modal presentation style of UIModalPresentationPopover and UIPopoverPresentationController. [-Wdeprecated-declarations]
    3. 3067: ▸                 popup = [[UIPopoverController alloc] initWithContentViewController:imagePicker];
    4. 3068: ▸ Linking UnityFramework
    5. 3069: ▸ ❌;  ld: could not reparse object file in bitcode bundle: 'Invalid bitcode version (Producer: '1103.0.32.29.0_0' Reader: '1100.0.33.17_0')', using libLTO version 'LLVM version 11.0.0, (clang-1100.0.33.17)' for architecture arm64
    6. 3070: ▸ ❌;  clang: error: linker command failed with exit code 1 (use -v to see invocation)
    7. 3071:** ARCHIVE FAILED **
    8. 3072: ▸ The following build commands failed:
    9. 3073: ▸     Ld /BUILD_PATH/Library/Developer/Xcode/DerivedData/Unity-iPhone-dtnsqloarjworogomrzittqhnits/Build/Intermediates.noindex/ArchiveIntermediates/Unity-iPhone/IntermediateBuildFilesPath/UninstalledProducts/iphoneos/UnityFramework.framework/UnityFramework normal arm64
    10. 3074:(1 failure)
    11.  
     
  20. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,783
    Does the cloud build succeed if you delete NativeGallery from your project? If so, can you attach your final NativeGallery.mm file here? But please try deleting NativeGallery first since I'm not sure if this issue is caused by NativeGallery.
     
  21. AcuityCraig

    AcuityCraig

    Joined:
    Jun 24, 2019
    Posts:
    55
    I deleted the nativegallery folder and commented out my code that used it. I still get the error - I made the assumption it was this plugin because its the only plugin that has a post processing behavior for unity cloud build. Did i delete all the files correctly (Just the native gallery folder) or is there more in other folders of the project?

    Code (CSharp):
    1. Linking UnityFramework
    2. 3088: ▸ ❌;  ld: could not reparse object file in bitcode bundle: 'Invalid bitcode version (Producer: '1103.0.32.29.0_0' Reader: '1100.0.33.17_0')', using libLTO version 'LLVM version 11.0.0, (clang-1100.0.33.17)' for architecture arm64
    3. 3089: ▸ ❌;  clang: error: linker command failed with exit code 1 (use -v to see invocation)
    4. 3090:** ARCHIVE FAILED **
     
  22. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,783
    Yes, deleting the NativeGallery folder should remove NativeGallery from your project completely. This shouldn't be caused by NativeGallery.
     
  23. AcuityCraig

    AcuityCraig

    Joined:
    Jun 24, 2019
    Posts:
    55
    Back to the drawing board. Thanks for the help!
     
    yasirkula likes this.
  24. YoungRichi

    YoungRichi

    Joined:
    Apr 19, 2018
    Posts:
    14
    Hey. Thank you for sharing this.
    I got a question. Maybe you can help me.
    I am trying to take a screenshot on my iPhone. I already granted the app access to my photo library.
    I get this error message when i call the screenshot function on my iPhone:
    ArgumentException( "Parameter 'album' is null or empty!" );

    https://github.com/yasirkula/UnityNativeGallery/blob/master/Plugins/NativeGallery/NativeGallery.cs
    From Line 349 or 379 here.

    Do you happen to know why? What am i missing here?

    EDIT::
    Ok i figured it out. I didn't set up the Album name properly :oops:
     
    Last edited: Apr 29, 2020
    yasirkula likes this.
  25. Chenfrank

    Chenfrank

    Joined:
    Mar 25, 2015
    Posts:
    14
    Hello, I have a question to ask you

    I use this

    NativeGallery.Permission states =
    NativeGallery.SaveImageToGallery(byte[],Application.productName,“ Image.png”,mediaSaveCallback =>
    {

    });
    states = Denied!
    I have confirmed that the permissions of the phone are open

    I use unity version: 2019.2.21
    mobile: samsung galaxy a20
     
  26. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,783
    Is Storage permission listed in the permissions list in Settings?
     
  27. Chenfrank

    Chenfrank

    Joined:
    Mar 25, 2015
    Posts:
    14
    yes~
     
  28. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,783
  29. Chenfrank

    Chenfrank

    Joined:
    Mar 25, 2015
    Posts:
    14
  30. Chenfrank

    Chenfrank

    Joined:
    Mar 25, 2015
    Posts:
    14
    Thank you for your patient answers
    I found a way myself

    Add less tools: node = "replace


    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" tools:node="replace" />
     
  31. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,783
    I'm glad it is working. I've seen this answer before and guessed that it would force add a missing Storage permission to AndroidManifest, but since you've said that the Storage permission was already there, I have no clue what difference
    tools:node="replace"
    makes to the built APK, it is like a magic solution to me now :p
     
  32. Chenfrank

    Chenfrank

    Joined:
    Mar 25, 2015
    Posts:
    14
    I also feel amazing!:)
     
  33. WahoPlay

    WahoPlay

    Joined:
    May 31, 2016
    Posts:
    5
    i am getting error when i try to load image from device using GetImageFromGallery, the error is filenotfound exception and it comes at this line:
    imageSet = NativeGallery.LoadImageAtPath(paths.ToString());
    Pls help!
     
  34. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,783
    Assuming that you are using GetImagesFromGallery, paths contains a string array (string[]) whereas LoadImageAtPath doesn't automagically work with string arrays. You need to iterate over the paths array and call LoadImageAtPath for each path separately.
     
  35. unityplayer20202020

    unityplayer20202020

    Joined:
    May 6, 2020
    Posts:
    1
    It is a great plugin. I implemented it.
    But I find a problem, the image I upload is not its own color. Is there anything else I need to set?
     

    Attached Files:

  36. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,783
    Probably caused by lighting. Try using an Unlit shader or assigning the Texture to a RawImage.
     
  37. Mandelboxed

    Mandelboxed

    Joined:
    Apr 17, 2015
    Posts:
    50
    Hi, I am interested in using this asset to read image and video metadata in order to correctly display media in a VR app. The catch is that videos are streamed over http and other metadata solutions I've looked at cannot read the orientation without fully downloading the file. Is it possible to read metadata over http using this asset?
     
  38. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,783
    NativeGallery uses native functions that take a file path parameter, so it won't work in your case.
     
  39. m4kvrstudios

    m4kvrstudios

    Joined:
    Jan 21, 2020
    Posts:
    10
    Great work yasirkula! It works nicely on my S10, how ever tried it on some older phones and it wont save to gallery is there a minimum android api level ?
     
  40. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,783
    There isn't. Does the photo appear in Gallery after restarting the device? Are there any meaningful error messages in logcat? Can the file be seen in Storage/DCIM/AlbumName folder when using file explorer?
     
  41. m4kvrstudios

    m4kvrstudios

    Joined:
    Jan 21, 2020
    Posts:
    10
    So I tried this on two separate old samsungs and the image does not save to gallery even after restart. I cant find any meaningful messages in logcat although logcat is new to me since I usually don't work on android.
    blank images/broken files with the correct name shows up at Storage/DCIM/AlbumName.
     
  42. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,783
    It would be nice to intercept an error message in logcat. Can you try deleting the NativeGallery folder and then installing an older version from this link to see if the issue occurs in the old versions, as well?
     
  43. m4kvrstudios

    m4kvrstudios

    Joined:
    Jan 21, 2020
    Posts:
    10
    I will try the older version tomorrow if I can't figure out the issue.
    The log is massive and I'm new to it as I said so here is a chunk of it (verbose)
     
    Last edited: May 14, 2020
  44. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,783
    I couldn't see anything useful either. Perhaps the source image itself is broken on those older Android versions? If you are trying to save another plugin's output image to Gallery, then the other plugin might be the faulty one here. You can save the source image to Application.temporaryCachePath to see if it is a valid image.

    P.S. I'd recommend you to include the file's extension to NativeGallery's filename parameter, as well.
     
  45. m4kvrstudios

    m4kvrstudios

    Joined:
    Jan 21, 2020
    Posts:
    10
    Sorry for all the questions but another issue I ran into is loading the first image from the gallery without prompting the user to pick one, is this possible?
     
  46. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,783
    Unless you know the absolute path of the image, it is not possible.
     
  47. Laguz

    Laguz

    Joined:
    Sep 27, 2014
    Posts:
    1
    Hello, this is a good asset :)

    i have a issue, "Undefined symbols for architecture armv7, arm64" for xcode build
    • _kUTTypeVideo / NativeGallery.o
    • OBJC_CLASS$_PHAssetCollection / NativeGallery.o
    • OBJC_CLASS$_PHPhotoLibrary / NativeGallery.o
    i have check up, this AssetsLibrary.framwork in Xcode General -> TARGETS : UnityFramework, Frameworks and Libraries : AssetsLibrary.framework
     
  48. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,783
    Can you check if Photos and MobileCoreServices frameworks are also added there?
     
  49. swifter14

    swifter14

    Joined:
    Mar 2, 2017
    Posts:
    165
    My app gets restarted when using GetImageFromGallery on Galaxy S8. The app restarted every time I try to load a pic from my gallery, sometimes it works sometimes it doesn't
    I don't even try to load a texture just to get the path,
    The function starts, then I choose a pic from my gallery click on it and then the app restarts

    Code (CSharp):
    1. NativeGallery.Permission permission = NativeGallery.GetImageFromGallery((path) =>
    2.         {
    3.           if (path != null)
    4.             {
    5.        
    6.                 Debug.Log("Image path: " + path);
    7.  
    8.                 NativeGallery.ImageOrientation ImageOrientation = NativeGallery.GetImageProperties(path).orientation;
    9.                 string or = ImageOrientation.ToString();
    10.        }
    11.         }, "Select a PNG image", "image/png");
    12.  
    13.         Debug.Log("Permission result: " + permission);
     
    Last edited: Jun 1, 2020
  50. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,783
    S8 is a powerful device but perhaps there are lots of apps running in the background (or your app is using too much RAM) which results in insufficient RAM. All occurrences of these inconsistent restarts I've seen so far were caused by the OS killing Unity activity due to very high RAM usage.

    Android Studio's memory profiler might be useful to see how much RAM your app is using. You can also check logcat for any meaningful error messages, but I don't think you will see anything NativeGallery related since this crash isn't reproduced all the time.