question

BrianErickson-9266 avatar image
0 Votes"
BrianErickson-9266 asked LeonLu-MSFT edited

Metered Network

My app needs an internet connection at start up...just to log in. I've got this handled using Xamarin.Essentials.Connectivity.

Later on, I'd like to know if the connection is metered or not...to allow the user to opt-in to data use. I'm not seeing a way to do this with Xamarin.

Am I missing something?

Thanks,
Brian

dotnet-xamarin
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

LeonLu-MSFT avatar image
0 Votes"
LeonLu-MSFT answered LeonLu-MSFT edited

Hello,​

Welcome to our Microsoft Q&A platform!

I'd like to know if the connection is metered or not...to allow the user to opt-in to data use.

No, I cannot find a way to allow the user to opt-in to data use with Xamarin.Essentials.Connectivity. You can see the source code about it

Android: https://github.com/xamarin/Essentials/blob/main/Xamarin.Essentials/Connectivity/Connectivity.android.cs

iOS:https://github.com/xamarin/Essentials/blob/main/Xamarin.Essentials/Connectivity/Connectivity.ios.tvos.macos.cs

You can make a feature request about the Metered Network for Xamarin.Essentials.Connectivity.

https://github.com/xamarin/Essentials/issues/new/choose


Update

I find Native API provide this function.

For Android you can use the native IsActiveNetworkMetered API to check if device is on a metered network.

https://docs.microsoft.com/en-us/dotnet/api/android.net.connectivitymanager.isactivenetworkmetered?view=xamarin-android-sdk-9

For iOS, For iOS, you can use NWPath.IsExpensive property to check whether the connection is metered.

https://docs.microsoft.com/en-us/dotnet/api/network.nwpath.isexpensive?view=xamarin-ios-sdk-12

Best Regards,

Leon Lu



If the response is helpful, please click "Accept Answer" and upvote it.

Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.





5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.