Click here to Skip to main content
15,508,758 members
Home / Discussions / Android
   

Android

 
QuestionImplement AsyncTask Pin
paradox029-Mar-21 23:02
paradox029-Mar-21 23:02 
QuestionRe: Implement AsyncTask Pin
David Crow8-Apr-21 5:33
David Crow8-Apr-21 5:33 
AnswerRe: Implement AsyncTask Pin
James_Carter42023-May-21 5:14
James_Carter42023-May-21 5:14 
QuestionAndroid Studio oddity Pin
David Crow3-Mar-21 5:08
David Crow3-Mar-21 5:08 
AnswerRe: Android Studio oddity Pin
Richard MacCutchan3-Mar-21 5:52
mveRichard MacCutchan3-Mar-21 5:52 
Questionhow to add a button in one the navigation drawer fragment so that when the user click he is directed to another sub fragment of that previous fragment Pin
George S Mulbah II2-Mar-21 16:55
George S Mulbah II2-Mar-21 16:55 
QuestionRe: how to add a button in one the navigation drawer fragment so that when the user click he is directed to another sub fragment of that previous fragment Pin
David Crow3-Mar-21 3:35
David Crow3-Mar-21 3:35 
QuestionXamarin Forms API - Can't Connect Pin
Kevin Marois16-Feb-21 7:13
professionalKevin Marois16-Feb-21 7:13 
I have been trying FOREVER to get a simple Xamarin Forms app to call a Web API. I am running this Microsoft sample Xamarin.Forms - TodoREST - Code Samples | Microsoft Docs

The only change I made was the port number that the API uses. This line is in a constants file. The emulator uses the internal ip of 10.0.2.2:
public static string RestUrl = DeviceInfo.Platform ==
    DevicePlatform.Android ?
        "http://10.0.2.2:44300/api/todoitems/{0}" :
        "http://localhost:44300/api/todoitems/{0}";
Here's the relevant code. The URI being passed is correct from the line above:
public async Task> RefreshDataAsync()
{
    Items = new List();

    Uri uri = new Uri(string.Format(Constants.RestUrl, string.Empty));
    try
    {
        HttpResponseMessage response = await client.GetAsync(uri);
        if (response.IsSuccessStatusCode)
        {
            string content = await response.Content.ReadAsStringAsync();
            Items = JsonConvert.DeserializeObject>(content);
        }
    }
    catch (Exception ex)
    {
        Debug.WriteLine(@"\tERROR {0}", ex.Message);
    }

    return Items;
}
It throws this exception:
{Java.Net.SocketException: Connection reset
  at Java.Interop.JniEnvironment+InstanceMethods.CallIntMethod (Java.Interop.JniObjectReference instance, Java.Interop.JniMethodInfo method, Java.Interop.JniArgumentValue* args) [0x0006e] in :0 
  at Java.Interop.JniPeerMembers+JniInstanceMethods.InvokeVirtualInt32Method (System.String encodedMember, Java.Interop.IJavaPeerable self, Java.Interop.JniArgumentValue* parameters) [0x0002a] in :0 
  at Java.Net.HttpURLConnection.get_ResponseCode () [0x0000a] in :0 
  at Xamarin.Android.Net.AndroidClientHandler+<>c__DisplayClass46_0.b__2 () [0x00000] in :0 
  at System.Threading.Tasks.Task`1[TResult].InnerInvoke () [0x0000f] in /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/external/corert/src/System.Private.CoreLib/src/System/Threading/Tasks/Future.cs:534 
  at System.Threading.Tasks.Task.Execute () [0x00000] in /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/external/corert/src/System.Private.CoreLib/src/System/Threading/Tasks/Task.cs:2319 
--- End of stack trace from previous location where exception was thrown ---

  at Xamarin.Android.Net.AndroidClientHandler.DoProcessRequest (System.Net.Http.HttpRequestMessage request, Java.Net.URL javaUrl, Java.Net.HttpURLConnection httpConnection, System.Threading.CancellationToken cancellationToken, Xamarin.Android.Net.AndroidClientHandler+RequestRedirectionState redirectState) [0x00372] in :0 
  at Xamarin.Android.Net.AndroidClientHandler.SendAsync (System.Net.Http.HttpRequestMessage request, System.Threading.CancellationToken cancellationToken) [0x002d0] in :0 
  at System.Net.Http.HttpClient.FinishSendAsyncBuffered (System.Threading.Tasks.Task`1[TResult] sendTask, System.Net.Http.HttpRequestMessage request, System.Threading.CancellationTokenSource cts, System.Boolean disposeCts) [0x0017e] in /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/external/corefx/src/System.Net.Http/src/System/Net/Http/HttpClient.cs:506 
  at TodoREST.RestService.RefreshDataAsync () [0x0006b] in C:\Projects\SandBox\Xamarin\Mirosoft Examples\Web Services\ToDoREST\TodoREST\Data\RestService.cs:30 
  --- End of managed Java.Net.SocketException stack trace ---
java.net.SocketException: Connection reset
    at java.net.SocketInputStream.read(SocketInputStream.java:209)
    at java.net.SocketInputStream.read(SocketInputStream.java:139)
    at com.android.okhttp.okio.Okio$2.read(Okio.java:136)
    at com.android.okhttp.okio.AsyncTimeout$2.read(AsyncTimeout.java:211)
    at com.android.okhttp.okio.RealBufferedSource.indexOf(RealBufferedSource.java:306)
    at com.android.okhttp.okio.RealBufferedSource.indexOf(RealBufferedSource.java:300)
    at com.android.okhttp.okio.RealBufferedSource.readUtf8LineStrict(RealBufferedSource.java:196)
    at com.android.okhttp.internal.http.Http1xStream.readResponse(Http1xStream.java:186)
    at com.android.okhttp.internal.http.Http1xStream.readResponseHeaders(Http1xStream.java:127)
    at com.android.okhttp.internal.http.HttpEngine.readNetworkResponse(HttpEngine.java:737)
    at com.android.okhttp.internal.http.HttpEngine.readResponse(HttpEngine.java:609)
    at com.android.okhttp.internal.huc.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:471)
    at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:407)
    at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getResponseCode(HttpURLConnectionImpl.java:538)
}

Can anyone help? All I want is to call into a Rest API can get data back.
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.

AnswerRe: Xamarin Forms API - Can't Connect Pin
Richard Deeming16-Feb-21 7:19
mveRichard Deeming16-Feb-21 7:19 
GeneralRe: Xamarin Forms API - Can't Connect Pin
Kevin Marois16-Feb-21 10:36
professionalKevin Marois16-Feb-21 10:36 
GeneralRe: Xamarin Forms API - Can't Connect Pin
Richard Deeming16-Feb-21 23:08
mveRichard Deeming16-Feb-21 23:08 
GeneralRe: Xamarin Forms API - Can't Connect Pin
Kevin Marois17-Feb-21 6:45
professionalKevin Marois17-Feb-21 6:45 
QuestionI cannot play videos Google Drive, the error “Whoops! there was a problem playing this video” appears. Pin
Otis Ryder24-Jan-21 23:49
Otis Ryder24-Jan-21 23:49 
QuestionLooking for a collaborator on a group project. Pin
FelipeRodas8624-Jan-21 10:46
FelipeRodas8624-Jan-21 10:46 
AnswerRe: Looking for a collaborator on a group project. Pin
Nathan-Albert Wallace28-Jul-22 23:04
Nathan-Albert Wallace28-Jul-22 23:04 
QuestionSuitable Laptop Model for Android Development Pin
phoohtoo19-Jan-21 1:19
phoohtoo19-Jan-21 1:19 
AnswerRe: Suitable Laptop Model for Android Development Pin
Richard MacCutchan19-Jan-21 1:49
mveRichard MacCutchan19-Jan-21 1:49 
GeneralRe: Suitable Laptop Model for Android Development Pin
phoohtoo19-Jan-21 3:21
phoohtoo19-Jan-21 3:21 
GeneralRe: Suitable Laptop Model for Android Development Pin
Richard MacCutchan19-Jan-21 4:45
mveRichard MacCutchan19-Jan-21 4:45 
AnswerRe: Suitable Laptop Model for Android Development Pin
David Crow19-Jan-21 5:06
David Crow19-Jan-21 5:06 
GeneralRe: Suitable Laptop Model for Android Development Pin
phoohtoo20-Jan-21 6:21
phoohtoo20-Jan-21 6:21 
AnswerRe: Suitable Laptop Model for Android Development Pin
thatraja19-Jan-21 6:41
professionalthatraja19-Jan-21 6:41 
GeneralRe: Suitable Laptop Model for Android Development Pin
phoohtoo20-Jan-21 6:19
phoohtoo20-Jan-21 6:19 
Questioncreation of login page in android studio Pin
Member 150388016-Jan-21 1:00
Member 150388016-Jan-21 1:00 
QuestionRe: creation of login page in android studio Pin
Richard MacCutchan6-Jan-21 1:25
mveRichard MacCutchan6-Jan-21 1:25 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.