Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Android Gallery on Unity3d

Discussion in 'Android' started by hash.triton, Mar 21, 2012.

  1. hash.triton

    hash.triton

    Joined:
    Mar 21, 2012
    Posts:
    4
    Hello, sorry for my bad English, so I decided to use google trantslate.
    The Russian community did not find people who are well able to bind Adnroid SDK + Unity3d. Therefore, I ask you to help.

    I need to open for the event buttonClick Android gallery and select from there the image is uploaded to the application.
    Write a guide so you do not want and use the gallery - this is the best option. Please help with code foreign comrades)

    Thank you very much, and write on the "simple" English))
     
  2. Tseng

    Tseng

    Joined:
    Nov 29, 2010
    Posts:
    1,217
    We're not here to do work for you lol.

    You can just wirte a Gallery activity in Eclipse and make a method to send an intents (Activities and most other stuff is handled via Intents, some kind of message broadcasting). Sending an intent is easy, it's someting like that (in Java)

    Code (csharp):
    1.  
    2. public void shareThis() {
    3.         Intent galleryIntent = new Intent(this, MyGalleryActivity.class);
    4.         startActivity(shareIntent);
    5. }
    6.  
    Call this via JNI from Android. Once a user has selected an image, send the image's path to unity via (java code agan)

    Code (csharp):
    1.  
    2. UnityPlayer.UnitySendMessage("ObjectNameInUnity", "MethodNameInUnity", "/path/to/the/image.png");
    3.  
    In C# you should have a GameObject which contains a script like th is:

    Code (csharp):
    1.  
    2. public class ObjectNameInUnity : MonoBehaviour {
    3.    
    4.     void MethodNameInUnity(string path) {
    5.         // load the image from that path and do something with it
    6.     }
    7. }
    8.  
     
  3. hash.triton

    hash.triton

    Joined:
    Mar 21, 2012
    Posts:
    4
    Just thought anyone has templates, because in principle it is a very broad problem.
    Write to c#
     
  4. Tseng

    Tseng

    Joined:
    Nov 29, 2010
    Posts:
    1,217
    Actually not. I've never seen a game that used it, so it can't be really that broad. You just have to do the steps above, it isn't that hard. Of couse you need some basic knowledge of Android and Android development, otherwise it's quite pointless to make Apps for that platform ;)
     
  5. hash.triton

    hash.triton

    Joined:
    Mar 21, 2012
    Posts:
    4
    Just makes sense that I need a photo on your avatar. And I just do not see any other option but to write a guide or use the gallery
     
  6. Tseng

    Tseng

    Joined:
    Nov 29, 2010
    Posts:
    1,217
    http://www.androidsnippets.com/get-file-path-of-gallery-image

    Here's a quick example on how to use the built-in gallery to select an image and return it's path. 60 seconds worth of googeling and then just send the resulting path to unity.

    If you are unable to use this info buts to implement it, then you probably shouldn't be an developer anyways. You can't expect to copy and paste or follow tutorials for everything and expect to get a Game or App done. You must learn to understand it and implement it yourself, without someone holding on your hand and leading your through each step.
     
    NanduTiger likes this.
  7. hash.triton

    hash.triton

    Joined:
    Mar 21, 2012
    Posts:
    4
    Thanks, very match.
     
  8. zeusrami

    zeusrami

    Joined:
    Dec 12, 2012
    Posts:
    17
    Pixel-Wrangler likes this.
  9. DeveshPandey

    DeveshPandey

    Joined:
    Sep 30, 2012
    Posts:
    221
    Pixel-Wrangler likes this.
  10. Pixel-Wrangler

    Pixel-Wrangler

    Joined:
    Dec 16, 2014
    Posts:
    2
    Thanks, DeveshPandey! Your plugin worked great on Unity 5 for selecting images from the Android gallery.
     
    DeveshPandey likes this.
  11. DeveshPandey

    DeveshPandey

    Joined:
    Sep 30, 2012
    Posts:
    221
    Thanks Pixel, please leave your feedback on assets store too.
     
  12. Voxel-Busters

    Voxel-Busters

    Joined:
    Feb 25, 2015
    Posts:
    1,952
  13. marcosocram

    marcosocram

    Joined:
    Jan 14, 2017
    Posts:
    3
  14. CoopOwnz

    CoopOwnz

    Joined:
    Oct 6, 2016
    Posts:
    74
  15. MSOTech

    MSOTech

    Joined:
    Oct 12, 2013
    Posts:
    3
    :) Interesting way of asking for help
     
  16. vamsikrish229

    vamsikrish229

    Joined:
    Dec 24, 2018
    Posts:
    3
    hello,
    i am unable to load images from a android mobile gallery into my unity application.
    if anyone done this can you please help me..!!
     
  17. domdev

    domdev

    Joined:
    Feb 2, 2015
    Posts:
    375
    same.. :D