• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by n06rin · Sep 14, 2015 at 10:31 AM · androidunity 5imageloadgallery

pick image from android gallery

Hello. I'm searching a way to load image from android gallery. I'm found that: http://answers.unity3d.com/questions/537476/open-gallery-android.html

but it is just open gallery. After a little work I simple modified it:

  public void OpenAndroidGallery()
     {
         #region [ Intent intent = new Intent(); ]
         //instantiate the class Intent
         AndroidJavaClass intentClass = new AndroidJavaClass("android.content.Intent");
         
              //instantiate the object Intent
              AndroidJavaObject intentObject = new AndroidJavaObject("android.content.Intent");
         #endregion [ Intent intent = new Intent(); ]
 
 
         #region [ intent.setAction(Intent.ACTION_GET_CONTENT); ]
         //call setAction setting ACTION_SEND as parameter
         intentObject.Call<AndroidJavaObject>("setAction", intentClass.GetStatic<string>("ACTION_GET_CONTENT"));
         #endregion [ intent.setAction(Intent.ACTION_GET_CONTENT); ]
 
 
         #region [ intent.setData(Uri.parse("content://media/internal/images/media")); ]
         //instantiate the class Uri
         AndroidJavaClass uriClass = new AndroidJavaClass("android.net.Uri");
 
         //instantiate the object Uri with the parse of the url's file
         AndroidJavaObject uriObject = uriClass.CallStatic<AndroidJavaObject>("parse", "content://media/internal/images/media");
 
         //call putExtra with the uri object of the file
         intentObject.Call<AndroidJavaObject>("putExtra", intentClass.GetStatic<string>("EXTRA_STREAM"), uriObject);
         #endregion [ intent.setData(Uri.parse("content://media/internal/images/media")); ]
         
              //set the type of file
              intentObject.Call<AndroidJavaObject>("setType", "image/jpeg");
 
         #region [ startActivityForResult(intent , 1); ]
         //instantiate the class UnityPlayer
         AndroidJavaClass unity = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
 
         //instantiate the object currentActivity
         AndroidJavaObject currentActivity = unity.GetStatic<AndroidJavaObject>("currentActivity");
         
              //call the activity with our Intent
              currentActivity.Call("startActivity", intentObject);
         #endregion [ startActivityForResult(intent , 1); ]
     }

Now it open gallery and I can choose image. Look at the last region. But how I can use it as a texture for example? How catch uri of image?

I think I can use some of unity assets, but now I try to implement it without assets. And I hope it would be interesting for other beginners.

Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image dragonapp · Sep 16, 2015 at 12:25 PM 0
Share

Yeh I have the same problem :/ have someone a result ??

avatar image dakotapearl · Jun 24, 2017 at 09:16 AM 0
Share

Did anyone find a solution to this? I would really like to know. Thanks!

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by pafla · Sep 16, 2015 at 01:48 PM

For an ordinary Android App, the results would be returned via the onActivityResult() callback function. So your Activity needs to override that function. The best way to accomplish that is to write a Java Plugin. The PlugIn could for instance extend the UnityPlayerActivity, override onActivityResult(), obtain the uri and send it to your Unity Code. Instructions on how to do this can be found in the docs. http://docs.unity3d.com/Manual/PluginsForAndroid.html

You could also move all your image loading code to Java, which would be a lot cleaner.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image DeveshPandey · Jan 06, 2017 at 06:12 PM 0
Share

Check this blog.

http://unitydevelopers.blogspot.com/2015/05/image-video-and-contact-picker-image.html

And this plugin https://assetstore.unity.com/packages/tools/integration/image-and-video-picker-28597?aid=1101l34jr

avatar image
1

Answer by Hoangndbk · Mar 08, 2018 at 07:28 AM

That's all you need :)) unimgpicker

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

8 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to load image from android gallery 0 Answers

Load Image from local folder on Android not working 2 Answers

Image Not Sharing after Oreo version? 0 Answers

How to save an in game screenshot directly to gallery? 1 Answer

Download Image to a new album (Android) 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges