javascript - Phonegap cordova 404 not found on Android -
i'm making application need use distant http server. in browser have no trouble ajax/inappbrowser/iframe when build , running in android doesn't work anymore.
i used distant chrome debugger , noticed request returning 404 not found cache, i'm guessing application not have right make request on web. searched solution can't figure out come from.
here config.xml:
<?xml version='1.0' encoding='utf-8'?> <widget id="foo" version="0.0.1" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0"> <name>foo</name> <description> foo </description> <author email="dev@cordova.apache.org" href="http://cordova.io"> </author> <content src="index.html" /> <plugin name="cordova-plugin-whitelist"/> <access origin="*" /> <allow-intent href="*" /> <allow-navigation href="*" /> <access origin="*" /> <platform name="android"> <allow-intent href="market:*" /> <access origin="*" /> <allow-intent href="*" /> <allow-navigation href="*" /> </platform> <platform name="ios"> <allow-intent href="itms:*" /> <allow-intent href="itms-apps:*" /> </platform> <engine name="android"/> <plugin name="cordova-plugin-inappbrowser"/>
i tried start again beggining simpliest. of lines maybe useless tried differents solutions fix problem.
index.html:
<!doctype html> <!-- licensed apache software foundation (asf) under 1 or more contributor license agreements. see notice file distributed work additional information regarding copyright ownership. asf licenses file under apache license, version 2.0 (the "license"); may not use file except in compliance license. may obtain copy of license @ http://www.apache.org/licenses/license-2.0 unless required applicable law or agreed in writing, software distributed under license distributed on "as is" basis, without warranties or conditions of kind, either express or implied. see license specific language governing permissions , limitations under license. --> <html> <head> <!-- customize policy fit own app's needs. more guidance, see: https://github.com/apache/cordova-plugin-whitelist/blob/master/readme.md#content-security-policy notes: * gap: required on ios (when using uiwebview) , needed js->native communication * https://ssl.gstatic.com required on android , needed talkback function * disables use of inline scripts in order mitigate risk of xss vulnerabilities. change this: * enable inline js: add 'unsafe-inline' default-src --> <!-- <meta http-equiv="content-security-policy" content="default-src 'self' data: gap: https://ssl.gstatic.com 'unsafe-eval'; style-src 'self' 'unsafe-inline'; media-src *"> --> <meta http-equiv="content-security-policy" content="default-src 'self' * ws://localhost:35729 data: gap: https://ssl.gstatic.com; style-src 'self' 'unsafe-inline'; media-src *;script-src 'self' localhost:35729 'unsafe-eval' 'unsafe-inline';"> <meta name="format-detection" content="telephone=no"> <meta name="msapplication-tap-highlight" content="no"> <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width"> <link rel="stylesheet" type="text/css" href="css/index.css"> <title>hello world</title> </head> <body> <center><div class=""> <div id="deviceready" class="row col s12"> <h1>foo</h1> <div class="input-field col s8"> <input type="text" id="addr" name="addr" placeholder="adresse"> </div> <div class="input-field col s4"> <input type="text" id="port" placeholder="port"> </div> <div class="input-field col s12"> <input type="text" id="name" placeholder="nom d'utilisateur"> </div> <div class="input-field col s12"> <input type="password" id="pswd" placeholder="mot de passe"> </div> <button id="button_test" class="waves-effect waves-light btn blue lighten-1" value="tester">tester</button> <button id="button_start" class="waves-effect waves-light btn blue lighten-1" value="commencer">commencer</button> </div> <div id="result"></div> <div id="window-iframe"></div> </div></center> <script type="text/javascript" src="cordova.js"></script> <script type="text/javascript" src="js/jquery.min.js"></script> <script type="text/javascript" src="js/index.js"></script> </body>
index.js
/* * licensed apache software foundation (asf) under 1 * or more contributor license agreements. see notice file * distributed work additional information * regarding copyright ownership. asf licenses file * under apache license, version 2.0 (the * "license"); may not use file except in compliance * license. may obtain copy of license @ * * http://www.apache.org/licenses/license-2.0 * * unless required applicable law or agreed in writing, * software distributed under license distributed on * "as is" basis, without warranties or conditions of * kind, either express or implied. see license * specific language governing permissions , limitations * under license. */ var app = { // application constructor initialize: function() { this.bindevents(); }, // bind event listeners // // bind events required on startup. common events are: // 'load', 'deviceready', 'offline', , 'online'. bindevents: function() { document.addeventlistener('deviceready', this.ondeviceready, false); }, // deviceready event handler // // scope of 'this' event. in order call 'receivedevent' // function, must explicitly call 'app.receivedevent(...);' ondeviceready: function() { app.receivedevent('deviceready'); }, // update dom on received event receivedevent: function(id) { var parentelement = document.getelementbyid(id); var listeningelement = parentelement.queryselector('.listening'); var receivedelement = parentelement.queryselector('.received'); listeningelement.setattribute('style', 'display:none;'); receivedelement.setattribute('style', 'display:block;'); console.log('received event: ' + id); } }; function debug(string){ $("#result").html($("#result").html()+"</br>"+string); } debug("ready"); document.getelementbyid("button_test").addeventlistener("click", test); document.getelementbyid("button_start").addeventlistener("click", start); document.getelementbyid("addr").value = localstorage.getitem("address"); document.getelementbyid("port").value = localstorage.getitem("port"); document.getelementbyid("name").value = localstorage.getitem("username"); document.getelementbyid("pswd").value = localstorage.getitem("password"); function test(){ debug("connecting..."); console.log("connecting..."); addr = document.getelementbyid("addr").value; port = document.getelementbyid("port").value; username = document.getelementbyid("name").value; password = document.getelementbyid("pswd").value; url_req = "http://www.lemonde.fr/"; // url_req = 'http://'+addr+':'+port;//'/actions.php?do=auth&login='+username+'&password='+password; debug("connecting...to->"+url_req) $.ajax({ url: url_req, timeout: 30000, success: function(data, status, xhr) { debug("ajax sucess"); console.log(data); data = json.parse(data); if(data.return == "success"){ $("#result").html("ok"); } else { debug("page return fail"); $("#result").html(data.error); } }, error: function (xhr, ajaxoptions, thrownerror) { debug("error->"+thrownerror); } }); localstorage.setitem("address", addr); localstorage.setitem("port", port); localstorage.setitem("username", username); localstorage.setitem("password", password); } function start(){ addr = document.getelementbyid("addr").value; port = document.getelementbyid("port").value; username = document.getelementbyid("name").value; password = document.getelementbyid("pswd").value; $("#window-iframe").html("<iframe src='http://www.lemonde.fr/' width='800px' height='600px'></iframe>"); //var ref = window.open('http://www.lemonde.fr/', '_blank', 'location=yes'); } app.initialize();
androidmanifest
<?xml version='1.0' encoding='utf-8'?> <manifest android:hardwareaccelerated="true" android:versioncode="1" android:versionname="0.0.1" package="foo" 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" /> <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="14" android:targetsdkversion="23" /> <uses-permission android:name="android.permission.internet" /> <uses-permission android:name="android.permission.access_network_state" /> <uses-permission android:name="android.permission.read_phone_state" /> </manifest>
Comments
Post a Comment