本文整理自网络,侵删。
安卓下,默认只允许 https 的访问,不允许 http 的访问。
用 Delphi 写一个安卓 APP,用 TIdHTTP 去访问一个 WEB 服务器,不行。网上查了一下,发现需要这样做:
在 APP 的工程目录下,有一个 XML 文件,“AndroidManifest.template.xml”,用文本 编辑器打开它:
在 <application android:persistent="%persistent%" 底下,增加一行:
android:usesCleartextTraffic="true">
增加完后,全文如下:
<?xml version="1.0" encoding="utf-8"?><!-- BEGIN_INCLUDE(manifest) --><manifest xmlns:android="http://schemas.android.com/apk/res/android" package="%package%" android:versionCode="%versionCode%" android:versionName="%versionName%" android:installLocation="%installLocation%"> <uses-sdk android:minSdkVersion="%minSdkVersion%" android:targetSdkVersion="%targetSdkVersion%" /> <%uses-permission%> <uses-feature android:glEsVersion="0x00020000" android:required="True"/> <application android:persistent="%persistent%" android:restoreAnyVersion="%restoreAnyVersion%" android:label="%label%" android:debuggable="%debuggable%" android:largeHeap="%largeHeap%" android:icon="%icon%" android:theme="%theme%" android:hardwareAccelerated="%hardwareAccelerated%" android:resizeableActivity="false"android:usesCleartextTraffic="true"> <%provider%> <%application-meta-data%> <%services%> <!-- Our activity is a subclass of the built-in NativeActivity framework class. This will take care of integrating with our NDK code. --> <activity android:name="com.embarcadero.firemonkey.FMXNativeActivity" android:label="%activityLabel%" android:configChanges="orientation|keyboard|keyboardHidden|screenSize" android:launchMode="singleTask"> <!-- Tell NativeActivity the name of our .so --> <meta-data android:name="android.app.lib_name" android:value="%libNameValue%" /> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <%activity%> <%receivers%> </application></manifest><!-- END_INCLUDE(manifest) -->
加上那一行以后,IdHTTP 可以使用 http 协议访问一个网站了。――――――――――――――――
原文链接:https://blog.csdn.net/pcplayer/article/details/101305862
相关阅读 >>
Delphi windows 编程[12] - 菜单与菜单资源(1-3)
更多相关阅读请进入《Delphi》频道 >>