Samuel Juliano
Samuel Juliano

Reputation: 1

How to get device's name in flutter

So, I'm developing a monitoring app for android that support multiple devices, and I would like to get the device's name. I've already googled about this, with no success. Already tried the device_info package, but it doesn't have the information I need. Which is the following shown in the image:

output obs.: first question here, so sorry if something is wrong.

Upvotes: 0

Views: 4350

Answers (2)

bqubique
bqubique

Reputation: 1385

Settings.Global.getString(contentResolver, Settings.Global.DEVICE_NAME)

Returns the name that was given to the device via device settings. Only available on Android 7.1+ (N_MR1). This name is seen when connecting to Bluetooth or wifi network. Using platform channels I delegated this name to Flutter side:

@RequiresApi(Build.VERSION_CODES.N_MR1)
private fun getDeviceName(): String {
    return Settings.Global.getString(contentResolver, Settings.Global.DEVICE_NAME)
}

And then just call this method using PlatformChannels via Flutter.

Upvotes: 0

Urvesh
Urvesh

Reputation: 61

You can use device_info_plus, it is provided by fluttercommunity.dev and supports almost all platforms. You can check this API reference to get information based on platforms.

Upvotes: 2

Related Questions