0

I have a Xamarin Forms (4.8) application targeting Android. For backend API calls I use HttpClient with PostAsync or GetAsync.

Most end users are using Android 8.1 devices and several have gotten new devices with Android 10.

On the Android 8.1 devices, the app works fine.

The Android 10 devices don't make it past the 1st API call to authenticate the user. Here is the line where the code throws an error:

HttpResponseMessage response = await client.PostAsync($"{Settings.ApiUrl}/api/auth/authenticate", jsonContent);

That line gives me an error from Exception Message: "Unable to resolve host '{myURL}.net': No address associated with hostname"

Like I said, the app works fine on the physical Android 8.1 device as well as the 8.1 and 10 emulators in Visual Studio. I can also hit the API endpoint with Postman and get the expected results.

The Android Manifest Target is Android 11 and minimum version is 7.1. The Visual Studio application settings "Compile using Android Version" is 9.0

I am not sure what to look at now.

Ryan
  • 650
  • 3
  • 15
  • 49
  • Do you have Internet permission in your Manifest? – Ivan Milisavljevic Jan 24 '22 at 22:25
  • can they connect to the server using the device browser? – Jason Jan 24 '22 at 22:33
  • https://stackoverflow.com/questions/59964096/android-q-10-unable-to-resolve-host-url-issue-when-connected-to-ssid-which-has – Jason Jan 24 '22 at 22:41
  • @IvanMilisavljevic Hi Ivan, the "Internet" permission is not set on my manifest. Would this be the issue even though other devices such as Android 8.1 is working fine? – Ryan Jan 25 '22 at 17:52
  • I had read the document about the two versions. I find the improvement about the [cleartext(non-HTTPS)](https://developer.android.com/about/versions/pie/android-9.0-changes-28). So you can try to add [assembly: Application(UsesCleartextTraffic = true)] to your AssemblyInfo.cs or follow the link to add the code into the AndroidManifest.xml. – Liyun Zhang - MSFT Jan 26 '22 at 03:17
  • Your http calls will fail if you are not using WiFi and have use mobile data option off in the device. Maybe this is an "Oh Right! I forgot I changed that!" scenario. – developer68 Jun 19 '22 at 20:26

0 Answers0