2015-05-19 210 views
1

我們正在使用Ionic(+ Cordova)構建一個Android應用程序。Ionic - 沒有互聯網連接

它在瀏覽器中所有的作品,但是當我建立並運行發生這種情況.apk文件:

外部圖像不會出現,內嵌谷歌地圖保持爲空。

<!DOCTYPE html> 
<html> 
<head> 
    <meta charset="utf-8"> 
    <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width"> 
    <title></title> 
    <link href="lib/ionic/css/ionic.css" rel="stylesheet"> 
    <link href="css/style.css" rel="stylesheet"> 

    <!-- IF using Sass (run gulp sass first), then uncomment below and remove the CSS includes above 
    <link href="css/ionic.app.css" rel="stylesheet"> 
    --> 

    <!-- ionic/angularjs js --> 
    <script src="lib/ionic/js/ionic.bundle.js"></script> 
    <script src="js/ng-cordova.min.js"></script> 

    <!-- cordova script (this will be a 404 during development) --> 
    <script src="cordova.js"></script> 

    <!-- your app's js --> 
    <script src="js/app.js"></script> 
</head> 
<body ng-app="starter"> 

    <ion-pane> 
      <ion-header-bar class="bar-stable"> 

      </ion-header-bar> 
      <ion-content> 
      <div class="main" role="main"> 

       <p id="geolocation">Finding geolocation...</p> 
       <img src="http://placehold.it/350x150.png" alt="no image" /> 

       <iframe src="https://www.google.com/maps/embed?pb=!1m14!1m12!1m3!1d635472.0298105411!2d5.1189025!3d51.525825749999996!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!5e0!3m2!1snl!2snl!4v1432033961557" width="600" height="450" frameborder="0" style="border:0"></iframe> 
      </div> 
      </ion-content> 
    </ion-pane> 
</body> 
</html> 

在我們剛剛的結束標記後創建以下行config.xml文件:在我們的index.html下面的代碼

<allow-navigation href="*" /> 
<allow-intent href="*" /> 
+0

什麼是您的互聯網許可? –

+1

[與Android Hybid應用程序顯示遠程圖像與Ionic框架問題的可能的重複?](http://stackoverflow.com/questions/29912773/issue-with-android-hybid-app-to-display-remote-image- with-ionic-framework) – Keval

+0

@mahdi pishguy你的意思是這條線嗎?

回答

7

檢查清單,讓您的應用使用互聯網。

<uses-permission android:name="android.permission.INTERNET" /> 

如果您正在使用科爾多瓦5(Android平臺版本4.0.0),那麼你應該包括白名單插件,也是新content security policy meta標籤,以允許谷歌地圖API來加載這樣的(上頂你與其他meta標籤以及HTML文件):

<meta http-equiv="Content-Security-Policy" content="default-src *; 
style-src 'self' 'unsafe-inline' http://fonts.googleapis.com/; 
script-src 'self' 'unsafe-inline' 'unsafe-eval' http://*.googleapis.com 
http://maps.gstatic.com;"> 

編輯: 檢查也是你的config.xml你所付出的訪問:

<access origin="*" /> 

例如允許所有連接

如果它不起作用,請檢查您的日誌併發布任何錯誤。

+1

訣竅,謝謝! –

+0

我有同樣的問題,添加'android.permission.INTERNET'沒有辦法,我不知道如何刪除權限! – Azmeer