我试图让 android ADK 在我的活动的另一个包中的库中工作,为此我需要各种权限/实例。我尝试将活动上下文传递给函数,然后运行:
public void setup(Context context)
{
mManager = UsbManager.getInstance(context);
UsbAccessory[] accessoryList = mManager.getAccessoryList();
PendingIntent mPermissionIntent = PendingIntent.getBroadcast(context, 0,
new Intent(ACTION_USB_PERMISSION), 0);
IntentFilter filter = new IntentFilter(ACTION_USB_PERMISSION);
context.registerReceiver(mUsbReceiver, filter);
mManager.requestPermission(accessoryList[0], mPermissionIntent);
if (accessoryList[0] != null) {
mAccessory = accessoryList[0];
openAccessory(mAccessory);
}
}
但这会使应用程序崩溃,即使除了第一行之外的所有内容都被注释掉了。我不完全确定我做错了什么,并希望得到任何帮助......(该函数被调用并传递“this”)