Forum Xamarin.Android

Service dont do requests when app is not running

hi everyone!
can anyone help me with mysterious error:
i have a service that create a request from a webservice, but its fail when app is not running... :neutral:

if app is open, all requests work like charm
i getting NameResolutionFailure from request, when app is closed

my android manifest:

<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.NETWORK"/>
<uses-permission android:name="android.permission.SET_TIME" />
<uses-permission android:name="android.permission.SET_TIME_ZONE" />
<uses-permission android:name="android.permission.GET_TASKS" />

my service:

[Service(Exported = false, Name = "myservicename")]
[IntentFilter(new string[] { "myfilter" })]
public class SyncService : SyncServiceBase {

    public override void OnCreate() {
        base.OnCreate();
    }

    public override void StartServiceInForeground() {
            base.StartServiceInForeground();
            Task.Run(() => StartService());
    }

    private void StartService() {
            var client = new HttpClient();
            client.DefaultRequestHeaders.Host = "myhostname";
            var result = client.GetAsync("10.1.1.204/simplerequest/test.asp").Result; //Getting ResolutionName error only when app is closed
    }
}

Im targeting android 6.0 and i get this error on emulator and device.

Posts

  • After a long time looking for a solution...
    I found this:
    [image link]
    us.v-cdn.net/5019960/uploads/editor/g7/widvkhs4ydwp.png

    The requests dont work when option Default(Native Tsl 1.2+) is active...
    But if i change to Native tsl 1.2+ my service works fine....
    The question is... why!?

Sign In or Register to comment.