상세 컨텐츠

본문 제목

안드로이드 webview swf플래시 로드 관련 Load an SWF into a WebView

스마트기기개발관련/안드로이드 개발

by AlrepondTech 2016. 6. 14. 11:33

본문

반응형

 

 

 

 

 

=================================

=================================

=================================

 

 

 

 

 

 

 

출처: http://stackoverflow.com/questions/2994116/load-an-swf-into-a-webview

 

I'm having problems with this. If I go to an SWF directly in the browser, it works fine. If I attempt to use loadUrl on an SWF file it stays blank and loads nothing.

 

---------------

 

Figured it out. You have to enable plugins.

webview.getSettings().setPluginsEnabled(true);

-------------------

 

Niky, you have a code example here.

I have used this example to test this code and confirm it works. In this example the qualibus.swf is in contained within the assets of the app. Please test this on an actual device, as on the emulator it show a blank page (probably the flash player is not present on the emulator)

Test3Activity.java:

package com.blabla.test3;  import android.app.Activity; import android.os.Bundle; import android.webkit.WebView;  public class Test3Activity extends Activity {     /** Called when the activity is first created. */     @Override     public void onCreate(Bundle savedInstanceState) {         super.onCreate(savedInstanceState);         setContentView(R.layout.main);          String url ="file:///android_asset/qualibus.swf";          WebView wv=(WebView) findViewById(R.id.webView1);         wv.getSettings().setPluginsEnabled(true);         wv.loadUrl(url);     } }

main.xml:

<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"     android:orientation="vertical"     android:layout_width="fill_parent"     android:layout_height="fill_parent"     > <WebView android:id="@+id/webView1"      android:layout_width="match_parent"      android:layout_height="match_parent"> </WebView> </LinearLayout>

Result:

-------------------------------------------------------------

sorry i am have applied the same procedure but stackoverflow.com/questions/9308712/… got this error –

i can not find wv.getSettings().setPluginsEnabled(true); method... i can only find webView.getSettings().setPluginState(PluginState.ON); method... please help me

 

----------------------------------------------------------------

 

The function WebView.getSettings().setPluginsEnabled(); method has been deprecated since API level 9, and was removed in API level 18.

You can use the newer functionWebView.getSettings().setPluginState(WebSettings.PluginState.ON); 
which was added in API level 8 and was deprecated in API level 18.

According to the WebSettings Documentation API levels beyond 18 will not support plugins; I'm assuming it's because the main plugin to support was flash which adobe is no longer developing for mobile.

Quoted from source

So, for now you can use it till 18, and handle compatibility with higher APIs (sadly)

 

 

 

 

=================================

=================================

=================================

 

 

 

출처: http://stackoverflow.com/questions/6106636/how-to-play-local-swf-files-in-a-webview

 

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 via url....but getting difficulty in playing local file inside webview

 

-----------------------------------------------------

What URL do you use to play it via the Browser? That should be the URL you should point your WebView to.– Lukas Knuth May 24 '11 at 6:59

 

------------------------------------------------------

Am using the code as: <html > <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Flash</title> </head> <body> <object width="550" height="400"> <param name="movie" value="circa-med.swf""> <embed src="circa-med.org/circa-med.swf"; width="550" height="400"> </embed> </object> </body> </html> Its working fine...Instead the url I want to use the code as <embed src=\"file:///sdcard/sample.swf\" to take the file from sdcard – Vivek Tamrakar May 24 '11 at 7:39 

 

-------------------------------------------------------

 

 

swf2.html:

<html>   <head>     <meta http-equiv="Content-Type" content="text/html" charset="UTF-8" />   </head>   <body>     <object width="215" height="140">       <param name="movie" value="choudanse7us.swf">         <embed src="file:///mnt/sdcard/choudanse7us.swf"                width="215" height="140">         </embed>     </object>   </body> </html>

below is the android code

package webView.video; import android.app.Activity; import android.os.Bundle; import android.os.Environment; import android.webkit.WebView;   public class WebViewActivity extends Activity { private WebView mWebView;  /** Called when the activity is first created. */      @Override      public void onCreate (Bundle savedInstanceState) {          super. onCreate (savedInstanceState);          setContentView(R.layout.main);             // html file with sample swf video in sdcard           //swf2.html points to swf in sdcard           mWebView = (WebView)findViewById(R.id.webview);          mWebView.getSettings().setJavaScriptEnabled(true);          mWebView.getSettings().setPluginsEnabled(true);          mWebView.getSettings().setAllowFileAccess(true);            if (!Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)){              System.exit(4);          } else {              mWebView.loadUrl("file://" + Environment.getExternalStorageDirectory() + "/swf2.html");          }       } }
shareimprove this answer

 

------------------------------------------------------

i have tried the same code but got this error stackoverflow.com/questions/9308712/… how to solve this? –

 

--------------------------------------------------------

 

@VENKI did you get answer to your question? I faced the same problem, and in my application also it was showing that blue colored cube with question mark symbol. I managed to solve it. I had flash installed in my device and still I was getting that cube. Let me know if you need the answer. – vaibhav Mar 2 '12 at 13:05

 

---------------------------------------------------------

 

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);

----------------------------------------------------------

Thanks but my doubt is while running swf file in browser (from server) we use these lines: "<param name=\"movie\" value=\"circa-med.swf\"> " + "<embed src=\"circa-med.org/circa-med.swf\" width=\"160\" height=\"180\"> " + "</embed>"+ "</object>" ........But for local file how to give path under<embed> tag – Vivek Tamrakar May 24 '11 at 9:09 

----------------------------------------------------------

Well, the first question is whether you need it to be embedded in a web page at a specific pixel size... if not, the above solution may be more useful. If you do need it embedded, does <param name=\"movie\" value=\"file:///android_asset/YourFile.swf\">... work for assets? If it does, you could probably edit the HTML string programmatically to include the results of "file://" + Environment.getExternalStorageDirectory() + "/YourPath/YourFile.swf" as the embedded file, for files on the SD card. – Sven Viking May 24 '11 at 9:26 

--------------------------------------------------------------

You'd still need to set setAllowFileAccess(true) and add the Permission as mentioned above, of course, for reading from the SD card. – Sven Viking May 24 '11 at 9:33

-------------------------------------------------------------

 

Afraid I haven't worked with .3gp files before -- I didn't know the Android WebView even supported them.EDIT: I just did some quick Googling, and from what I can see I'm pretty sure the WebView cannot load .3gp files. – Sven Viking May 24 '11 at 13:34 

-----------------------------------------------------------------------

 

 
The problem is just that the WebView has no height or width. Change the addView line to:linearLayout.addView(webview, LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT); . I just tried this myself, and it worked fine. – Sven VikingMay 25 '11 at 7:45 

 

----------------------------------------------------------------------------------------------------

 

 

import android.app.Activity; import android.os.Bundle; import android.os.Environment; import android.webkit.WebView;   public class WebViewActivity extends Activity { private WebView mWebView;  /** Called when the activity is first created. */      @Override      public void onCreate (Bundle savedInstanceState) {          super. onCreate (savedInstanceState);          setContentView(R.layout.main);             // html file with sample swf video in sdcard           //swf2.html points to swf in sdcard           mWebView = (WebView)findViewById(R.id.webview);          mWebView.getSettings().setJavaScriptEnabled(true);          mWebView.getSettings().setPluginsEnabled(true);          mWebView.getSettings().setAllowFileAccess(true);            if (!Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)){              System.exit(4);          } else {              mWebView.loadUrl("file://" + Environment.getExternalStorageDirectory() + "/swf2.html");          }       } }
shareimprove this answer

 

 

=================================

=================================

=================================

 

 

 

 

 

 

 

 

 

 

반응형


관련글 더보기

댓글 영역