简体   繁体   English

Android 应用程序没有互联网连接 - 无需权限

[英]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.我在 android manifest.xml 中包含了互联网权限。

I have tried these but didn't work:我试过这些,但没有奏效:

  1. Building apk and installing in the new phone.构建 apk 并安装在新手机中。
  2. Compiling directly to the new phone.直接编译到新手机。
  3. Sending the apk from old phone to new phone via shareit.通过 shareit 将 apk 从旧手机发送到新手机。
  4. Creating a signed apk and installing.创建签名的 apk 并安装。
  5. Checked via wifi and mobile data (NOTE: BOTH WIFI AND MOBILE DATA WORKS IN OLD PHONE).通过 wifi 和移动数据进行检查(注意:旧手机中的 WIFI 和移动数据均可使用)。
  6. Checked android compatibility: supports up to android 10.检查android兼容性:最多支持android 10。

*I added error messages for try...catch blocks in form of toasts for the user to know what's the issue. *我为 try...catch 块添加了错误消息,以敬酒的形式让用户知道问题所在。 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.通过研究,我了解到 Internet 权限被归类为正常权限,在安装时不会提示用户。

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旧手机:搭载 Android 8.1 的三星 J7 Prime 新手机:搭载 Android 9 的三星 J7 Pro

Any idea or suggestion will be gladly helpful... Thank you!任何想法或建议都会很高兴有帮助...谢谢!

in android 9 and above you have to set network Security Config在 android 9 及更高版本中,您必须设置网络安全配置
first of all in res package create xml package and in xml package create new xml resource file with network_security_config name首先在 res 包中创建 xml 包,然后在 xml 包中创建具有 network_security_config 名称的新 xml 资源文件

<?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"
<uses-permission android:name="android.permission.INTERNET" />

使用调试 APK 而不是签名 APK

请在清单上添加权限以授予权限.INTERNET

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM