Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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
1
Question by mcpepa · Dec 08, 2015 at 11:59 AM · androidrefreshgallery

How to refresh android gallery

I record a video in unity, I move this video to the DCIM folder in the device, but I can only see the video when I restart the device. I guess that when I turn on my phone it scann the memory, is there a posibility to make that scann affter the video is moved?. I saw post about using unity pluggins and using the "System.IO" but I cant figure it out how to make it work. this looks like doing something, but its not working.

          //REFRESHING THE ANDROID PHONE PHOTO GALLERY IS BEGUN
          AndroidJavaClass classPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
          AndroidJavaObject objActivity = classPlayer.GetStatic<AndroidJavaObject>("currentActivity");        
          AndroidJavaClass classUri = new AndroidJavaClass("android.net.Uri");        
          AndroidJavaObject objIntent = new AndroidJavaObject("android.content.Intent", new object[2]{"android.intent.action.MEDIA_MOUNTED", classUri.CallStatic<AndroidJavaObject>("parse", "file://" + myScreenshotLocation)});        
          objActivity.Call ("sendBroadcast", objIntent);
          //REFRESHING THE ANDROID PHONE PHOTO GALLERY IS COMPLETE

this is also a code from this question but it doesnt work for me http://answers.unity3d.com/questions/200173/android-how-to-refresh-the-gallery-.html

Comment
Add comment
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

3 Replies

· Add your reply
  • Sort: 
avatar image
3
Best Answer

Answer by Hazzanger · Sep 26, 2016 at 12:20 AM

@mcpepa

NOTE: This plugin will refresh the gallery and open it. It is assumed you have already saved the screenshot or image prior to this.

Accessing the gallery from Unity alone can't be done, but using an IDE medium like android studio or Eclipse can. Unity just doesn't have the correct API. So if you open up android studio and create a plugin, there's very little you have to do in unity. Use this link to see a tutorial about making plugins:

http://www.thegamecontriver.com/2015/04/android-plugin-unity-android-studio.html

Now, you can make your own plugin, or just use one that I made:

https://drive.google.com/file/d/0B_oGNe3B4oysNGJuOEN0TGZYNEU/view?usp=sharing

I used the package name of com.vexstarstruck.unity. I don't know if it is necessary for you to do the same. If so, you could just make your own plugin. I highly recommend you learn how to make your own plugins as it will be extremely useful to use the native functions android provides.

Copy this jar file into your Assets/Plugins/Android folder. Then in Unity, when you want to call this plugin, add this code to any script after you save the image:

 AndroidJavaClass unity = new AndroidJavaClass ("com.unity3d.player.UnityPlayer");
 AndroidJavaObject currentActivity = unity.GetStatic<AndroidJavaObject> ("currentActivity");
 currentActivity.Call ("addImageGallery", myScreenshotLocation);

The reason it may not have worked for you is because you did not have the correct plugin naming, function, or package name. Either way, anyone can contact me if you need clarification or extra help.

Comment
Add comment · Show 2 · 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 mcpepa · Sep 26, 2016 at 03:38 AM 0
Share

this means that for IOS I have to use a pluggin created in xcode? thanks for the suggestion and the tutorial links, you rock, I will find a way to make pluggins. :D

avatar image Gopisgs · Sep 25, 2017 at 05:56 AM 0
Share

Hi @Hazzanger i tried your plugin but it was not working for me ,can you give me any idea to do this. Thanks in advance

avatar image
1

Answer by justinMochaRax · Mar 13, 2017 at 04:26 PM

See this: http://stackoverflow.com/questions/21469431/permission-denial-not-allowed-to-send-broadcast-in-android

Just change android.intent.action.MEDIA_MOUNTED into android.intent.action.MEDIA_SCANNER_SCAN_FILE, because ACTION_MEDIA_MOUNTED got locked in KitKat. Thanksfully ACTION_MEDIA_SCANNER_SCAN_FILE still works.

Hope this will help.

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
avatar image
0

Answer by dansyo · Mar 17, 2017 at 10:06 AM

MediaScannerConnection class scans for new files and directories on to gallery .. Check this post for more information http://whats-online.info/science-and-tutorials/135/how-to-save-an-image-to-gallery-in-android-programmatically/

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

7 People are following this question.

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

Related Questions

Android: How to refresh the gallery ? 4 Answers

Save Screenshot and Show it in Gallery (iOS & Android) 3 Answers

[Edited]Access photos from gallery in application (Android) 1 Answer

Screenshot 0 Answers

Saving screencap to android gallery 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