Reputation: 1120
I've developed an Android app that works perfectly on an emulator but displays the error message:
we did not get any data
When I run it on a real device (Samsung S9). I suspect the problem is with how I'm connecting to my backend.
Here's what I've tried:
Code (Most Relevant Parts):
Relevant part of AndroidManifest.xml: (especially any network-related permissions)
<uses-permission android:name="android.permission.INTERNET"/>
app_constants.dart: (Focus on BASE_URL)
class AppConstants {
static const String BASE_URL="http://10.0.2.2:8080";
// ... other constants
}
I'm grateful for any help you might be able to give.
Upvotes: 0
Views: 399
Reputation: 612
Based on static const String BASE_URL="http://192.168.xx.xx:8080"
requests which are outside SSL Encryption, add:
<application android:usesCleartextTraffic="true">
</application>
To the AndroidManifest.xml
Upvotes: 1
Reputation: 1224
10.0.2.2 is a special alias to your host loopback interface i.e., 127.0.0.1 on your development machine. You may be able to change your AppConstants
to your LAN address if your device and backend are running on the same LAN. This may require additional configuration to get it to work.
class AppConstants{
static const String BASE_URL="http://192.168.xx.xx:8080";
static const String GET_TASKS="/gettasks";
static const String POST_TASK="/create";
static const String GET_TASK="/gettask/";
static const String UPDATE_TASK="/update/";
static const String DELETE_TASK="/delete/";
}
You may use ifconfig -a
to get your LAN IP.
Upvotes: 2