Tag Archives: Android Foundation

The local web page in WebView failed to load with XMLHttpRequest

Problem description

When using WebView to display local web pages, if developers use XMLHttpRequest to load additional local files, the following error messages will appear on some mobile phones:

Failed to execute 'send' on 'XMLHttpRequest': Failed to load 'file:///asset/content.txt'

Cause of the problem

The reason for this error is that Android, based on security considerations, has prohibited local web pages in WebView from using XMLHttpRequest to read local files since Android version 4.1. As a result, “phones before Android 4.1” can use XMLHttpRequest normally, while “phones after Android 4.1” cannot use XMLHttpRequest normally.

Solution

Use the “allowfileaccessfromfileurls” method provided by WebView to restart the function of XMLHttpRequest to read files. Subsequent local web pages executed in WebView can normally use XMLHttpRequest to read local file contents.

// WebSettings
WebSettings settings = webView.getSettings();
settings.setJavaScriptEnabled(true);
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN) {
   settings.setAllowFileAccessFromFileURLs(true);
}

After the eclipse Android virtual machine starts, an error will be reported: similar to SDK manager devices.xml Solution

Android SDK is updated with Android SDK manager. ADT is installed on eclipse to develop Android. Now, an error is reported every time eclipse is opened, and an error is also reported every time virtual machine is opened. The wrong information is the same.

The error information is as follows:
[2015-05-30-10:14:35 – Android SDK] error when loading the SDK:Error : Error parsing D:/android-sdks/system-images/android-22/android-wear/armeabi-v7a/ devices.xml
CVC complex type. 2.4. D: found invalid content starting with element’d: skin ‘. There should be no child elements here.
Error: Error parsing D:/android-sdks/system-images/android-22/android-wear/x86/ devices.xml
CVC complex type. 2.4. D: found invalid content starting with element’d: skin ‘. There should be no child elements here

——————————————————————————————————————————————————-

Enter the SDK directory and add D/android-sdk/system-images/android-22/android-wear/armeabi-v7a/ devices.xml And D/Android SDK/system images/android-22/Android wear/x86/ devices.xml Delete the file, and then delete the devices.xml Copy it to the folder you deleted, restart eclipse, and solve the problem
then