flutter android bindings
android bindings
this is a flutter plugin for using android’s numerous platform-specific apis in flutter apps.
prerequisites
compatibility
android bindings
android only.
installation
dependencies:
flutter_android: ^0.8.0
features
android bindings
- 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
android bindings
feature | flutter api |
---|---|
activity launch | android_content.intent#startactivity() |
bluetooth scanning | android_bluetooth.bluetoothlescanner |
distance calculation | android_location.location.distancebetween() |
face detection | android_media.facedetector |
heart-rate monitoring | android_hardware.sensormanager.getdefaultsensor() |
parcel serialization | android_os.parcel |
sensor event streams | android_hardware.sensor#subscribe() |
todo: dirs
examples
activity launch
import 'package:flutter_android/android_content.dart' show intent;
await intent(
action: "android.intent.action.view", // intent.action_view
data: uri.parse("https://flutter.dev"),
).startactivity();
parcel serialization
import 'package:flutter_android/android_os.dart' show parcel;
var parcel = parcel.obtain()
..writeboolean(true)
..writeint(42)
..writedouble(3.1415)
..writestring("hello, world!")
..writelist(<object>[1, 2, 3])
..writemap(<string, object>{"a": 1, "b": 2, "c": 3});
await _channel.invokemethod('somejavamethod', parcel.asuint8list());
// in java, your methodcallhandler's call.arguments contains the marshaled parcel
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.
allflutter_android
apis throw anassertionerror
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;
componentname
contentvalues
context.cachedir
context.codecachedir
context.datadir
context.externalcachedir
context.externalfilesdir
context.filesdir
context.getsharedpreferences()
context.getsystemservice()
context.nobackupfilesdir
context.packagecodepath
context.packagename
context.packageresourcepath
intent
sharedpreferences
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;
bundle
environment.datadirectory
environment.downloadcachedirectory
environment.externalstoragedirectory
environment.externalstoragestate
environment.rootdirectory
environment.isexternalstorageemulated
environment.isexternalstorageremovable
cross-reference
android | flutter |
---|---|
android.app |
android_app |
android.app.activity |
android_app.activity |
android.app.activitymanager |
android_app.activitymanager |
android.app.alarmmanager |
android_app.alarmmanager |
android.app.authenticationrequiredexception |
android_app.authenticationrequiredexception |
android.app.downloadmanager |
android_app.downloadmanager |
android.app.keyguardmanager |
android_app.keyguardmanager |
android.app.notification |
android_app.notification |
android.app.notification.action |
android_app.notificationaction |
android.app.notification.builder |
android_app.notificationbuilder |
android.app.notificationmanager |
android_app.notificationmanager |
android.app.pendingintent |
android_app.pendingintent |
android.app.searchmanager |
android_app.searchmanager |
android.app.wallpapercolors |
android_app.wallpapercolors |
android.app.wallpaperinfo |
android_app.wallpaperinfo |
android.app.wallpapermanager |
android_app.wallpapermanager |
android.bluetooth |
android_bluetooth |
android.bluetooth.bluetoothadapter |
android_bluetooth.bluetoothadapter |
android.bluetooth.bluetoothdevice |
android_bluetooth.bluetoothdevice |
android.bluetooth.bluetoothheadset |
android_bluetooth.bluetoothheadset |
android.bluetooth.bluetoothmanager |
android_bluetooth.bluetoothmanager |
android.bluetooth.le.bluetoothlescanner |
android_bluetooth.bluetoothlescanner |
android.bluetooth.le |
android_bluetooth |
android.content |
android_content |
android.content.activitynotfoundexception |
android_content.activitynotfoundexception |
android.content.componentname |
android_content.componentname |
android.content.contentvalues |
android_content.contentvalues |
android.content.context |
android_content.context |
android.content.intent |
android_content.intent |
android.content.intentfilter |
android_content.intentfilter |
android.content.sharedpreferences |
android_content.sharedpreferences |
android.database |
android_database |
android.database.cursor |
android_database.cursor |
android.database.cursorindexoutofboundsexception |
android_database.cursorindexoutofboundsexception |
android.database.databaseutils |
android_database.databaseutils |
android.database.matrixcursor |
android_database.matrixcursor |
android.database.sqlexception |
android_database.sqlexception |
android.graphics |
android_graphics |
android.graphics.bitmap |
android_graphics.bitmap |
android.graphics.color |
dart-ui.color |
android.graphics.point |
android_graphics.point |
android.graphics.pointf |
android_graphics.pointf |
android.graphics.drawable.icon |
flutter.icon |
android.hardware |
android_hardware |
android.hardware.sensor |
android_hardware.sensor |
android.hardware.sensorevent |
android_hardware.sensorevent |
android.hardware.sensoreventlistener |
android_hardware.sensoreventlistener |
android.hardware.sensormanager |
android_hardware.sensormanager |
android.location |
android_location |
android.location.location |
android_location.location |
android.media |
android_media |
android.media.facedetector |
android_media.facedetector |
android.media.facedetector.face |
android_media.face |
android.net |
android_net |
android.nfc |
android_nfc |
android.os |
android_os |
android.os.batterymanager |
android_os.batterymanager |
android.os.build |
android_os.build |
android.os.bundle |
android_os.bundle |
android.os.environment |
android_os.environment |
android.os.hardwarepropertiesmanager |
android_os.hardwarepropertiesmanager |
android.os.parcel |
android_os.parcel |
android.os.parcelable |
android_os.parcelable |
android.os.powermanager |
android_os.powermanager |
android.os.process |
android_os.process |
android.os.statfs |
android_os.statfs |
android.os.systemclock |
android_os.systemclock |
android.os.usermanager |
android_os.usermanager |
android.os.vibrationeffect |
android_os.vibrationeffect |
android.os.vibrator |
android_os.vibrator |
android.provider |
android_provider |
android.security |
android_security |
android.speech |
android_speech |
android.telephony |
android_telephony |
android.view |
android_view |
java.util.locale |
dart-ui.locale |
Comments are closed.