How to reflect screenshots taken on Android into the gallery

Asked 1 years ago, Updated 1 years ago, 100 views

I am using vuforia to create an AR app for Android.

I implemented the camera function in C#, but it will not be reflected in the gallery unless I reseat the SD card or restart the terminal.After researching for about a month, I found out that I needed MediaScan on the Android side, but I'm at a loss because I don't know how to describe it in C#.I have asked various institutions, but none of them have been reflected.

../../../DCIM/Camera/

You need to scan the above folder to reflect the following files in gallery.

string fileName="camera" + System.DateTime.Now.Ticks.ToString() + ".png";
path = path + fileName;

I'm sorry I'm an amateur. If there's a good way, I don't mind just giving you a hint. Could you please let me know?

c# android unity3d

2022-09-30 20:27

3 Answers

MediaScannerConnection.scanFile().

http://techbooster.org/android/multimedia/5341/

On the Activity side of Android, add a method to call MediaScannerConnection.scanFile() and get the Activity object on the C# side and call it.


2022-09-30 20:27

I have posted an implementation on my blog that will only be completed with C#.
I call MediaScannerConnection.scanFile() using AndroidJavaClass and AndroidJavaObject.
http://westhillapps.blog.jp/archives/42570662.html


2022-09-30 20:27

The code for fkm's answer is from Java, and if you confuse it with C#, it will cause an error.

Write a plug-in in Java and call it from the C# side. http://docs-jp.unity3d.com/Documentation/Manual/PluginsForAndroid.html

If you search by the word native plug-in, the information will get stuck.


2022-09-30 20:27

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.