Getting Started with Android Things on Raspberry Pi 3: Installation, Hardware Setup, and a Sample Blink Project
This tutorial explains what Android Things is, guides you through preparing a Raspberry Pi 3, flashing the Android Things image, wiring an LED circuit, and running a sample Blink application that uses a SeekBar to control GPIO‑driven LED blinking.
Android Things is Google’s IoT operating system that lets Android developers build hardware devices using familiar Android tools; it runs on devices such as Raspberry Pi 3, smart speakers, and cameras, and supports a subset of Android APIs like Firebase and Maps.
The article first introduces the Raspberry Pi 3 hardware specifications and lists the required peripherals (power supply, HDMI cable, SD card, network cable, etc.) before describing the step‑by‑step process of downloading the Android Things system image, flashing it to an SD card with Win32DiskImager, and booting the board.
After the board is up, the guide shows how to connect to it via adb , then walks through importing the official sample‑simplepio project in Android Studio, focusing on the blink module.
The core of the demo is the BlinkActivity.java file, which creates a SeekBar UI to adjust the LED blinking interval, opens a GPIO pin with PeripheralManagerService , and toggles the pin state in a recurring Runnable . Key code excerpts are:
public class BlinkActivity extends Activity {
private static final String TAG = BlinkActivity.class.getSimpleName();
private int interval_between_blinks_ms = 1000;
private SeekBar mSeekbar;
private TextView mSeekbarValue;
private Handler mHandler = new Handler();
private Gpio mLedGpio;
...
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.blink_activity);
mSeekbar = findViewById(R.id.seekBar);
mSeekbar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { ... });
PeripheralManagerService service = new PeripheralManagerService();
String pinName = BoardDefaults.getGPIOForLED();
mLedGpio = service.openGpio(pinName);
mLedGpio.setDirection(Gpio.DIRECTION_OUT_INITIALLY_LOW);
mHandler.post(mBlinkRunnable);
}
private Runnable mBlinkRunnable = new Runnable() {
public void run() {
if (mLedGpio == null) return;
mLedGpio.setValue(!mLedGpio.getValue());
mHandler.postDelayed(this, interval_between_blinks_ms);
}
};
}The corresponding layout file blink_activity.xml defines a vertical LinearLayout containing the SeekBar and a TextView to display the current interval:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<SeekBar
android:id="@+id/seekBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:max="1000"
android:progress="1000" />
<TextView
android:id="@+id/seekBar_value"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:textSize="30dp" />
</LinearLayout>Finally, the article lists the required SDK tools (Android Studio 2.4+, SDK API 24+), shows screenshots of a successful build and runtime on the Raspberry Pi display, and invites readers to follow the author’s public account for more Android Things content.
Qunar Tech Salon
Qunar Tech Salon is a learning and exchange platform for Qunar engineers and industry peers. We share cutting-edge technology trends and topics, providing a free platform for mid-to-senior technical professionals to exchange and learn.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.