不支持协议(Android)

时间:2014-05-12 04:42:06

标签: java javascript android cordova

我正在尝试在手机间隙中开发应用程序。它监视服务器作业。目前服务器不可用所以我把我的系统作为服务器。我将项目文件放在安装我的服务器的同一目录中。我试图在主要活动中访问我的文件。但它在我的模拟器上显示错误。错误标题为不支持协议。我在下面分享主要活动文件和html文件。请看这些文件。 主要活动文件:

package com.example.productionmonitor;
import org.apache.cordova.DroidGap;
import android.os.Bundle;
import android.view.Menu;

public class MainActivity extends DroidGap{

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        System.out.println("Here");
        super.setIntegerProperty("loadUrlTimeoutValue",120000);
       super.loadUrl("file////C:/Program Files/Elixir Technologies/Tango/tomcat/webapps/productionmanagerserver/Monitor app/productionMonitor.htm");
        //super.loadUrl("file:///android_asset/www/productionMonitor.htm");
        //super.loadUrl("C:///|\Program Files\/Elixir Technologies\/Tango\tomcat\webapps\productionmanagerserver\Monitor app\productionMonitor.htm");
        //super.loadUrl("http:///localhost:8080/productionmanagerserver/productionMonitor.htm");

    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

}

这是我保存在位置的 html文件(C:\ Program Files \ Elixir Technologies \ Tango \ tomcat \ webapps \ productionmanagerserver \ Monitor app \ login.html),我想访问这个档案。

<!doctype html>
<html lang="en-US">
<head>

    <meta charset="utf-8">

    <title>Login</title>

    <link rel="stylesheet" href="http://fonts.googleapis.com/css?family=Varela+Round">
    <link rel="stylesheet" href="./files/login.css">

    <!--[if lt IE 9]>
        <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
    <![endif]-->

    <script>
    var strFile ;
    function userLogin()
    {
        window.location.href = "productionMonitor.htm";
    }
    function init()
        {
            var xmlhttp = null ;
            try {
                xmlhttp = new XMLHttpRequest();
            } catch (trymicrosoft) {
                try {
                    xmlhttp = new ActiveXObject("MsXML2.XMLHTTP");
                } catch (othermicrosoft) {
                    try {
                        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
                    } catch (failed) {
                            xmlhttp = null;
                        }
                    }
                }

            if (xmlhttp == null)
            alert("Error creating request object!");

            if ("withCredentials" in xmlhttp) {

                // Check if the XMLHttpRequest object has a "withCredentials" property.
                // "withCredentials" only exists on XMLHTTPRequest2 objects.
                //xhr.open(method, url, true);

            } else if (typeof XDomainRequest != "undefined") {

                // Otherwise, check if XDomainRequest.
                // XDomainRequest only exists in IE, and is IE's way of making CORS requests.
                xmlhttp = new XDomainRequest();

            }               

            return xmlhttp ;
        }

        function CallWebservice()
        {

            var req = init() ;

            var url ="http://localhost:8080/identityserver/domains/allData";
            req.open('GET',url,true);
            req.send(null);             
            req.onreadystatechange = function() {
                if (req.readyState != 4) return; // Not there yet
                if (req.status != 200) {
                     // Handle request failure here...
                    alert("Call failed");
                    return;
                }
                // Request successful, read the response
                strFile = req.responseText ;
                parseDomainList(strFile);                       
            }
        }

        function parseDomainList(dlist)
        {
            var xmlDoc = new DOMParser().parseFromString(strFile,'text/xml');
            var domain = xmlDoc.getElementsByTagName("domain");
            for (i=0;i<domain.length;i++)
            {
                var dname =domain[i].getElementsByTagName("domain_name");
                var domainid = document.getElementById("domain") ;
                var option=document.createElement("option");
                domainid.appendChild(option);               
            }
            alert(strFile) ;
            userLogin() ;
        }

    </script>

</head>

<body>

    <div id="login">

        <h2><span class="fontawesome-lock"></span>Sign In</h2>

        <form action="javascript:void(0);" method="POST">

            <fieldset>

                <p><label for="email">User Name</label></p>
                <p><input type="email" id="email" value="admin" onBlur="if(this.value=='')this.value='admin'" onFocus="if(admin')this.value=''"></p> 

                <p><label for="password">Password</label></p>
                <p><input type="password" id="password" value="admin" onBlur="if(this.value=='')this.value='admin'" onFocus="if(this.value=='admin')this.value=''"></p>

                <p><label for="domain">Domain List</label></p>
                <p><select type="domain" id="domain"> </select> </p>                

                <p><input type="submit" value="Sign In" onclick="CallWebservice()"></p>

            </fieldset>

        </form>

    </div> <!-- end login -->

</body> 
</html>

1 个答案:

答案 0 :(得分:1)

将文件放在Windows计算机上的位置并不重要。您的Android设备和模拟器都无法访问它们。如果你考虑一下,那会很可怕。

您需要将开发机器转换为适当的服务器,然后使用来自模拟器的特殊IP地址10.0.2.2访问它,这是开发机器的环回。如果您正在设备上进行测试,则需要访问开发机器的本地IP地址,假设您在同一个LAN上。