1. Download our Official Android App: Forums for Android!

Apps Play a local swf-file (flash) with webview?

Discussion in 'Android Development' started by xtreme, Sep 9, 2010.

  1. xtreme

    xtreme Lurker
    Thread Starter
    Rank:
    None
    Points:
    5
    Posts:
    4
    Joined:
    May 4, 2010

    May 4, 2010
    4
    0
    5
    I guess webview is the best solution to play a local swf-file (flash). I just get cryptic character in the emulator with this html code in webview.

    HTML:
    1.  
    2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    3. <html xmlns="http://www.w3.org/1999/xhtml">
    4. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    5. <title>Flash</title>
    6. </head>
    7.  
    8. <object width="550" height="400">
    9. <param name="movie" value="Flashfile.swf">
    10. <embed src="Flashfile.swf" width="550" height="400">
    11.  
    12. </body>
    13. </html>
    14.  
    15.  
    How can i play a local swf-file when the user click on some kind of link, java or html?
     

    Advertisement

  2. Profete162

    Profete162 Lurker
    Rank:
    None
    Points:
    5
    Posts:
    9
    Joined:
    Dec 18, 2009

    Dec 18, 2009
    9
    0
    5
    Same question here, sorry to spam this forum, but this question was asked several times, and I could n t find any clue..
     
  3. ab0mbs

    ab0mbs Lurker
    Rank:
    None
    Points:
    6
    Posts:
    5
    Joined:
    Feb 6, 2011

    Feb 6, 2011
    5
    2
    6
    If you want to play it in a webview you would first need to create your webview with these settings

    Code (Text):
    1.  
    2.  
    3.         mWebView = (WebView) findViewById(R.id.webview);
    4.         mWebView.getSettings().setJavaScriptEnabled(true);
    5.         mWebView.getSettings().setPluginsEnabled(true);
    6.  
    You can then load data into the webview like so
    Code (Text):
    1.  
    2.  
    3.         String html = "<object width=\"550\" height=\"400\"> <param name=\"movie\" value=\"file:///sdcard/flash/2204355.swf\"> <embed src=\"file:///sdcard/flash/2204355.swf\" width=\"550\" height=\"400\"> </embed> </object>";
    4.         String mimeType = "text/html";
    5.         String encoding = "utf-8";
    6.        
    7.         mWebView.loadDataWithBaseURL("null", html, mimeType, encoding, "");
    8.  
    I simply made custom html inside the program and told it to load a flash file that I had stored in the flash folder on my sdcard.

    keep in mind that in the custom html you have to escape the " with a back slash like this \" so that it wont end the string. You also have to have it all on one line unless you want to append strings together like so

    Code (Text):
    1. String myString = "something" + "something else"
     
    powerpoint45 and CBarbas like this.
  4. Profete162

    Profete162 Lurker
    Rank:
    None
    Points:
    5
    Posts:
    9
    Joined:
    Dec 18, 2009

    Dec 18, 2009
    9
    0
    5
    Yes, thank a lot, but by a local file, I meant a file from the asset folder.

    Of, course, I can copy it to the SdCard, but wouldn't it be better and cleaner for the user to use the asset folder, something like:


    Code (Text):
    1. value=\":///[B]asset folder[/B]/2204355.swf\"
    Thank a lot.
     
  5. ab0mbs

    ab0mbs Lurker
    Rank:
    None
    Points:
    6
    Posts:
    5
    Joined:
    Feb 6, 2011

    Feb 6, 2011
    5
    2
    6
    if you want to use a file in the assets folder you would just have to change this part of the html string from this
    Code (Text):
    1.  
    2. <param name=\"movie\" value=\"file:///sdcard/flash/2204355.swf\"> <embed src=\"file:///sdcard/flash/2204355.swf\" width=\"550\" height=\"400\">
    3.  
    and change the value and src parts to this

    Code (Text):
    1.  
    2. <param name=\"movie\" value=\"file:///android_asset/2204355.swf\"> <embed src=\"file:///android_asset/2204355.swf\" width=\"550\" height=\"400\">
    3.  
    All you have to do is put the file in the assets folder. And make sure when you add it to your project that you copy the file in and not just link to it
     
  6. Profete162

    Profete162 Lurker
    Rank:
    None
    Points:
    5
    Posts:
    9
    Joined:
    Dec 18, 2009

    Dec 18, 2009
    9
    0
    5
    Just amazing!
    One of my client is asking for a tablet-sized presentation for his marketting team.
    They wanted to make an interactive presentation of their products.

    Making animations with Android was really hurting and painful!
    Flash just saved my life.

    Thank a lot, man!
     
  7. fou

    fou Lurker
    Rank:
    None
    Points:
    5
    Posts:
    1
    Joined:
    Mar 24, 2011

    Mar 24, 2011
    1
    0
    5
    Hi
    I try this code but the swf didn't display into the webview.

    Code (Text):
    1. public void onCreate(Bundle savedInstanceState) {
    2.         super.onCreate(savedInstanceState);
    3.         setContentView(R.layout.main);
    4.         objectview= (WebView)this.findViewById(R.id.webkit);
    5.         //ex
     

    Attached Files:

    • im.JPG
      im.JPG
      File size:
      4.4 KB
      Views:
      48
  8. yogidk

    yogidk Lurker
    Rank:
    None
    Points:
    5
    Posts:
    2
    Joined:
    Apr 6, 2011

    Apr 6, 2011
    2
    0
    5
    public void onCreate(Bundle savedInstanceState) {
    WebView mWebView;
    super.onCreate(savedInstanceState);

    setContentView(R.layout.
    main);
    mWebView =(WebView) findViewById(R.id.​
    webview);
    mWebView.getSettings().setJavaScriptEnabled(
    true);
    mWebView.getSettings().setPluginsEnabled(
    true);

    String html = ​
    "<object width=\"550\" height=\"400\"> <param name=\"movie\" value=\"file:///android_asset/changing_tyres.swf\"> <embed src=\"file:///android_asset/changing_tyres.swf\" width=\"550\" height=\"400\"> </embed> </object>";
    String mimeType =
    "text/html";
    String encoding =
    "utf-8";
    mWebView.loadDataWithBaseURL(
    "null", html, mimeType, encoding, "");

    }


    I have used the above code to display my swf file changing_tyres.swf. But the screen is blank when i run in the emulator. I have just followed the code that was written above. Only thing that I changed was the swf file. Could you please tell me what could have gone wrong or why the screen is blank.

     
  9. summitch

    summitch Lurker
    Rank:
    None
    Points:
    5
    Posts:
    1
    Joined:
    Jul 17, 2011

    Jul 17, 2011
    1
    0
    5
    Note: I'm using an Asus Transformer and trying to launch a simple webview app in 3.1 (API lvl 12).

    I am having the same issue.

    I've seen the code above all over the place (StackOverflow and the like), and it's all pretty much identical, but none of it works.

    When I run it, I get a black screen. If I change the file name, I get "Webpage not available," so I'm pretty sure that's correct.

    I think it has something to do with the plugin. If I use the standard browser, I can hit flash games just fine. However, I navigated to a Facebook game with the webview app that I made, and the game doesn't appear. There's a white space allotted for it, and oddly, the music is playing, but the game doesn't appear.
     
  10. CBarbas

    CBarbas Lurker
    Rank:
    None
    Points:
    5
    Posts:
    1
    Joined:
    Sep 17, 2011

    Sep 17, 2011
    1
    0
    5
    Greece

    You have

    saved me with this. I have searched allover for this solution!


    Thanks
     
  11. danuchiha

    danuchiha Lurker
    Rank:
    None
    Points:
    5
    Posts:
    1
    Joined:
    Jan 10, 2012

    Jan 10, 2012
    1
    0
    5
    I have a game in a swf file, is there a possibility to make an application for android in Eclipse where user can in their own mobile invoke and play with this .swf ? (maybe from a webView?)

    can I do it using FLEX? but I don't have a concrete idea

    (sorry is the theme is repetitive here, i couldn't find something that can help me)

    hope you guys can help me :thinking:
     
  12. freefulltime

    freefulltime Lurker
    Rank:
    None
    Points:
    5
    Posts:
    2
    Joined:
    Aug 24, 2015

    Aug 24, 2015
    2
    0
    5
    Female
  13. Mina Nabil

    Mina Nabil Lurker
    Rank:
    None
    Points:
    15
    Posts:
    2
    Joined:
    Mar 15, 2016

    Mar 15, 2016
    2
    0
    15
    Male
    Cairo Governorate, Egypt
    hi can you help me and make it video please in eclipse
    thanks in advance
     

Share This Page

Loading...