1

我想开发一个使用电话间隙的混合 Android 移动应用程序。

首先: 我已经开发了响应式 Web 应用程序,该应用程序在 Web 浏览器中运行良好。还使用 Ripple 模拟器插件(chrome 浏览器)在 android 中进行模拟。

现在 我想把它转换成ANDROID MobileAPP,所以我选择了phonegap。我已经阅读了一些基本教程,并将所有 css/js/images/ 等文件夹放在asset->www-> 文件夹中,
在 index.html 中我参考了 cordova.js 我在 java 文件中对 loadurl(file:/// .........index.html)
和结果...模拟器显示警告消息..“不幸的是,'appname' 已停止工作....

并且logcat错误是:我不确定它指向什么......所以需要帮助。如果我看到我的应用程序在移动设备上运行,我感觉很棒。

注意:“hello world”index.html 工作正常,但不是我自己的 index.html 和..我使用了 angular js,less.js(less.js 编译得很好,我可以从日志中查看)

         -> 11-09 13:06:37.768: E/CordovaWebView(1549): CordovaWebView: TIMEOUT ERROR!
         -> 11-09 13:06:37.778: D/Cordova(1549): CordovaWebViewClient.onReceivedError:
Error      code=-6 Description=The connection to the server was unsuccessful.             URL=file:///android_asset/www/index.html
     -> 11-09 13:06:37.778: D/CordovaActivity(1549): onMessage(onReceivedError,{"errorCode":-6,"url":"file:\/\/\/android_asset\/www\/index.html","description":"The connection to the server was unsuccessful."})
     -> 11-09 13:06:38.128: I/Choreographer(1549): Skipped 78 frames!  The application may be doing too much work on its main thread.
     -> 11-09 13:06:38.128: D/SoftKeyboardDetect(1549): Ignore this event
     -> 11-09 13:06:38.528: I/Choreographer(1549): Skipped 68 frames!  The application may be doing too much work on its main thread.
     -> 11-09 13:06:40.118: D/AndroidRuntime(1549): Shutting down VM
     -> 11-09 13:06:40.118: W/dalvikvm(1549): threadid=1: thread exiting with uncaught exception (group=0xb3a3bb90)
     -> 11-09 13:06:40.148: E/AndroidRuntime(1549): FATAL EXCEPTION: main
     -> 11-09 13:06:40.148: E/AndroidRuntime(1549): Process: com.example.test, PID: 1549
     -> 11-09 13:06:40.148: E/AndroidRuntime(1549): java.lang.RuntimeException: Error receiving broadcast Intent { act=android.net.conn.CONNECTIVITY_CHANGE flg=0x4000010 (has extras) } in org.apache.cordova.NetworkManager$1@b3e0a2e0
     -> 11-09 13:06:40.148: E/AndroidRuntime(1549):     at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:778)
     -> 11-09 13:06:40.148: E/AndroidRuntime(1549):     at android.os.Handler.handleCallback(Handler.java:733)
     -> 11-09 13:06:40.148: E/AndroidRuntime(1549):     at android.os.Handler.dispatchMessage(Handler.java:95)
     -> 11-09 13:06:40.148: E/AndroidRuntime(1549):     at android.os.Looper.loop(Looper.java:137)
     -> 11-09 13:06:40.148: E/AndroidRuntime(1549):     at android.app.ActivityThread.main(ActivityThread.java:4998)
     -> 11-09 13:06:40.148: E/AndroidRuntime(1549):     at java.lang.reflect.Method.invokeNative(Native Method)
     -> 11-09 13:06:40.148: E/AndroidRuntime(1549):     at java.lang.reflect.Method.invoke(Method.java:515)
     -> 11-09 13:06:40.148: E/AndroidRuntime(1549):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:777)
     -> 11-09 13:06:40.148: E/AndroidRuntime(1549):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:593)
     -> 11-09 13:06:40.148: E/AndroidRuntime(1549):     at dalvik.system.NativeStart.main(Native Method)
     -> 11-09 13:06:40.148: E/AndroidRuntime(1549): Caused by: java.lang.SecurityException: ConnectivityService: Neither user 10051 nor current process has android.permission.ACCESS_NETWORK_STATE.
     -> 11-09 13:06:40.148: E/AndroidRuntime(1549):     at android.os.Parcel.readException(Parcel.java:1461)
     -> 11-09 13:06:40.148: E/AndroidRuntime(1549):     at android.os.Parcel.readException(Parcel.java:1415)
     -> 11-09 13:06:40.148: E/AndroidRuntime(1549):     at android.net.IConnectivityManager$Stub$Proxy.getActiveNetworkInfo(IConnectivityManager.java:813)
     -> 11-09 13:06:40.148: E/AndroidRuntime(1549):     at android.net.ConnectivityManager.getActiveNetworkInfo(ConnectivityManager.java:560)
     -> 11-09 13:06:40.148: E/AndroidRuntime(1549):     at org.apache.cordova.NetworkManager$1.onReceive(NetworkManager.java:107)
     -> 11-09 13:06:40.148: E/AndroidRuntime(1549):     at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:768)
     -> 11-09 13:06:40.148: E/AndroidRuntime(1549):     ... 9 more
     -> 11-09 13:06:40.188: W/System.err(1549): java.lang.SecurityException: ConnectivityService: Neither user 10051 nor current process has android.permission.ACCESS_NETWORK_STATE.
     -> 11-09 13:06:40.248: W/System.err(1549):     at android.os.Parcel.readException(Parcel.java:1461)
     -> 11-09 13:06:40.248: W/System.err(1549):     at android.os.Parcel.readException(Parcel.java:1415)
     -> 11-09 13:06:40.258: W/System.err(1549):     at android.net.IConnectivityManager$Stub$Proxy.getActiveNetworkInfo(IConnectivityManager.java:813)
     -> 11-09 13:06:40.258: W/System.err(1549):     at android.net.ConnectivityManager.getActiveNetworkInfo(ConnectivityManager.java:560)
     -> 11-09 13:06:40.258: W/System.err(1549):     at org.apache.cordova.NetworkManager.execute(NetworkManager.java:127)
     -> 11-09 13:06:40.258: W/System.err(1549):     at org.apache.cordova.api.CordovaPlugin.execute(CordovaPlugin.java:66)
     -> 11-09 13:06:40.258: W/System.err(1549):     at org.apache.cordova.api.PluginManager.exec(PluginManager.java:215)
     -> 11-09 13:06:40.268: W/System.err(1549):     at org.apache.cordova.ExposedJsApi.exec(ExposedJsApi.java:51)
     -> 11-09 13:06:40.268: W/System.err(1549):     at com.android.org.chromium.base.SystemMessageHandler.nativeDoRunLoopOnce(Native Method)
     -> 11-09 13:06:40.268: W/System.err(1549):     at com.android.org.chromium.base.SystemMessageHandler.handleMessage(SystemMessageHandler.java:27)
     -> 11-09 13:06:40.268: W/System.err(1549):     at android.os.Handler.dispatchMessage(Handler.java:102)
     -> 11-09 13:06:40.268: W/System.err(1549):     at android.os.Looper.loop(Looper.java:137)
     -> 11-09 13:06:40.358: W/System.err(1549):     at android.os.HandlerThread.run(HandlerThread.java:61)
     -> 11-09 13:06:58.018: I/Process(1549): Sending signal. PID: 1549 SIG: 9

}

更新:执行问题解决的以下步骤.....

与服务器的连接不成功。可以通过增加超时来解决...

    <preference name="load-url-timeout" value="60000" />

将其粘贴到 config.xml 或

让你的 index.html 看起来像这样

   <!doctype html>
    <html>
  <head>
    <title>tittle</title>
    <script>
        window.location='./main.html';
    </script>
  <body>        
</body>
   </html>      

在此之前将 index.html 内容移动到 main.html...

而其他(java.lang.RuntimeException: Error received broadcast Intent)错误可以通过正确定义权限来处理

<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.RECEIVE_SMS" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.WRITE_CONTACTS" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> 
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.BROADCAST_STICKY" />

2. manifest.xml 中的活动名称...

  <application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
    android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale"
        android:name="com.example.test.MainActivity" // u can use yours..ofcourse its //automatically generated by eclipse IDE
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>
4

1 回答 1

3

线

Neither user 10051 nor current process has android.permission.ACCESS_NETWORK_STATE

指出,您的应用程序没有获得此权限。检查您的AndroidManifest.xml并添加该行

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

lg

快速

于 2013-11-09T18:29:18.510 回答