android - PhoneGap 设备就绪函数未被调用

标签 android cordova

我对 PhoneGap Android 比较陌生,我有一个 iPhone 应用程序,需要迁移到 Android 应用程序 我已将 www 从 iPhone 应用程序添加到我的 Android 应用程序中,并添加了 list 权限,甚至复制了 XML包含 config.xml 和 cordova.xml 的文件夹,但问题是我的设备就绪函数没有被调用

这是我的index.html代码

    <!DOCTYPE html>
     <html>
     <head>

          <meta name="viewport" content="width=device-width, initial-scale=1" />
         <meta name="apple-mobile-web-app-capable" content="yes" />

      <link
      href="http://code.jquery.com/mobile/1.0rc2/jquery.mobile-1.0rc2.min.css"
       rel="stylesheet" />
       <script src="scripts/jquery-1.7.1.min.js" type="text/javascript"></script>

    <link href="css/style.css" type="text/css" rel="stylesheet" />
     <link href="css/index.css" type="text/css" rel="stylesheet" />
    <script src="scripts/app.js" type="text/javascript"></script>
     <script type="text/javascript"
src="http://code.jquery.com/jquery-1.6.4.min.js"></script>
   <script type="text/javascript"
src="http://code.jquery.com/mobile/1.0rc2/jquery.mobile-1.0rc2.min.js"></script>
 <script src="scripts/gallery_handler.js" type="text/javascript"></script>
 <script src="scripts/itpoverlay.js" type="text/javascript"></script>
   <script src="scripts/sqlite.js" type="text/javascript"></script>
    <script src="scripts/jquery.exif.js" type="text/javascript"></script>

    </head>
       <body id="body">
         <div class="app" style="display: none;">
      <div id="deviceready">
        <p class="status pending blink">Connecting to Device</p>
        <p class="status complete blink hide">Device is Ready</p>
    </div>
</div>
<div data-role="page" id="gallerypage" data-theme="a">
    <div data-role="header">
        <h1 class="headtitle">NG DESIIGNS</h1>
    </div>

    <div data-role="content" id="pagecontent">
        <ul id="gallery" class="gallery">

        </ul>
    </div>
</div>
<script type="text/javascript" src="cordova-2.0.0.js"></script>
<script type="text/javascript" src="js/index.js"></script>
<script type="text/javascript">
alert("app to be initialized");
    app.initialize();
    document.addEventListener('deviceready', function() {
        alert("device ready called");
        db.transaction(queryDB, errorCB, successCB);
    }, false);
    document.addEventListener("offline", function() {
        alert("Your Device is offline");
    }, false);
</script>
      </body>
     </html>

这是index.js

    var app = {
    initialize: function() {
    alert("index.js bind");
    this.bind();
   },
    bind: function() {
    alert("index.js bind function calld device ready");
    document.addEventListener('deviceready', this.deviceready, false);
   },
   deviceready: function() {
    alert("device ready");
    // note that this is an event handler so the scope is that of the event
    // so we need to call app.report(), and not this.report()
    app.report('deviceready');
    },
    report: function(id) { 
    console.log("report:" + id);
    // hide the .pending <p> and show the .complete <p>
    document.querySelector('#' + id + ' .pending').className += ' hide';
    var completeElem = document.querySelector('#' + id + ' .complete');
    completeElem.className = completeElem.className.split('hide').join('');
      }
    };

另请参阅 logcat

0-08 10:46:32.294: I/dalvikvm(763): threadid=3: reacting to signal 3
10-08 10:46:32.414: I/dalvikvm(763): Wrote stack traces to '/data/anr/traces.txt'
10-08 10:46:32.664: D/CordovaLog(763): Found preference for phonegap-version=2.0.0
10-08 10:46:32.673: D/CordovaLog(763): Found preference for orientation=default
10-08 10:46:32.673: D/CordovaLog(763): Found preference for target-device=universal
10-08 10:46:32.683: D/CordovaLog(763): Found preference for fullscreen=false
10-08 10:46:32.703: D/JsMessageQueue(763): Set native->JS mode to 1
10-08 10:46:32.803: I/dalvikvm(763): threadid=3: reacting to signal 3
10-08 10:46:32.873: I/dalvikvm(763): Wrote stack traces to '/data/anr/traces.txt'
10-08 10:46:32.934: W/webcore(763): java.lang.Throwable: EventHub.removeMessages(int what = 107) is not supported before the WebViewCore is set up.
10-08 10:46:32.934: W/webcore(763):     at android.webkit.WebViewCore$EventHub.removeMessages(WebViewCore.java:1683)
10-08 10:46:32.934: W/webcore(763):     at android.webkit.WebViewCore$EventHub.access$7900(WebViewCore.java:926)
10-08 10:46:32.934: W/webcore(763):     at android.webkit.WebViewCore.removeMessages(WebViewCore.java:1795)
10-08 10:46:32.934: W/webcore(763):     at android.webkit.WebView.sendOurVisibleRect(WebView.java:2917)
10-08 10:46:32.934: W/webcore(763):     at android.webkit.ZoomManager.setZoomScale(ZoomManager.java:593)
10-08 10:46:32.934: W/webcore(763):     at android.webkit.ZoomManager.access$1700(ZoomManager.java:49)
10-08 10:46:32.934: W/webcore(763):     at android.webkit.ZoomManager$PostScale.run(ZoomManager.java:984)
10-08 10:46:32.934: W/webcore(763):     at android.os.Handler.handleCallback(Handler.java:605)
10-08 10:46:32.934: W/webcore(763):     at android.os.Handler.dispatchMessage(Handler.java:92)
10-08 10:46:32.934: W/webcore(763):     at android.os.Looper.loop(Looper.java:137)
10-08 10:46:32.934: W/webcore(763):     at android.app.ActivityThread.main(ActivityThread.java:4424)
10-08 10:46:32.934: W/webcore(763):     at java.lang.reflect.Method.invokeNative(Native Method)
10-08 10:46:32.934: W/webcore(763):     at java.lang.reflect.Method.invoke(Method.java:511)
10-08 10:46:32.934: W/webcore(763):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
10-08 10:46:32.934: W/webcore(763):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
10-08 10:46:32.934: W/webcore(763):     at dalvik.system.NativeStart.main(Native Method)
10-08 10:46:32.964: D/gralloc_goldfish(763): Emulator without GPU emulation detected.
10-08 10:46:33.823: D/dalvikvm(763): GC_CONCURRENT freed 115K, 3% free 6838K/7047K, paused 4ms+4ms
10-08 10:46:41.603: I/SqliteDatabaseCpp(763): sqlite returned: error code = 14, msg = cannot open file at line 27701 of [8609a15dfa], db=/data/data/com.example.phonegapapp/databases/webview.db
10-08 10:46:41.603: I/SqliteDatabaseCpp(763): sqlite returned: error code = 14, msg = os_unix.c: open() at line 27701 - "" errno=2 path=/CachedGeoposition.db, db=/data/data/com.example.phonegapapp/databases/webview.db
10-08 10:46:41.994: E/Cordova(763): Error loading url gap://ready
10-08 10:46:41.994: E/Cordova(763): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=gap://ready }
10-08 10:46:41.994: E/Cordova(763):     at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1512)
10-08 10:46:41.994: E/Cordova(763):     at android.app.Instrumentation.execStartActivity(Instrumentation.java:1384)
10-08 10:46:41.994: E/Cordova(763):     at android.app.Activity.startActivityForResult(Activity.java:3190)
10-08 10:46:41.994: E/Cordova(763):     at android.app.Activity.startActivity(Activity.java:3297)
10-08 10:46:41.994: E/Cordova(763):     at org.apache.cordova.CordovaWebViewClient.shouldOverrideUrlLoading(CordovaWebViewClient.java:222)
10-08 10:46:41.994: E/Cordova(763):     at android.webkit.CallbackProxy.uiOverrideUrlLoading(CallbackProxy.java:224)
10-08 10:46:41.994: E/Cordova(763):     at android.webkit.CallbackProxy.handleMessage(CallbackProxy.java:324)
10-08 10:46:41.994: E/Cordova(763):     at android.os.Handler.dispatchMessage(Handler.java:99)
10-08 10:46:41.994: E/Cordova(763):     at android.os.Looper.loop(Looper.java:137)
10-08 10:46:41.994: E/Cordova(763):     at android.app.ActivityThread.main(ActivityThread.java:4424)
10-08 10:46:41.994: E/Cordova(763):     at java.lang.reflect.Method.invokeNative(Native Method)
10-08 10:46:41.994: E/Cordova(763):     at java.lang.reflect.Method.invoke(Method.java:511)
10-08 10:46:41.994: E/Cordova(763):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
10-08 10:46:41.994: E/Cordova(763):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
10-08 10:46:41.994: E/Cordova(763):     at dalvik.system.NativeStart.main(Native Method)
10-08 10:46:43.553: E/libEGL(763): call to OpenGL ES API with no current context (logged once per thread)
10-08 10:46:43.553: D/ShaderProgram(763): couldn't load the vertex shader!
10-08 10:46:43.553: E/libEGL(763): call to OpenGL ES API with no current context (logged once per thread)
10-08 10:46:43.553: D/ShaderProgram(763): couldn't load the vertex shader!
10-08 10:46:43.553: E/libEGL(763): call to OpenGL ES API with no current context (logged once per thread)
10-08 10:46:43.553: D/ShaderProgram(763): couldn't load the vertex shader!
10-08 10:46:43.553: E/libEGL(763): call to OpenGL ES API with no current context (logged once per thread)
10-08 10:46:43.553: D/ShaderProgram(763): couldn't load the vertex shader!
10-08 10:46:43.553: E/libEGL(763): call to OpenGL ES API with no current context (logged once per thread)
10-08 10:46:43.553: D/ShaderProgram(763): couldn't load the vertex shader!
10-08 10:51:48.393: I/dalvikvm(828): threadid=3: reacting to signal 3
10-08 10:51:48.413: I/dalvikvm(828): Wrote stack traces to '/data/anr/traces.txt'
10-08 10:51:48.674: D/CordovaLog(828): Found preference for phonegap-version=2.0.0
10-08 10:51:48.694: D/CordovaLog(828): Found preference for orientation=default
10-08 10:51:48.694: D/CordovaLog(828): Found preference for target-device=universal
10-08 10:51:48.694: D/CordovaLog(828): Found preference for fullscreen=false
10-08 10:51:48.704: D/JsMessageQueue(828): Set native->JS mode to 1
10-08 10:51:48.893: I/dalvikvm(828): threadid=3: reacting to signal 3
10-08 10:51:48.934: W/webcore(828): java.lang.Throwable: EventHub.removeMessages(int what = 107) is not supported before the WebViewCore is set up.
10-08 10:51:48.934: W/webcore(828):     at android.webkit.WebViewCore$EventHub.removeMessages(WebViewCore.java:1683)
10-08 10:51:48.934: W/webcore(828):     at android.webkit.WebViewCore$EventHub.access$7900(WebViewCore.java:926)
10-08 10:51:48.934: W/webcore(828):     at android.webkit.WebViewCore.removeMessages(WebViewCore.java:1795)
10-08 10:51:48.934: W/webcore(828):     at android.webkit.WebView.sendOurVisibleRect(WebView.java:2917)
10-08 10:51:48.934: W/webcore(828):     at android.webkit.ZoomManager.setZoomScale(ZoomManager.java:593)
10-08 10:51:48.934: W/webcore(828):     at android.webkit.ZoomManager.access$1700(ZoomManager.java:49)
10-08 10:51:48.934: W/webcore(828):     at android.webkit.ZoomManager$PostScale.run(ZoomManager.java:984)
10-08 10:51:48.934: W/webcore(828):     at android.os.Handler.handleCallback(Handler.java:605)
10-08 10:51:48.934: W/webcore(828):     at android.os.Handler.dispatchMessage(Handler.java:92)
10-08 10:51:48.934: W/webcore(828):     at android.os.Looper.loop(Looper.java:137)
10-08 10:51:48.934: W/webcore(828):     at android.app.ActivityThread.main(ActivityThread.java:4424)
10-08 10:51:48.934: W/webcore(828):     at java.lang.reflect.Method.invokeNative(Native Method)
10-08 10:51:48.934: W/webcore(828):     at java.lang.reflect.Method.invoke(Method.java:511)
10-08 10:51:48.934: W/webcore(828):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
10-08 10:51:48.934: W/webcore(828):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
10-08 10:51:48.934: W/webcore(828):     at dalvik.system.NativeStart.main(Native Method)
10-08 10:51:48.954: D/gralloc_goldfish(828): Emulator without GPU emulation detected.
10-08 10:51:48.954: I/dalvikvm(828): Wrote stack traces to '/data/anr/traces.txt'
10-08 10:51:49.764: D/dalvikvm(828): GC_CONCURRENT freed 119K, 3% free 6839K/7047K, paused 4ms+3ms
10-08 10:52:10.864: I/SqliteDatabaseCpp(828): sqlite returned: error code = 14, msg = cannot open file at line 27701 of [8609a15dfa], db=/data/data/com.example.phonegapapp/databases/webview.db
10-08 10:52:10.874: I/SqliteDatabaseCpp(828): sqlite returned: error code = 14, msg = os_unix.c: open() at line 27701 - "" errno=2 path=/CachedGeoposition.db, db=/data/data/com.example.phonegapapp/databases/webview.db
10-08 10:52:11.233: E/Cordova(828): Error loading url gap://ready
10-08 10:52:11.233: E/Cordova(828): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=gap://ready }
10-08 10:52:11.233: E/Cordova(828):     at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1512)
10-08 10:52:11.233: E/Cordova(828):     at android.app.Instrumentation.execStartActivity(Instrumentation.java:1384)
10-08 10:52:11.233: E/Cordova(828):     at android.app.Activity.startActivityForResult(Activity.java:3190)
10-08 10:52:11.233: E/Cordova(828):     at android.app.Activity.startActivity(Activity.java:3297)
10-08 10:52:11.233: E/Cordova(828):     at org.apache.cordova.CordovaWebViewClient.shouldOverrideUrlLoading(CordovaWebViewClient.java:222)
10-08 10:52:11.233: E/Cordova(828):     at android.webkit.CallbackProxy.uiOverrideUrlLoading(CallbackProxy.java:224)
10-08 10:52:11.233: E/Cordova(828):     at android.webkit.CallbackProxy.handleMessage(CallbackProxy.java:324)
10-08 10:52:11.233: E/Cordova(828):     at android.os.Handler.dispatchMessage(Handler.java:99)
10-08 10:52:11.233: E/Cordova(828):     at android.os.Looper.loop(Looper.java:137)
10-08 10:52:11.233: E/Cordova(828):     at android.app.ActivityThread.main(ActivityThread.java:4424)
10-08 10:52:11.233: E/Cordova(828):     at java.lang.reflect.Method.invokeNative(Native Method)
10-08 10:52:11.233: E/Cordova(828):     at java.lang.reflect.Method.invoke(Method.java:511)
10-08 10:52:11.233: E/Cordova(828):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
10-08 10:52:11.233: E/Cordova(828):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
10-08 10:52:11.233: E/Cordova(828):     at dalvik.system.NativeStart.main(Native Method)
10-08 10:52:12.824: E/libEGL(828): call to OpenGL ES API with no current context (logged once per thread)
10-08 10:52:12.824: D/ShaderProgram(828): couldn't load the vertex shader!
10-08 10:52:12.824: E/libEGL(828): call to OpenGL ES API with no current context (logged once per thread)
10-08 10:52:12.824: D/ShaderProgram(828): couldn't load the vertex shader!
10-08 10:52:12.824: E/libEGL(828): call to OpenGL ES API with no current context (logged once per thread)
10-08 10:52:12.824: D/ShaderProgram(828): couldn't load the vertex shader!
10-08 10:52:12.834: E/libEGL(828): call to OpenGL ES API with no current context (logged once per thread)
10-08 10:52:12.834: D/ShaderProgram(828): couldn't load the vertex shader!
10-08 10:52:12.834: E/libEGL(828): call to OpenGL ES API with no current context (logged once per thread)
10-08 10:52:12.834: D/ShaderProgram(828): couldn't load the vertex shader!

最佳答案

您必须将 www 文件夹中的 cordova.js 更改为 android cordova.js 之一

关于android - PhoneGap 设备就绪函数未被调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12775796/

相关文章:

android - 如何从 PWA 应用主屏幕链接中删除 Chrome Logo (Android O 预览版)

android - 将现有的 gradle 依赖拆分为多个模块

Android 版本 4.4+ Phonegap 中的 sqlite 错误

cordova - cordova 3.5用于分析的插件

android - SpannableString:是否可以应用两个或多个RelativeSizeSpans?

android - 将滑动手势处理添加到撰写 View

java - Android 客户端 - Java 服务器应用程序

android - cordova Android 中的域白名单似乎被忽略了

javascript - Cordova cordova-plugin-qrscanner : Opaque camera view

ios - 找不到 Cordova iOS 插件