Friday, August 10, 2012

SWF to APK

 
Since long I have been struggling to convert .swf file to .apk file and the best part is I have the solution !!
Even I was searching around  the internet for the solution ,and the outcome was obvious none of the methods worked !!! And I believe there are no tools yet that convert .swf to .apk directly.

Most Important !! The phone should be flash player enabled for the apk to work or else just a white screen would appear if the phone isnt flash enabled.

So after so many trials and errors  I came out with a solution and it worked perfectly !!
Without any wasting any time lets get started !! 

Create an android project  eclipse and just include the code !

Here is code.


import android.app.Activity;
import android.os.Bundle;
import android.webkit.WebView;

public class MainActivity 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/Flash.swf";                           //Include your swf file here.
        WebView wv=(WebView) findViewById(R.id.web_engine);
        wv.getSettings().setPluginsEnabled(true);
        wv.loadUrl(url);       
    }
}


XML code

Just replace the main.xml with the following code.
You can use any layouts of your choice, I have used absolute layout.
Its pretty straight forward.

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



Thats it !!
Run the project !
Your APK is Ready ! Do comment !
Happy Coding !





42 comments:

  1. Hi, Could u send the eclipse project file to sankar2389@gmail.com

    ReplyDelete
    Replies
    1. can you send me a copy too please
      jbanks1994@yahoo.com.au

      Delete
    2. I have even included the xml code.
      I think you wont be having any kind of errors if you follow the steps.

      Delete
  2. just create a new project
    Place your .swf file in "assets" folder
    and include these lines

    String url ="file:///android_assest/your_file";

    WebView wv=(WebView) findViewById(R.id.web_engine);
    wv.getSettings().setPluginsEnabled(true);
    wv.loadUrl(url);

    ReplyDelete
  3. please mail it to me also at (sunildeepu6@gmail.com).

    ReplyDelete
  4. Hi pavan,

    Where we have to include these lines ? Is it into the .java file locate in com.exemple.projectname ?

    Thanks

    ReplyDelete
    Replies
    1. Exactly !!
      In d main method.
      The complete code is provided above.Have a look.

      Delete
  5. setContentView (R.layout.main), this code gives an error

    ReplyDelete
  6. Hi...where can i get that 3 items in bin/res/... folder? classes.dex and so on ...?

    Next. .. WebView wv=(WebView) findViewById(R.id.web_engine); gives me an error ...

    could you help me?

    ReplyDelete
    Replies
    1. you need to include webview layout !
      I have updated the blog with xml code.
      You wont b having any kinds of trouble.
      Just follow the steps.

      Delete
  7. Just paste ur swf file in assets folder.
    And u need import WebView.
    Den d error goes off for sure.

    ReplyDelete
  8. I would like to include gyroscope control . How can i do that?

    ReplyDelete
  9. I think its not possible through this method as this is just packaging up d swf file into an apk......

    ReplyDelete
  10. Can you please make a video tutorial about this method when ever i try it i get erorrs

    ReplyDelete
    Replies
    1. what kind of errors ?
      The xml is code is updated
      Just follow the steps u wont be having any kind of errors.

      Delete
  11. Actually you can simple use a Andaired
    for converting SWF to APK

    ReplyDelete
  12. For this to work:
    wv.getSettings().setPluginsEnabled(true);

    do i have to externally install any plugins on my android device?

    ReplyDelete
    Replies
    1. Due to errors in the code U've pasted above I referred the android developer website and made the following changes.

      But when I run it directly in my android device the app crashes. What could be the problem.

      Device: Nexus7(Android version 4.3)

      I've installed the adobe flash player plugin as well.


      MainActivity.java

      package com.example.myfirstapp;

      import android.app.Activity;
      import android.os.Bundle;
      import android.webkit.WebSettings;
      import android.webkit.WebView;

      public class MainActivity 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/cards2.swf"; //Include your swf file here.
      WebView myWebView = (WebView) findViewById(R.id.webview);
      WebSettings webSettings = myWebView.getSettings();
      webSettings.setJavaScriptEnabled(true);
      myWebView.loadUrl(url);
      }
      }

      Activity_main.xml:


      Delete
    2. activity_main.xml

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

      Delete
    3. i removed the opening closing brackets bcoz i wasn't able to post the xml code

      Delete
    4. What exactly do u mean by crash ??
      Do u have a blank white screen ?

      Delete
  13. Replies
    1. Flash is no longer supported(officially) from Jellybean versions.

      Delete
  14. just a quick question, should i put the first code at this folder?

    src/com/mydomain/gamefolder/filename.java

    ReplyDelete
  15. i got an error in:
    wv.getSettings().setPluginsEnabled(true);
    what should i do??
    it says: the method setPluginsEnabled(boolean) is undefined for the type Web settings

    ReplyDelete
    Replies
    1. I have the same problem, and in .xml it says that AbsoluteLayout is deprecated

      Delete
  16. How to put the .swf file to eclipse android project and do I have to paste your code on the main activity under the src file?

    ReplyDelete
  17. Can you please tell us if this codes were still reliable by this time> thank you :)

    ReplyDelete
  18. Hallo. Another way is using adobe air.

    Load swf into air and create apt pack with publish option.

    C.

    ReplyDelete
  19. this coding not work bro...

    wv.getSettings().setPluginsEnabled(true);

    please help me give solution.. anggihalfiantara@gmail.com

    ReplyDelete
  20. شكرا لك ولكن لو سمحت أعطنا كود واضح بدون تفاصيل

    ReplyDelete
  21. youtube-free.com – YouTube HD (2 MB) Videos, Videos, Reviews - Vimeo
    https://www.youtube.com/channel/m4cvr6uYcE6yFqVZjm/videos/mygadget+video-free-c/videos-f5c4d9e0/4f5d9e0_v4jmpk?wet=8 youtube mp4

    ReplyDelete
  22. Hard Rock Hotel & Casino New Orleans - Mapyro
    Find hotels, motels, 양산 출장마사지 and other lodging 과천 출장샵 near Hard Rock 서산 출장마사지 Hotel & Casino New Orleans in New 김천 출장마사지 Orleans. Hotel Information, reviews, photos and more. 성남 출장마사지

    ReplyDelete