flutter_android 0.4.0

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.

Changelog #

All notable changes to this project will be documented in this file.

The format is based on Keep a Changelog, and this project adheres to Semantic Versioning.

0.4.0 - 2019-03-13

Added #

  • android_hardware.Sensor.* constants
  • android_hardware.SensorManager.* constants
  • android_location.Location.* constants
  • android_os.*.* constants

0.3.7 - 2019-03-12

Added #

  • android_bluetooth.Bluetooth{Adapter,Device,Headset,LeScanner}.* constants

0.3.6 - 2019-02-28

No functional changes.

0.3.5 - 2019-02-15

Changed #

  • Fixed a bug in android_hardware.SensorManager.registerListener()

0.3.4 - 2019-02-15

Added #

  • android_location.Location class
  • android_hardware.Sensor#subscribe() method
  • android_hardware.SensorEvent class
  • android_hardware.SensorManager.getDefaultSensor() static method
  • android_hardware.SensorManager.registerListener() static method

0.3.3 - 2019-02-15

Added #

  • android_location.Location class stub
  • android_location.Location.distanceBetween() static method

0.3.2 - 2019-02-15

Added #

  • Declared Bluetooth permissions for the example app
  • Declared body sensor permissions for the example app
  • android_hardware.Sensor class stub
  • android_hardware.SensorEvent class stub
  • android_hardware.SensorEventListener class stub
  • android_hardware.SensorManager class stub

0.3.1 - 2019-02-14

Added #

  • android_bluetooth.BluetoothAdapter class stub
  • android_bluetooth.BluetoothDevice class stub
  • android_bluetooth.BluetoothHeadset class stub
  • android_bluetooth.BluetoothLeScanner class stub
  • android_bluetooth.BluetoothManager class stub

0.3.0 - 2019-02-14

Changed #

  • Required Dart SDK 2.1+

Added #

  • Face detection demo in the example app
  • android_graphics.Bitmap.fromImage() static method
  • android_graphics.Bitmap.fromAssetImage() static method
  • android_graphics.Bitmap#getHeight() method
  • android_graphics.Bitmap#getWidth() method
  • android_graphics.Bitmap#toImage() method
  • android_graphics.Point class
  • android_graphics.PointF class
  • android_media.Face class
  • android_media.FaceDetector class

0.2.5 - 2019-02-13

Added #

  • android_graphics library
  • android_graphics.Bitmap class

0.2.4 - 2019-01-28

Changed #

  • Added sanity checks to android_database.MatrixCursor

0.2.3 - 2018-12-10

Added #

  • android_content.Context.getSharedPreferences() method
  • android_content.SharedPreferences class

0.2.2 - 2018-12-08

Changed #

  • Made android_database.Cursor iterable

0.2.1 - 2018-12-06

Changed #

  • Enhanced the example application and added a screenshot

0.2.0 - 2018-12-05

Changed #

  • android_database.Cursor#getBlob() now returns a Uint8List, not a ByteBuffer

0.1.14 - 2018-12-04

Added #

  • android_content.ContentValues class

0.1.13 - 2018-11-23

Added #

  • android_app.ActivityManager.isRunningInTestHarness getter

0.1.12 - 2018-11-22

Changed #

  • Corrected the return value for android_database.Cursor#moveToNext()

0.1.11 - 2018-11-21

Added #

  • android_database.MatrixCursor class

Changed #

  • Corrected return values for android_database.Cursor#moveTo*() methods

0.1.10 - 2018-11-21

Added #

  • android_database.DatabaseUtils static methods

0.1.9 - 2018-11-21

Added #

  • android_app.Notification class
  • android_app.NotificationAction class

0.1.8 - 2018-11-20

Added #

0.1.7 - 2018-11-15

Added #

  • android_database.Cursor#get() method

Changed #

  • android_database.CursorIndexOutOfBoundsException constructor

0.1.6 - 2018-11-15

Added #

  • android_database.Cursor interface
  • android_database.CursorIndexOutOfBoundsException exception
  • android_database.DatabaseUtils class
  • android_database.SQLException exception

0.1.5 - 2018-11-15

Added #

  • android_app.WallpaperColors class
  • android_content.ComponentName class
  • android_content.Intent class
  • android_os.Bundle class

0.1.4 - 2018-11-14

Added #

  • android_bluetooth library
  • android_database library
  • android_hardware library
  • android_location library
  • android_media library
  • android_net library
  • android_nfc library
  • android_provider library
  • android_security library
  • android_speech library
  • android_telephony library
  • android_view library

0.1.3 - 2018-11-14

Added #

  • android_content.Context.*_SERVICE constants
  • android_content.Context.getSystemService() method

Changed #

  • All plugin code is now protected by a LocalPlatform().isAndroid assertion
  • The appropriate classes now implement android_os.Parcelable

0.1.2 - 2018-11-14

Added #

0.1.1 - 2018-11-03

Added #

  • android_os library
  • android_os.Environment.dataDirectory getter
  • android_os.Environment.downloadCacheDirectory getter
  • android_os.Environment.externalStorageDirectory getter
  • android_os.Environment.externalStorageState getter
  • android_os.Environment.rootDirectory getter
  • android_os.Environment.isExternalStorageEmulated getter
  • android_os.Environment.isExternalStorageRemovable getter

0.1.0 - 2018-11-03

Added #

  • android_content library
  • android_content.Context.cacheDir getter
  • android_content.Context.codeCacheDir getter
  • android_content.Context.dataDir getter
  • android_content.Context.externalCacheDir getter
  • android_content.Context.externalFilesDir getter
  • android_content.Context.filesDir getter
  • android_content.Context.noBackupFilesDir getter
  • android_content.Context.packageCodePath getter
  • android_content.Context.packageName getter
  • android_content.Context.packageResourcePath getter

example/README.md

flutter_android_example #

Demonstrates how to use the flutter_android plugin.

Screenshot #

Screenshot 1

Screenshot 2

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  flutter_android: ^0.4.0

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:flutter_android/android.dart';
import 'package:flutter_android/android_app.dart';
import 'package:flutter_android/android_bluetooth.dart';
import 'package:flutter_android/android_content.dart';
import 'package:flutter_android/android_database.dart';
import 'package:flutter_android/android_graphics.dart';
import 'package:flutter_android/android_hardware.dart';
import 'package:flutter_android/android_location.dart';
import 'package:flutter_android/android_media.dart';
import 'package:flutter_android/android_net.dart';
import 'package:flutter_android/android_nfc.dart';
import 'package:flutter_android/android_os.dart';
import 'package:flutter_android/android_provider.dart';
import 'package:flutter_android/android_security.dart';
import 'package:flutter_android/android_speech.dart';
import 'package:flutter_android/android_telephony.dart';
import 'package:flutter_android/android_view.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
76
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
90
Overall:
Weighted score of the above. [more]
86
Learn more about scoring.

We analyzed this package on Jul 15, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.4.0
  • pana: 0.12.19
  • Flutter: 1.7.8+hotfix.3

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Maintenance issues and suggestions

Support latest dependencies. (-10 points)

The version constraint in pubspec.yaml does not support the latest published versions for 1 dependency (meta).

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
flutter 0.0.0
meta ^1.1.6 1.1.6 1.1.7
platform ^2.2.0 2.2.0
Transitive dependencies
collection 1.14.11
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test
test >=1.3.4 <2.0.0

Admin