Android studio 如何获取USB存储路径?
我正在尝试读取USB OTG存储中的文本文件中的数据,但我无法读取,因为我是Android开发新手。有人能指导我这个过程吗 我尝试了以下库并用简单的方法实现: 这是我的代码:Android studio 如何获取USB存储路径?,android-studio,usb-drive,usb-otg,Android Studio,Usb Drive,Usb Otg,我正在尝试读取USB OTG存储中的文本文件中的数据,但我无法读取,因为我是Android开发新手。有人能指导我这个过程吗 我尝试了以下库并用简单的方法实现: 这是我的代码: package com.numerologysolution.usbplugin; import com.faraji.environment3.Device; import com.faraji.environment3.Environment3; public class HelloWorld { public
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;
}
}
它表示来自JNI的响应无效
这是我的JNI代码:
numerologysolution.Jni.JNIUtil.StaticCall("usb", "Invalid Response From JNI", "com.numerologysolution.usbplugin.HelloWorld");
这是我创建的JNI类:
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;
}
}
}
namespace numerologysolution.Jni
{
公共类JNIUtil
{
公共静态T StaticCall(string methodName、T defaultValue、string androidJavaClass)
{
T结果;
//只适用于Android!
if(Application.platform!=RuntimePlatform.Android)
{
返回默认值;
}
尝试
{
使用(AndroidJavaClass androidClass=新的AndroidJavaClass(AndroidJavaClass))
{
if(null!=androidClass)
{
结果=androidClass.CallStatic(methodName);
}
其他的
{
结果=默认值;
}
}
}
catch(System.Exception-ex)
{
//如果出现异常,只返回默认值
//取消对此的注释以查看Unity调试日志中的异常。。。。
//UnityEngine.Debug.Log(string.Format(“{0}.{1}异常:{2}”,androidJavaClass,methodName,例如ToString());
返回默认值;
}
返回结果;
}
}
}
有谁能为我指明正确的方向吗
提前感谢。您是否尝试过在
catch
块中取消日志消息的注释?还要确保proguard或其他类似工具不会因为未直接使用而删除您的类。确定。我将取消注释并生成一个build,但它什么也没做。事实上,它甚至不允许我在删除注释后进行编译