SHARE
TWEET

Untitled

a guest Jun 19th, 2017 44 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using UnityEngine;
  2. using UnityEngine.UI;
  3. using UnityEngine.Assertions;
  4. using System.Linq;
  5. using System.Collections;
  6. using System.Collections.Generic;
  7.  
  8. using System.IO;
  9.  
  10. public class Android
  11. {
  12.     [System.Diagnostics.Conditional("UNITY_ANDROID")]
  13.     public static void RefreshFiles(string root)
  14.     {
  15.         foreach (string file in Directory.GetFiles(root, "*", SearchOption.AllDirectories))
  16.         {
  17.             RefreshFile (file);
  18.         }
  19.     }
  20.  
  21.     [System.Diagnostics.Conditional("UNITY_ANDROID")]
  22.     public static void RefreshFile(string path)
  23.     {
  24.         #if !UNITY_EDITOR && UNITY_ANDROID
  25.         if (!File.Exists (path))
  26.         {
  27.             return;
  28.         }
  29.            
  30.         using (AndroidJavaClass jcUnityPlayer = new AndroidJavaClass ("com.unity3d.player.UnityPlayer"))
  31.         using (AndroidJavaObject joActivity = jcUnityPlayer.GetStatic<AndroidJavaObject> ("currentActivity"))
  32.         using (AndroidJavaObject joContext = joActivity.Call<AndroidJavaObject> ("getApplicationContext"))
  33.         using (AndroidJavaClass jcMediaScannerConnection = new AndroidJavaClass ("android.media.MediaScannerConnection"))
  34.         jcMediaScannerConnection.CallStatic("scanFile", joContext, new string[] { path }, null, null);
  35.         #endif
  36.     }
  37. }
RAW Paste Data
Top