Search code examples
javaandroidxmlandroid-studioandroid-permissions

Android App doesn't have internet connection - No Permissions required


Well, I have built an app to store values on a remote database. It works!! I didn't use an emulator for testing instead I used my own phone. Now the problem is that on my phone, it works perfectly...no issues but when I installed it on another phone, the app doesn't connect to the internet. I have included internet permission in android manifest.xml.

I have tried these but didn't work:

  1. Building apk and installing in the new phone.
  2. Compiling directly to the new phone.
  3. Sending the apk from old phone to new phone via shareit.
  4. Creating a signed apk and installing.
  5. Checked via wifi and mobile data (NOTE: BOTH WIFI AND MOBILE DATA WORKS IN OLD PHONE).
  6. Checked android compatibility: supports up to android 10.

*I added error messages for try...catch blocks in form of toasts for the user to know what's the issue. and the catch exception for no internet returns connection problem. I'm getting that error message.

As I researched, I got to know that internet permission is categorized as normal permission which is not prompted to the user upon installation.

I built a second dummy app: Same issue with it... compiled directly to new phone but didn't work...it works in old phone...

Old phone: Samsung J7 Prime with Android 8.1 New Phone: Samsung J7 Pro with Android 9

Any idea or suggestion will be gladly helpful... Thank you!


Solution

  • in android 9 and above you have to set network Security Config
    first of all in res package create xml package and in xml package create new xml resource file with network_security_config name

    <?xml version="1.0" encoding="utf-8"?>
    <network-security-config>
        <base-config cleartextTrafficPermitted="true" />
     </network-security-config>
    

    then in manifest in

    android:networkSecurityConfig="@xml/network_security_config"