Android REST call not working in emulator
See original GitHub issueOK, I have tried for days and I am now crying uncle. I cannot get the Android build of my Capacitor app to make a REST call from the device emulator in Android Studio. The same code works fine in a browser (ionic serve), in iOS using a device and the simulator, but not in the Android emulator. Instead it does nothing and just returns a response code of 0.
I am on a Mac, using the latest Capacitor beta (as of July 1st), and the latest Android Studio (3.1.3). I am using API 26 on a Nexus 6.
I am trying to hit a REST call running in AWS that I wrote. It is HTTP and has no security right now since I am in development.
I run Burp Suite on my machine as a proxy and set the proxy for Safari and I see all the requests and responses. I set the proxy on the Android emulator and Burp shows no traffic at all. The same holds true for the Android Profiler. There is some initial network traffic when the app starts up, but never when I make the REST call.
Here’s the call:
login(loginRequest): Observable<AuthenticationResponse> {
console.log('in login');
localStorage.clear();
return this.http.put<AuthenticationResponse>(this.rest.getApiUrl() + '/v1/consumers/login', loginRequest,
{ headers: this.requestHeaders })
.map(user => {
// login successful if there's a jwt token in the response
if (user && user.token) {
localStorage.setItem('currentUser', user.token);
localStorage.setItem('userId', user.user.toLocaleString());
}
return user;
}
).do(user => {
this.push.initPushNotification(user.user);
});
}
I am using the default setup for Android and it appears that all the Internet and network permissions are there in the AndroidManifest.xml file:
<!-- Permissions -->
<uses-permission android:name="android.permission.INTERNET" />
<!-- Camera, Photos -->
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<!-- Geolocation API -->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-feature android:name="android.hardware.location.gps" />
<!-- Network API -->
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
I have never used Android Studio or the Android emulator so I may be missing some setting.
Thanks, Steve
Issue Analytics
- State:
- Created 5 years ago
- Comments:11 (3 by maintainers)
These solutions didnt work for me. My code works on the browser, I can see the data from my API, but the data is never shown in the android emulator. I hope somebody has the solution!
This did not solve the problem for me, i’m still having the same issue.