0

I am trying to read the data in a text file inside my USB OTG storage but I am not able to do it as I am new to Android development. Can anyone guide me with the process?

I tried the following library and implemented in a simple method: This library

This is my code:

package com.numerologysolution.usbplugin;
import com.faraji.environment3.Device;
import com.faraji.environment3.Environment3;

 public class HelloWorld {

public static Device[] usb()
 {
    Device[] devices = Environment3.getDevices(null, true, true, false);
    return devices;
 }
}

It says Invalid response from JNI This is my JNI code:

numerologysolution.Jni.JNIUtil.StaticCall("usb", "Invalid Response From JNI", "com.numerologysolution.usbplugin.HelloWorld");

This is JNI class I created:

namespace numerologysolution.Jni
 {
   public class JNIUtil 
   {
     public static T StaticCall<T>(string methodName, T defaultValue, string androidJavaClass)
    {
        T result;

        // Only works on Android!
        if (Application.platform != RuntimePlatform.Android)
        {
            return defaultValue;
        }

        try
        {
            using (AndroidJavaClass androidClass = new AndroidJavaClass(androidJavaClass))
            {
                if (null != androidClass)
                {
                    result = androidClass.CallStatic<T>(methodName);
                }
                else
                {
                    result = defaultValue;
                }

            }
        }
        catch (System.Exception ex)
        {
            // If there is an exception, do nothing but return the default value
            // Uncomment this to see exceptions in Unity Debug Log....
            // UnityEngine.Debug.Log(string.Format("{0}.{1} Exception:{2}", androidJavaClass, methodName, ex.ToString() ));
            return defaultValue;
        }

        return result;
      }
    }   
  }

Can anyone guide me in the right direction regarding this?

Thanks in advance.

0 Answers0