Search code examples
androidandroid-9.0-pienetwork-connection

API call in Android 9 configuration devices and emulator shows connection error


I am using Android 9 emulator, it has internet connection from system and I have added internet permission in manifest. When I try to call api it shows error message as : connection error.


Solution

  • As Piyush commented in my question the answer is to add android:usesCleartextTraffic="true" in manifest file with in application tag

    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        package="com.mypackage">
    
        <uses-permission android:name="android.permission.INTERNET" />
       
        <application
            android:allowBackup="true"
            android:icon="@drawable/appicon"
            android:label="@string/app_name"
            android:supportsRtl="true"
            android:theme="@style/AppTheme"
            android:usesCleartextTraffic="true">
            //your android components...
    </application>