Android library for sending fastboot commands from an Android device to a device running fastboot.
Only supports fastboot over USB On-The-Go (OTG) connections.
Original-Source: https://github.com/google/fastboot-mobile
Add it in your root build.gradle at the end of repositories:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven { url 'https://jitpack.io' }
}
}
Add the dependency
dependencies {
implementation 'com.github.RohitVerma882:fastboot-android:<version>'
}
List Attached Fastboot Devices
// Includes connected devices.
val deviceIds: List<DeviceId> = FastbootDeviceManager.getAttachedDeviceIds()
List Connected Fastboot Devices
val deviceIds: List<DeviceId> = FastbootDeviceManager.getConnectedDeviceIds()
Connect to a Fastboot Device
// typealias DeviceId = String
FastbootDeviceManager.addFastbootDeviceManagerListener(
object : FastbootDeviceManagerListener() {
override fun onFastbootDeviceAttached(deviceId: DeviceId) {
Log.d("Device attached: $deviceId")
}
override fun onFastbootDeviceDetached(deviceId: DeviceId) {
Log.d("Device detached: $deviceId")
}
override fun onFastbootDeviceConnected(
deviceId: DeviceId,
deviceContext: FastbootDeviceContext
) {
// Do some fastboot stuff...
val response = deviceContext.sendCommand(FastbootCommand.getVar("current-slot"))
val bootSlot = response.data
Log.d("Device $deviceId with slot $bootSlot.")
}
})
FastbootDeviceManager.connectToDevice(/* Device Name */ "/dev/bus/usb/001/002")