How to Play local swf files in a webview

后端 未结 3 1021
没有蜡笔的小新
没有蜡笔的小新 2020-11-29 03:05

Am trying to play local .swf files (kept in asset or sdcard) inside webview. But am not getting any luck...Can anyone guide me the proper way??? I am able to play swf files

3条回答
  •  半阙折子戏
    2020-11-29 03:41

    For assets:

    webView.loadUrl("file:///android_asset/YourFile.swf");
    

    will play the file auto-scaled to the WebView size.


    For the SD card, I expect something like this would work:

    if (!Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)){
        Log.d(TAG, "No SDCard");
    } else {
        webView.loadUrl("file://" + Environment.getExternalStorageDirectory() + "/YourPath/YourFile.swf");
    }
    

    (Using the READ_EXTERNAL_STORAGE permission, of course).

    Edit: You may also need to set:

    webView.getSettings().setAllowFileAccess(true);
    

提交回复
热议问题