isDeviceConnected static method

Future<bool> isDeviceConnected()

Check if device is connected

Implementation

static Future<bool> isDeviceConnected() async {
  try {
    final result = await Process.run('adb', ['devices']);
    if (result.exitCode == 0) {
      final output = result.stdout as String;
      // Check if there's a device listed (not just "List of devices attached")
      final lines = output.split('\n');
      return lines.any(
        (line) =>
            line.trim().isNotEmpty &&
            !line.contains('List of devices') &&
            !line.contains('daemon'),
      );
    }
    return false;
  } catch (e) {
    return false;
  }
}