Flutter Android Bindings

Project license Pub package Dartdoc reference Travis CI build status

This is a Flutter plugin for using Android's numerous platform-specific APIs in Flutter apps.

Features

  • Implements bindings to a growing set of Android's platform-specific APIs.

  • Reduces duplication of effort by centralizing Android bindings in a single package.

Feature Table

FeatureFlutter API
Bluetooth scanningandroid_bluetooth.BluetoothLeScanner
Face detectionandroid_media.FaceDetector
Distance calculationandroid_location.Location.distanceBetween()
Heart-rate monitoringandroid_hardware.SensorManager.getDefaultSensor()
Sensor event streamsandroid_hardware.Sensor#subscribe()

Compatibility

Android only.

Examples

Face detection

import 'package:flutter_android/android_graphics.dart' show Bitmap;
import 'package:flutter_android/android_media.dart' show Face, FaceDetector;

var photo = Image.asset("images/einstein.png");

var bitmap = Bitmap.fromAssetImage(photo.image as AssetImage);
var detector = FaceDetector(width: 280, height: 396);

for (var face in await detector.findFaces(bitmap)) {
  if (face.confidence < Face.CONFIDENCE_THRESHOLD) {
    continue; // skip dubious results below the cut-off threshold
  }
  print("Found a face at (${face.midPoint.x}, ${face.midPoint.y}) with confidence ${face.confidence}");
}

Heart-rate monitoring

import 'package:flutter_android/android_hardware.dart'
    show Sensor, SensorEvent, SensorManager;

var sensor = await SensorManager.getDefaultSensor(Sensor.TYPE_HEART_RATE);

var events = await sensor.subscribe();
events.listen((SensorEvent event) {
  print(event.values[0]);
});

Frequently Asked Questions

TODO

Caveats

  • iOS is not and cannot be supported. All flutter_android APIs throw an AssertionError if they are invoked when running on iOS. For cross-platform apps, we recommend that you depend on the platform package to conditionalize your use of Android APIs.

Reference

android

import 'package:flutter_android/android.dart' as android;

android_app

import 'package:flutter_android/android_app.dart' as android_app;

android_bluetooth

import 'package:flutter_android/android_bluetooth.dart' as android_bluetooth;

android_content

import 'package:flutter_android/android_content.dart' as android_content;

android_database

import 'package:flutter_android/android_database.dart' as android_database;

android_graphics

import 'package:flutter_android/android_graphics.dart' as android_graphics;

android_hardware

import 'package:flutter_android/android_hardware.dart' as android_hardware;

android_location

import 'package:flutter_android/android_location.dart' as android_location;

android_media

import 'package:flutter_android/android_media.dart' as android_media;

android_os

import 'package:flutter_android/android_os.dart' as android_os;

Cross-Reference

AndroidFlutter
android.appandroid_app
android.app.Activityandroid_app.Activity
android.app.ActivityManagerandroid_app.ActivityManager
android.app.AlarmManagerandroid_app.AlarmManager
android.app.AuthenticationRequiredExceptionandroid_app.AuthenticationRequiredException
android.app.DownloadManagerandroid_app.DownloadManager
android.app.KeyguardManagerandroid_app.KeyguardManager
android.app.Notificationandroid_app.Notification
android.app.Notification.Actionandroid_app.NotificationAction
android.app.Notification.Builderandroid_app.NotificationBuilder
android.app.NotificationManagerandroid_app.NotificationManager
android.app.PendingIntentandroid_app.PendingIntent
android.app.SearchManagerandroid_app.SearchManager
android.app.WallpaperColorsandroid_app.WallpaperColors
android.app.WallpaperInfoandroid_app.WallpaperInfo
android.app.WallpaperManagerandroid_app.WallpaperManager
android.bluetoothandroid_bluetooth
android.bluetooth.BluetoothAdapterandroid_bluetooth.BluetoothAdapter
android.bluetooth.BluetoothDeviceandroid_bluetooth.BluetoothDevice
android.bluetooth.BluetoothHeadsetandroid_bluetooth.BluetoothHeadset
android.bluetooth.BluetoothManagerandroid_bluetooth.BluetoothManager
android.bluetooth.le.BluetoothLeScannerandroid_bluetooth.BluetoothLeScanner
android.bluetooth.leandroid_bluetooth
android.contentandroid_content
android.content.ActivityNotFoundExceptionandroid_content.ActivityNotFoundException
android.content.ComponentNameandroid_content.ComponentName
android.content.ContentValuesandroid_content.ContentValues
android.content.Contextandroid_content.Context
android.content.Intentandroid_content.Intent
android.content.IntentFilterandroid_content.IntentFilter
android.content.SharedPreferencesandroid_content.SharedPreferences
android.databaseandroid_database
android.database.Cursorandroid_database.Cursor
android.database.CursorIndexOutOfBoundsExceptionandroid_database.CursorIndexOutOfBoundsException
android.database.DatabaseUtilsandroid_database.DatabaseUtils
android.database.MatrixCursorandroid_database.MatrixCursor
android.database.SQLExceptionandroid_database.SQLException
android.graphicsandroid_graphics
android.graphics.Bitmapandroid_graphics.Bitmap
android.graphics.Colordart-ui.Color
android.graphics.Pointandroid_graphics.Point
android.graphics.PointFandroid_graphics.PointF
android.graphics.drawable.Iconflutter.Icon
android.hardwareandroid_hardware
android.hardware.Sensorandroid_hardware.Sensor
android.hardware.SensorEventandroid_hardware.SensorEvent
android.hardware.SensorEventListenerandroid_hardware.SensorEventListener
android.hardware.SensorManagerandroid_hardware.SensorManager
android.locationandroid_location
android.location.Locationandroid_location.Location
android.mediaandroid_media
android.media.FaceDetectorandroid_media.FaceDetector
android.media.FaceDetector.Faceandroid_media.Face
android.netandroid_net
android.nfcandroid_nfc
android.osandroid_os
android.os.BatteryManagerandroid_os.BatteryManager
android.os.Buildandroid_os.Build
android.os.Bundleandroid_os.Bundle
android.os.Environmentandroid_os.Environment
android.os.HardwarePropertiesManagerandroid_os.HardwarePropertiesManager
android.os.Parcelandroid_os.Parcel
android.os.Parcelableandroid_os.Parcelable
android.os.PowerManagerandroid_os.PowerManager
android.os.Processandroid_os.Process
android.os.StatFsandroid_os.StatFs
android.os.SystemClockandroid_os.SystemClock
android.os.UserManagerandroid_os.UserManager
android.os.VibrationEffectandroid_os.VibrationEffect
android.os.Vibratorandroid_os.Vibrator
android.providerandroid_provider
android.securityandroid_security
android.speechandroid_speech
android.telephonyandroid_telephony
android.viewandroid_view
java.util.Localedart-ui.Locale

See Also

  • The flutter_sqlcipher package implements encrypted SQLite databases based on the android.database APIs.

Libraries

android
Android bindings for Flutter.
android_app
Contains high-level classes encapsulating the overall Android application model. [...]
android_bluetooth
Provides classes that manage Bluetooth functionality, such as scanning for devices, connecting with devices, and managing data transfer between devices. [...]
android_content
Contains classes for accessing and publishing data on a device. [...]
android_database
Contains classes to explore data returned through a content provider. [...]
android_graphics
Provides low level graphics tools such as canvases, color filters, points, and rectangles that let you handle drawing to the screen directly. [...]
android_hardware
Provides support for hardware features, such as the camera and other sensors. [...]
android_location
Contains the framework API classes that define Android location-based and related services. [...]
android_media
Provides classes that manage various media interfaces in audio and video. [...]
android_net
Classes that help with network access. [...]
android_nfc
Provides access to Near Field Communication (NFC) functionality, allowing applications to read NDEF message in NFC tags. [...]
android_os
Provides basic operating system services, message passing, and inter-process communication on the device. [...]
android_provider
Provides convenience classes to access the content providers supplied by Android. [...]
android_security
Provides access to a few facilities of the Android security subsystems. [...]
android_speech
Provides access to the speech recognition service. [...]
android_telephony
Provides APIs for monitoring the basic phone information, such as the network type and connection state, plus utilities for manipulating phone number strings. [...]
android_view
Provides classes that expose basic user interface classes that handle screen layout and interaction with the user. [...]