Share via

AddCapability(NetCapability.Mcx) issue Java.Lang.SecurityException: 'ConnectivityService: user 10132 has no permission to access restricted network.'

DustOfRust 141 Reputation points
2023-08-23T21:41:04.5333333+00:00

Executes the following code in xamarin.

When I set .AddCapability(NetCapability.Supl) to Supl

Or when I have .AddCapability(NetCapability.Mms) on mms

This phone app works. But when I insert .AddCapability(NetCapability.Mcx) the app crashes and won't work.

I don't know why, is it a permissions issue?

But what if I have already marked everything in the manifest and in the android settings I have also assigned everything to the application?

Anyone got any ideas?

The API is set to 33

All latest versions

      var context = Android.App.Application.Context;

            Android.Provider.Settings.System.CanWrite(context);

            NetworkRequest request = new NetworkRequest.Builder()
           .AddTransportType(Android.Net.TransportType.Cellular)
           .AddCapability(NetCapability.Supl)
           .Build();

            ConnectivityManager connectivityManager = (ConnectivityManager)context.GetSystemService(Android.Content.Context.ConnectivityService);

            MyNetworkCallback networkCallback = new MyNetworkCallback();
            connectivityManager.RequestNetwork(request, networkCallback);

        private class MyNetworkCallback : ConnectivityManager.NetworkCallback
        {
            public override void OnAvailable(Network network)
            {
                base.OnAvailable(network);  
            }

            public override void OnLost(Network network)
            {
                base.OnLost(network);
            }
        }

When i set "Mcx" not "Supl" or "MMS" and run application

.AddCapability(NetCapability.Mcx)

Visual studio return this error, why?

Java.Lang.SecurityException: 'ConnectivityService: user 10132 has no permission to access restricted network.'

What permissions do I need to be able to execute the code with the Mcx parameter?

Developer technologies | .NET | Xamarin

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.