android_multiple_identifier 1.0.3

  • Readme
  • Changelog
  • Example
  • Installing
  • 88

android_multiple_identifier #

Exclusive for Android A plugin that provides multiple Android unique identifiers for you to choose the one that best applies to your needs. This plugin is aimed for projects that need to a unique identifier for Android devices and need multiple options to test in their applications:

  • ANDROID_ID usually works but it is known not to be 100% reliable.
  • IMEI code is unique for each device but only comes with devices that have telephony services. It is also not recommended for other than fraud prevention.
  • Serial Number is also unique for each device but it is only required for devices that do not have telephony services, so it is possible that some devices do not have a serial number (possible but very unlikely).

All there 3 options are provided so you can use the one that best applies to your needs (or maybe multiple options combined).

Permission READ_PHONE_STATE are required but the plugin has a method that takes care of that.

Getting Started #

Make sure you add the needed permission to your Android Manifest Permission and Info.plist.

<uses-permission android:name="android.permission.READ_PHONE_STATE" />

API #

Android #

Be sure to ask permissions first, otherwise, the app won't be able to get the IMEI code and Serial number:

await AndroidMultipleIdentifier.requestPermission();

Then you can call any of the three available methods:

String imei = await AndroidMultipleIdentifier.imeiCode;
String serial = await AndroidMultipleIdentifier.serialCode;
String androidID = await AndroidMultipleIdentifier.androidID;

Or call a map contaning the 3 values so you reduce the times you call native android:

Map idMap = await AndroidMultipleIdentifier.idMap;

String imei = idMap["imei"];
String serial = idMap["serial"];
String androidID = idMap["androidId"];

Android Permissions #

Besides the request permission method:

await AndroidMultipleIdentifier.requestPermission();

You can use methods for checking status of the permissions:

bool permissionStatus = await AndroidMultipleIdentifier.checkPermission(); // true if the permission is already granted
bool isPermissionRejected = await AndroidMultipleIdentifier.checkPermissionRationale(); // true if the user previously rejected the app
bool setToNeverAskAgain = AndroidMultipleIdentifier.neverAskAgain; //true if the user rejected the app and set to never ask again

For openning settings (and modifiying permissions manually):

AndroidMultipleIdentifier.openSettings();

Check Platform Version #

Just in case you need it:

platformVersion = await AndroidMultipleIdentifier.platformVersion;

iOS #

For now the iOs functionality has been disabled. The app won't crash on iOS if you add it to your pubspec.yaml file.

1.0.3 #

  • Added try catch to succes() method to avoid IllegalStateException

1.0.2 #

  • Breaking change. Migrate from the deprecated original Android Support Library to AndroidX. This shouldn't result in any functional changes, but it requires any Android apps using this plugin to also migrate if they're using the original support library.

0.2.7 #

  • Added compatibility with other plugins that requests permissions.
  • Added license.

0.2.6 #

  • Added a method for opening the application settings screen.

0.2.5 #

  • Added a method for checking if the user check the "never ask again" box on permission request

0.2.4 #

  • Fixed bug on rationale method for android below api 26

0.2.1 - 0.2.3 #

  • updated and fixed instruccions

0.2.0 #

  • updated plugin info

0.1.10 #

  • Added functionality to api lower than 26.

0.1.9 #

  • Removed simple_permissions plugin, removed method channels for iOS
  • It's not compatible with iOS but it doesn't crash on iOS when added in the pubspec.yaml file

0.1.3 - 0.1.4 #

  • Added an idMap method that returns a map with all the id's

0.0.9 - 0.1.2 #

  • Fixed graddle dependencies issues for older versions.

0.0.2 #

  • Added Permission methods

0.0.1 #

  • Initial release.

example/README.md

import 'package:flutter/material.dart';
import 'package:android_multiple_identifier/android_multiple_identifier.dart';
import 'dart:async';
import 'package:flutter/services.dart';

void main() => runApp(MyApp());

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  String _platformVersion = 'Unknown';
  String _imei = 'Unknown';
  String _serial = 'Unknown';
  String _androidID = 'Unknown';

  @override
  void initState() {
    super.initState();
    initPlatformState();
  }

  // Platform messages are asynchronous, so we initialize in an async method.
  Future<void> initPlatformState() async {
    String platformVersion;
    String imei;
    String serial;
    String androidID;

    // Platform messages may fail, so we use a try/catch PlatformException.
    try {
      platformVersion = await AndroidMultipleIdentifier.platformVersion;
    } on PlatformException {
      platformVersion = 'Failed to get platform version.';
    }

    await AndroidMultipleIdentifier.requestPermission();

    try {
      imei = await AndroidMultipleIdentifier.imeiCode;
      serial = await AndroidMultipleIdentifier.serialCode;
      androidID = await AndroidMultipleIdentifier.androidID;
    } catch (e) {
      imei = 'Failed to get IMEI.';
      serial = 'Failed to get Serial Code.';
      androidID = 'Failed to get Android id.';
    }

    // If the widget was removed from the tree while the asynchronous platform
    // message was in flight, we want to discard the reply rather than calling
    // setState to update our non-existent appearance.
    if (!mounted) return;

    setState(() {
      _platformVersion = platformVersion;
      _imei = imei;
      _serial = serial;
      _androidID = androidID;
    });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Center(
            child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          crossAxisAlignment: CrossAxisAlignment.center,
          children: <Widget>[
            Text(
              '\nRunning on: $_platformVersion\n',
              textAlign: TextAlign.center,
            ),
            Text('IMEI: $_imei\n'),
            Text(
              'Serial Code: $_serial\n',
              textAlign: TextAlign.center,
            ),
            Text(
              'Android ID: $_androidID\n',
              textAlign: TextAlign.center,
            ),
          ],
        )),
      ),
    );
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  android_multiple_identifier: ^1.0.3

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:android_multiple_identifier/android_multiple_identifier.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
77
Health:
Code health derived from static analysis. [more]
99
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
88
Learn more about scoring.

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

  • Dart: 2.5.1
  • pana: 0.12.21
  • Flutter: 1.9.1+hotfix.4

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Health issues and suggestions

Document public APIs. (-1 points)

13 out of 13 API elements have no dartdoc comment.Providing good documentation for libraries, classes, functions, and other API elements improves code readability and helps developers find and use your API.

Format lib/android_multiple_identifier.dart.

Run flutter format to format lib/android_multiple_identifier.dart.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev.68.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.11 1.14.12
meta 1.1.7
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8