device_identity/lib/device_identity.dart
宏谋刘 161d9c18f3 1.0
2023-05-10 16:07:15 +08:00

127 lines
2.7 KiB
Dart
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import 'dart:async';
import 'dart:io';
import 'package:flutter/services.dart';
/// 获取设备标识
class DeviceIdentity {
/// channel
static const MethodChannel _channel = MethodChannel('device_identity');
/// 判断是否是安卓平台
static bool get isAndroid {
return Platform.isAndroid;
}
/// 在`Application#onCreate`里初始化注意APP合规性若最终用户未同意隐私政策则不要调用
static Future<void> register() async {
if (isAndroid) {
await _channel.invokeMethod('register');
}
}
/// 获取安卓ID可能为空
static Future<String> get androidId async {
if (isAndroid) {
final String androidId = await _channel.invokeMethod('getAndroidID');
return androidId;
}
return "";
}
/// 获取IMEI只支持Android 10之前的系统需要READ_PHONE_STATE权限可能为空
static Future<String> get imei async {
if (isAndroid) {
final String imei = await _channel.invokeMethod('getIMEI');
return imei;
}
return "";
}
/// 获取OAID/AAID可能为空
static Future<String> get oaid async {
if (isAndroid) {
final String oaid = await _channel.invokeMethod('getOAID');
return oaid;
}
return "";
}
/// 获取UA
static Future<String> get ua async {
if (isAndroid) {
final String ua = await _channel.invokeMethod('getUA');
return ua;
}
return "";
}
/// 获取DRMID
static Future<String> get drmId async {
if (isAndroid) {
final String ua = await _channel.invokeMethod('getDrmID');
return ua;
}
return "";
}
/// 获取IP
static Future<String> get ip async {
if (isAndroid) {
final String ua = await _channel.invokeMethod('getIp');
return ua;
}
return "";
}
/// 获取DRMID
static Future<String> get mac async {
if (isAndroid) {
final String ua = await _channel.invokeMethod('getMac');
return ua;
}
return "";
}
static Future<String> get model async {
if (isAndroid) {
final String ua = await _channel.invokeMethod('getModel');
return ua;
}
return "";
}
static Future<String> get product async {
if (isAndroid) {
final String ua = await _channel.invokeMethod('getProduct');
return ua;
}
return "";
}
static Future<String> get bssid async {
if (isAndroid) {
final String ua = await _channel.invokeMethod('getBssid');
return ua;
}
return "";
}
static Future<String> get osVersion async {
if (isAndroid) {
final String ua = await _channel.invokeMethod('getOsVersion');
return ua;
}
return "";
}
}