Exemple #1
0
 public static bool FileWaitingToImport()
 {
     using (var activity = AndroidShare.GetCurrentActivity())
         using (var intent = activity.Call <AndroidJavaObject>("getIntent"))
         {
             if (intent.Call <bool>("hasExtra", "used"))
             {
                 return(false);
             }
             using (var uri = intent.Call <AndroidJavaObject>("getData"))
             {
                 if (uri == null)
                 {
                     return(false);
                 }
                 string uriString = uri.Call <string>("toString");
                 if (uriString == "")
                 {
                     return(false);
                 }
                 Debug.Log("Intent uri " + uriString);
                 Debug.Log("Intent type " + intent.Call <string>("getType"));
                 return(true);
             }
         }
 }
Exemple #2
0
    private static void ReadSharedURL(Stream outputStream)
    {
        using (var activity = AndroidShare.GetCurrentActivity())
            using (var intent = activity.Call <AndroidJavaObject>("getIntent"))
                using (var uri = intent.Call <AndroidJavaObject>("getData"))
                    using (var inputStream = GetInputStreamForURI(uri, activity))
                    {
                        byte[] buffer    = new byte[8192];
                        var    bufferPtr = AndroidJNIHelper.ConvertToJNIArray(buffer);
                        // get the method id of InputStream.read(byte[] b, int off, int len)
                        var      readMethodId = AndroidJNIHelper.GetMethodID(inputStream.GetRawClass(), "read", "([BII)I");
                        jvalue[] args         = new jvalue[3];
                        // construct arguments to pass to InputStream.read
                        args[0].l = bufferPtr;     // buffer
                        args[1].i = 0;             // offset
                        args[2].i = buffer.Length; // length

                        while (true)
                        {
                            int bytesRead = AndroidJNI.CallIntMethod(inputStream.GetRawObject(), readMethodId, args);
                            if (bytesRead <= 0)
                            {
                                break;
                            }
                            byte[] newBuffer = AndroidJNIHelper.ConvertFromJNIArray <byte[]>(bufferPtr);
                            outputStream.Write(newBuffer, 0, bytesRead);
                        }
                        outputStream.Flush();
                    }
    }
Exemple #3
0
 private static string GetImportURI()
 {
     using (var activity = AndroidShare.GetCurrentActivity())
         using (var intent = activity.Call <AndroidJavaObject>("getIntent"))
             using (var uri = intent.Call <AndroidJavaObject>("getData"))
                 return(uri.Call <string>("toString"));
 }
Exemple #4
0
    public static void Share(string filePath)
    {
#if UNITY_ANDROID
        AndroidShare.Share(filePath);
#elif UNITY_IOS
        IOSShare.Share(filePath);
#endif
    }
Exemple #5
0
 public static void OpenFileManager()
 {
     using (AndroidJavaObject activity = AndroidShare.GetCurrentActivity())
         using (AndroidJavaClass downloadManagerClass = new AndroidJavaClass("android.app.DownloadManager"))
             using (AndroidJavaObject intentObject = new AndroidJavaObject("android.content.Intent"))
             {
                 using (intentObject.Call <AndroidJavaObject>("setAction", downloadManagerClass.GetStatic <string>("ACTION_VIEW_DOWNLOADS")))
                 { }
                 activity.Call("startActivity", intentObject);
             }
 }
Exemple #6
0
 public static void ClearFileWaitingToImport()
 {
     using (var activity = AndroidShare.GetCurrentActivity())
         using (var intent = activity.Call <AndroidJavaObject>("getIntent"))
             using (intent.Call <AndroidJavaObject>("putExtra", "used", true))
             { }
     try
     {
         if (tempPath != null)
         {
             File.Delete(tempPath);
         }
         tempPath = null;
     }
     catch (Exception e)
     {
         Debug.LogError(e);
     }
 }
Exemple #7
0
 void Share()
 {
     StartCoroutine(AndroidShare.SaveAndShare(Initializer.Instance.sacrificeCounts.sacrificeCount));
 }