Flutter Same Device ID on Different Devices - android

I'm using device_info_plus library for Device uniqid.
Everything working fine till.
But now I'm facing weird issue.
All device id has been changed.
Like first they are getting as 240a75fXXXXXXXXX like this.
Now they are getting as RKQ1.21XXXXXX.XXX like this.
Also same device id founded on different device.
Same device id has been get from 5 different device.
This is issue is only on Android Devices. Everything working fine on iOS.
I'm using
device_info_plus: ^8.0.0
await _deviceInfo.androidInfo.then((value) {
device_imeino = value.id;
});
Whats wrong??

You can try out with this code :
device_info_plus: ^3.2.1
String? deviceId = '';
getDeviceID() async {
final DeviceInfoPlugin deviceInfoPlugin = DeviceInfoPlugin();
if (Platform.isAndroid) {
AndroidDeviceInfo androidInfo = await deviceInfoPlugin.androidInfo;
deviceId = androidInfo.androidId ?? '';
} else if (Platform.isIOS) {
IosDeviceInfo iosInfo = await deviceInfoPlugin.iosInfo;
deviceId = iosInfo.identifierForVendor ?? '';
}
}

androidID is removed from device_info_plus since v4.1.0. Check the changelog.
android_id package is recommanded to get the correct androidId.

Related

Flutter HEALTH package get steps from user returns always null?

I am working on a personal project and I am using flutter to develop an app (cross platform) that reads in the user's health data from google fit (Android) or Apple Health. I am using this package and even the EXACT same code like in the documentation (I am currently only testing on Android):
Future fetchStepData() async {
int? steps;
// get steps for today (i.e., since midnight)
final now = DateTime.now();
final midnight = DateTime(now.year, now.month, now.day);
bool requested = await health.requestAuthorization([HealthDataType.STEPS]);
if (requested) {
try {
steps = await health.getTotalStepsInInterval(midnight, now);
} catch (error) {
print("Caught exception in getTotalStepsInInterval: $error");
}
print('Total number of steps: $steps');
setState(() {
_nofSteps = (steps == null) ? 0 : steps;
_state = (steps == null) ? AppState.NO_DATA : AppState.STEPS_READY;
});
} else {
print("Authorization not granted - error in authorization");
setState(() => _state = AppState.DATA_NOT_FETCHED);
}
}
Then I am calling this function with await and I also have inserted the correct permission in all Android Manifest files:
Also I set up an OAuth2 Client ID for the project and added my google account as a test user.
BUT THE FUNCTION SETS THE VARIABLE STEPS ALWAYS TO NULL? The boolean variable "requested" is true, so it seems like the actual connection is working?
I am really disappointed by myself guys and I really need help - THANK YOU!
I tried adding the correct android permissions, asking for permissions explicitly, different time intervalls but nothing worked for me, I always got a null value back.

How to execute ADB inside Android app with Flutter?

It possible to run ADB inside android flutter application without root.
There is an application that did it and it works as expected:
https://github.com/nightmare-space/adb_tool
It is using ADB binary compiled for Android like we can see here:
https://github.com/nightmare-space/adb_tool/tree/main/assets/android
However I can't find how it works, even with the full source.
ADB is installed to a strange location as you can see:
I tried to replicate this but it doesn't work at all.
final deposit = (await getApplicationDocumentsDirectory()).path;
const program = '/data/data/com.example.my_app/files/usr/bin/adb';
ByteData data = await rootBundle.load('assets/android/adb');
List<int> bytes = data.buffer.asUint8List(data.offsetInBytes, data.lengthInBytes);
var file = File(program);
file = await file.create(recursive: true);
file.writeAsBytes(bytes);
await Process.run('chmod', ['+x', program]);
var results = await Process.run(program, ['--version']); // Permission error.
setState(() {
_counter += 1;
textarea.text = results.stdout;
});

Flutter - Get/Set Android and IOS device name for Bluetooth/Wifi/Hotspot discovery

I tried to use the device_info_plus package but I could not find any options for getting or setting the Android or Ios device user name so that it appears as Someone's Iphone on wifi/bluetooth discovery.
Is not there any method to achieve that?
import 'package:device_info/device_info.dart';
DeviceInfoPlugin deviceInfo = DeviceInfoPlugin();
AndroidDeviceInfo androidInfo = await deviceInfo.androidInfo;
print('Running on ${androidInfo.model}'); // e.g. "Moto G (4)"
IosDeviceInfo iosInfo = await deviceInfo.iosInfo;
print('Running on ${iosInfo.utsname.machine}'); // e.g. "iPod7,1"

Google sign in "Choose an account to continue" loop

I'm trying to implement the following packages with my Flutter app:
https://pub.dev/packages/permission_handler
https://pub.dev/packages/fit_kit
and I've done so by writing the following two functions:
Future<void> checkPermissions() async {
var status = await Permission.activityRecognition.status;
if (status.isUndetermined || status.isDenied) {
Permission.activityRecognition.request();
} else if (status.isPermanentlyDenied) {
openAppSettings();
}
}
Future<void> read() async {
results.clear();
await checkPermissions();
for (DataType type in [DataType.STEP_COUNT, DataType.DISTANCE]) {
try {
results[type] = await FitKit.read(
type,
dateFrom: _weekBeginning,
dateTo: _now,
);
} on UnsupportedException catch (e) {
results[e.dataType] = [];
}
}
dailyStepBuffer = 0;
dailyDistanceBuffer = 0;
for(FitData dataPoint in results[DataType.STEP_COUNT]){
print(dataPoint);
dailyStepBuffer += dataPoint.value.round();
}
for(FitData dataPoint in results[DataType.DISTANCE]){
print(dataPoint);
dailyDistanceBuffer += dataPoint.value.round();
}
setState(() {
dailySteps = dailyStepBuffer;
dailyDistance = dailyDistanceBuffer;
});
}
The functions and packages work as intended on iOS, but for some reason, whenever I call read() on an Android device, it shows me this sign in screen, and when I click on my account, it does nothing and I get the error:
E/flutter ( 8211): [ERROR:flutter/lib/ui/ui_dart_state.cc(166)] Unhandled Exception: PlatformException(FitKit, User denied permission access, null)
I've gotten the OAuth 2.0 client ID using my SHA-1 fingerprint, added <uses-permission android:name="android.permission.ACTIVITY_RECOGNITION"/> to my AndroidManifest.xml file and added the following to my build.gradle:
implementation 'com.google.android.gms:play-services-fitness:19.0.0'
implementation 'com.google.android.gms:play-services-auth:18.1.0'
Unfortunately though, none of these appear to have solved the issue. I'd be extremely grateful if anyone could help me solve this, thanks!
Can you try flutter clean and check if this persist?
It seems that the FitKit class has a requestPermissions method. Use that along with FitKit.hasPermissions to ensure that the necessary permissions are granted.
It turned out that for some reason, my package name and application id were different, and so entering the application id instead of the package name when getting my OAuth 2.0 Client ID solved it.

What can i use as a device identifier in flutter?

I'm building an app and I need a unique identifier for each device and I don't want it to change even if the user uninstalls the app, what should I use? I don't know what I should look for. I searched a bit and I found something named deviceid is it good enough?
https://pub.dev/packages/device_id
Apparently device_id plugin have some bugs with newest versions of flutter. You can use device_info instead.
Here is an example:
static Future<List<String>> getDeviceDetails() async {
String deviceName;
String deviceVersion;
String identifier;
final DeviceInfoPlugin deviceInfoPlugin = new DeviceInfoPlugin();
try {
if (Platform.isAndroid) {
var build = await deviceInfoPlugin.androidInfo;
deviceName = build.model;
deviceVersion = build.version.toString();
identifier = build.androidId; //UUID for Android
} else if (Platform.isIOS) {
var data = await deviceInfoPlugin.iosInfo;
deviceName = data.name;
deviceVersion = data.systemVersion;
identifier = data.identifierForVendor; //UUID for iOS
}
} on PlatformException {
print('Failed to get platform version');
}
//if (!mounted) return;
return [deviceName, deviceVersion, identifier];
}
The safest way is to build a registration for the user. So, if the user want to use your app, he needs to register a profile. Each account gets a unique identifier and even when the user reinstall the app you can identifier him.
The package that you linked is possible too, but remember jailbreaked devices could change the device id.
I'm not 100% sure, but in Swift/iOS you can use for this case KeyChain. Check this package, maybe it can help you. You can find more infos about KeyChain here.

Categories

Resources