- Home /
How to refresh gallery in Android 9 (2022)?
Hi all!
struggling with updating gallery after adding rendered texture to it for few hours. Know there could find some answers for this question, but unfortunately from android 4, and currently not working...
(+) File is created in right localization, and can check it in FileManager (no issue here!);
(-) Can't force gallery to scan its own file to update it's content. Using this weird code found on stack overflow:
//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://" + m_dataPath + _todayFolder) });
objActivity.Call("sendBroadcast", objIntent);
//REFRESHING THE ANDROID PHONE PHOTO GALLERY IS COMPLETE
this code generating error:
Autoconnected Player AndroidJavaException: java.lang.SecurityException: Permission Denial: not allowed to send broadcast android.intent.action.MEDIA_MOUNTED from pid=9650, uid=10288
Also tried to replace:
android.intent.action.MEDIA_MOUNTED
with:
ACTION_MEDIA_SCANNER_SCAN_FILE
but without result, maybe someone could help with this issue (BTW calling it feature is not option :))
Answer by privatecontractor · Apr 23 at 09:23 AM
if anyone will be looking for answer (find solution by myself):
using (AndroidJavaClass jcUnityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer"))
using (AndroidJavaObject joActivity = jcUnityPlayer.GetStatic<AndroidJavaObject>("currentActivity"))
using (AndroidJavaObject joContext = joActivity.Call<AndroidJavaObject>("getApplicationContext"))
using (AndroidJavaClass jcMediaScannerConnection = new AndroidJavaClass("android.media.MediaScannerConnection"))
using (AndroidJavaClass jcEnvironment = new AndroidJavaClass("android.os.Environment"))
using (AndroidJavaObject joExDir = jcEnvironment.CallStatic<AndroidJavaObject>("getExternalStorageDirectory"))
{
jcMediaScannerConnection.CallStatic("scanFile", joContext, new string[] { _wholestring_pathToFileAndFileNameWithExtension }, null, null);
}
(+) instead of Path inserted string _wholestring_pathToFileAndFileNameWithExtension
Your answer
![](https://koobas.hobune.stream/wayback/20220613055721im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Load image from Android-gallery on OS 5.0.1 0 Answers
Multiple Cars not working 1 Answer
open another app from ours? 2 Answers
Distribute terrain in zones 3 Answers