PeripheralManagerService throws NoClassDefFoundError

后端 未结 3 713
[愿得一人]
[愿得一人] 2020-12-11 18:56

I have the following code in my app to access PeripheralManagerService:

PeripheralManagerService service = new PeripheralManagerService();
Gpio          


        
3条回答
  •  情话喂你
    2020-12-11 19:32

    Starting in Preview 7, Android Things API services are not constructed as new instances. They are instead accessed as singletons via getInstance() to be more in line with Android API paradigms. Some of the classes, such as PeripheralManagerService were also renamed.

    Be sure to update your app to use the Preview 7 SDK:

    dependencies {
        compileOnly 'com.google.android.things:androidthings:0.7-devpreview'
    }
    

    Then modify your code to access the PeripheralManager instead:

    PeripheralManager manager = PeripheralManager.getInstance();
    Gpio ledGpio;
    try {
        ledGpio = manager.openGpio("BCM6");
        ledGpio.setDirection(Gpio.DIRECTION_OUT_INITIALLY_LOW);
    } catch (IOException e) {
        Log.e(TAG, "Error configuring GPIO pins", e);
    }
    

    Review the Android Things API reference to verify if any of the other APIs you are calling have changed.

提交回复
热议问题