I have the following code in my app to access PeripheralManagerService
:
PeripheralManagerService service = new PeripheralManagerService();
Gpio
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.
I ran into the same issue but the above solution did not work for me. I was trying to create a alphanumeric display project by choosing new->project and choosing Android Things. The generated gradle build file looked like below. Note the driver for ht16k33 has version 0.3. This caused the problem. Once I changed it to 1.0 the ClassNotFound issue went away.
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.google.android.things.contrib:driver-ht16k33:0.3'
implementation 'com.android.support:support-v4:28.0.0-beta01'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
compileOnly 'com.google.android.things:androidthings:+'
}
Rather than using PeripheralManagerService service = new PeripheralManagerService();
use
PeripheralManager peripheralManager=PeripheralManager.getInstance();