我正在创建一个使用设备串行端口的应用程序。为此,我一直在尝试使用Android中的PeripheralManager。我的清单中列出了适当的权限:
<uses-permission android:name="com.google.android.things.permission.MANAGE_INPUT_DRIVERS" />
<uses-permission android:name="com.google.android.things.permission.USE_PERIPHERAL_IO" />
但是,当我尝试在设备上调试代码时,出现运行时异常:STUB!详细信息如下:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.zebratechnologies.androidfulltest_L10AW, PID: 7783
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.zebratechnologies.androidfulltest_L10AW/com.zebratechnologies.androidfulltest_L10AW.SerialPortTestActivity}: java.lang.RuntimeException: Stub!
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2791)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2869)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1602)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6528)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
Caused by: java.lang.RuntimeException: Stub!
at com.google.android.things.pio.PeripheralManager.getInstance(PeripheralManager.java:21)
at com.zebratechnologies.androidfulltest_L10AW.SerialPortTestActivity.Init(SerialPortTestActivity.java:29)
at com.zebratechnologies.androidfulltest_L10AW.SerialPortTestActivity.onCreate(SerialPortTestActivity.java:22)
at android.app.Activity.performCreate(Activity.java:7026)
at android.app.Activity.performCreate(Activity.java:7017)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1215)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2744)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2869)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1602)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6528)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
这是我要在设备上运行的代码:
import android.app.Activity;
import android.os.Bundle;
import com.google.android.things.pio.PeripheralManager;
import java.util.List;
public class SerialPortTestActivity extends Activity {
PeripheralManager manager;
List<String> deviceList;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Init();
System.out.println(findSerialPorts());
}
protected void Init() {
manager = PeripheralManager.getInstance();
deviceList = manager.getUartDeviceList();
}
public String findSerialPorts() {
if (deviceList.isEmpty()) {
return"No UART port available on this device.";
} else {
return("List of available devices: " + deviceList);
}
}
}
有人知道为什么会这样吗?谢谢您的帮助!