android - Ionic 应用程序 - 无法访问互联网

标签 android cordova

我使用 ionic 和 Phonegap 构建了一个小型移动 Android 6 应用程序。这不是我的第一个 Hybrid 应用程序,但却是我第一个使用 Ionic 的应用程序。该应用程序调用一个 php 文件来查询 MySQL 数据库并将一些信息返回到 View 。该应用程序可根据需要在线和本地运行,但在我通过 PhoneGap 构建后无法访问互联网。我的样式以及从 PHP 调用返回的信息都没有加载。我已经通过 PhoneGap 发布了该应用程序,并通过 Samsung galaxy 5 进行了测试;我在 Mac 上开发了所有内容。

我根据需要安装了 Cordova 白名单插件,并向 list 添加了必要的权限,但我需要另一双眼睛来检查这个。

这是我的 config.xml 文件:

配置文件

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<widget id="com.ionicframework.testrest902325" version="0.0.1" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
  <name>NAME</name>
  <description>
       DESCRIPTION
    </description>
  <author email="name@name.edu" href="http://example.com.com/">
    </author>
  <content src="index.html"/>
<access origin="*"/>
  <preference name="webviewbounce" value="false"/>
  <preference name="UIWebViewBounce" value="false"/>
  <preference name="DisallowOverscroll" value="true"/>
  <preference name="android-minSdkVersion" value="16"/>
  <preference name="BackupWebStorage" value="none"/>
  <feature name="StatusBar">
    <param name="ios-package" value="CDVStatusBar" onload="true"/>
  </feature>
</widget>

这是我的 AndroidManifest.xml

<?xml version='1.0' encoding='utf-8'?>
<manifest android:hardwareAccelerated="true" android:versionCode="1" android:versionName="0.0.1" package="com.ionicframework.testrest902325" xmlns:android="http://schemas.android.com/apk/res/android">
    <supports-screens android:anyDensity="true" android:largeScreens="true" android:normalScreens="true" android:resizeable="true" android:smallScreens="true" android:xlargeScreens="true" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
    <application android:hardwareAccelerated="true" android:icon="@drawable/icon" android:label="@string/app_name" android:supportsRtl="true">
        <activity android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale" android:label="@string/activity_name" android:launchMode="singleTop" android:name="MainActivity" android:theme="@android:style/Theme.DeviceDefault.NoActionBar" android:windowSoftInputMode="adjustResize">
            <intent-filter android:label="@string/launcher_name">
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
    <uses-sdk android:minSdkVersion="16" android:targetSdkVersion="23" />
</manifest>

最佳答案

我遇到了非常相似的问题;即使安装了白名单插件并获得了必要的权限,我的应用程序也从未连接到我的网络服务。

然后我想试试在 config.xml 中包含白名单插件。因此,在我的项目文件夹中,我运行了以下更新了我的 config.xml 的命令

cordova plugin add cordova-plugin-whitelist --save

之后,由我的自动构建系统生成的 APK 连接到我的网络服务。

关于android - Ionic 应用程序 - 无法访问互联网,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35539437/

相关文章:

返回 bool 值的 Android alertdialog 生成器

android - 您可以在多大程度上自定义 Fabric's Digits 在 Android 上的流程、外观和感觉?

android - 以编程方式设置按钮背景颜色删除边距和圆角

javascript - Cordova跨域文件://iframe contentwindow communication

java - 默认情况下未选中抽屉导航项目

android - 哪个包装设计更好?

cordova - Ionic 3 Cordova 错误 : Device communication timed out. 尝试拔下并重新插入设备

android - 获取 PhoneGap 中 Assets 文件夹的绝对路径

javascript - 使用 Framework7 时 Cordova 插件不工作

javascript - window.scrollTo 不适用于 IOS 的phonegap