Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 11 Next capture
2021 2022 2023
1 capture
11 Jun 22 - 11 Jun 22
sparklines
Close Help
  • 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
0
Question by fusecore · Jul 20, 2015 at 08:31 PM · androidimportintent

How to import a .png using intents on Android?

For my game I want to import and export levels the player has made in the editor.
I've figured out how to do the export from Application.persistentDataPath to Dropbox/gallery using Intents, but cannot seem to find how to receive an image using Intents.

As far as I can tell so far, the basics is the same, but instead of ACTION_SEND I use ACTION_GET_CONTENT, but I have no idea where the image is then sent. All examples I find are for native Android apps and those seem to call a function when an image is selected, but I'm unsure how to deal with this on Android.

Could someone provide some insight?

[edit] So far I seem to need to find out how to call startActivityForResult instead of startActivity, and where/how to override onActivityResult. Everything I find is people writing plugins for Unity, but I'd like to keep it to C# scripts. If I can use intents, then this must be possible too right?

What I have so far:

     void OnMouseDown(){
         AndroidJavaClass intentClass = new AndroidJavaClass ("android.content.Intent");
         AndroidJavaObject intentObject = new AndroidJavaObject ("android.content.Intent");
         
         intentObject.Call<AndroidJavaObject> ("setType", "image/png");
         intentObject.Call<AndroidJavaObject> ("setAction", intentClass.GetStatic<string> ("ACTION_GET_CONTENT"));
         
         AndroidJavaClass unity = new AndroidJavaClass ("com.unity3d.player.UnityPlayer");
         AndroidJavaObject currentActivity = unity.GetStatic<AndroidJavaObject> ("currentActivity");
         
         currentActivity.Call ("startActivityForResult", 
                               intentObject.Call<AndroidJavaObject>(intentClass.CallStatic(    "createChooser", intentObject, "Select picture")), 
                               intentClass.GetStatic<string> ("SELECT_IMAGE"));
     }
 
     void onActivityResult(string resultData){
         //?
     }
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 willoliveira · Jul 23, 2016 at 05:25 PM 0
Share

Tthere is still no solution to the above problem? I have the same problem...

avatar image fusecore willoliveira · Jul 24, 2016 at 10:54 AM 1
Share

I've solved it using this cheap asset: https://www.assetstore.unity3d.com/en/#!/content/38872

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by tarasfromlviv · Jan 07, 2017 at 12:45 PM

Hello guys, to get onActivityResult result callback you will have to write a plugin - there are two ways of achieving this:

  • Overriding`UnityPlayerActivity` and overriding onActivityResult there - I don't recommend it as it most of the times complicates the build process immensely

  • Writing you own activity which handles the onActivityResult callback - launching it, doing the job in onCreate and killing it when the job is done (image passed to the C# code)

I also wrote an article how to do that: https://medium.com/@tarasleskiv/unity-android-plugins-and-onactivityresult-callback-abef4b6bbc87#.53gj04ean

I am using this approach in my plugin exactly for this purpose.

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.

Follow this Question

Answers Answers and Comments

24 People are following this question.

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

Related Questions

Integration of InMobi with HeyZap Mediation 1 Answer

[ANDROID] How can this intent be made in Unity? 0 Answers

Open another app with intent url on Android 1 Answer

Import error from Eclipse with *.jar 0 Answers

how to open app from notification intent 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