WebSocket in Android WebView

前端 未结 3 828
长发绾君心
长发绾君心 2020-12-14 10:44

today my problem is that I am developing an app that is using a WebSocket. On iOS everything is working out fine but on android the WebView doesn\'t support the WebSocket. W

相关标签:
3条回答
  • 2020-12-14 11:08

    I created a sample project which adds the WebSocket object to the WebView for phonegap. You can find it here: https://github.com/pusher/pusher-phonegap-android

    I put up a video going over the project here: http://blog.pusher.com/2012/7/5/pusher-on-phonegap-for-android

    I used this project to demonstrate how to use PhoneGap with Pusher on Android but ultimately it's just a project that happens to include the Pusher script tag. You could easily use another library that needs the WebSocket object or just use it directly.

    It uses the websocket-android-phonegap library: https://github.com/anismiles/websocket-android-phonegap

    0 讨论(0)
  • 2020-12-14 11:09

    check your error code first;if the code is :ERR_CLEARTEXT_NOT_PERMITTED; Try to add android:usesCleartextTraffic="true" to you application tag in your AndroidManifest.xml like below:

     <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:theme="@style/AppTheme"
        android:usesCleartextTraffic="true">
    
    0 讨论(0)
  • 2020-12-14 11:18

    Android webview doesn't accommodate WebSocket. So you need to implement with some WebSocket library.

    jWebSocket http://jwebsocket.org/

    weberknecht http://code.google.com/p/weberknecht/

    0 讨论(0)
提交回复
热议问题