Extending your Android Air Application using Java

This is a basic template for AirApps.

The template will help you extending basic flash apps by adding a context menu with 2 extra functionality ( DialogBox and Exit Button) on top of air.

Basically what you have to do to run this example it’s installing Eclipse and and the adt plugin for android, if you don’t have it already installed.
I decide to add this article because I’m starting seeing many apps running in background even if the window is not focused.
Someone said it was not possible to kill the app on exit…
I said let me try and see what can we do.

Please leave a comment.

The Structure:
(Resources used app.xml and test.swf)

The result:

The Swf loaded with the context Menu…and

the EXIT BUTTON!

Enjoy! The source is attached here.
(rename the extension from odt to zip)

About these ads

Tags: , , , , , , , , , ,

16 Responses to “Extending your Android Air Application using Java”

  1. Arthur Neves Says:

    Really good one, I will try !

  2. Tehsin Says:

    Hey there

    Thanks for the post!

    Was wondering if it was possible to create a service on Android using this approach, and then having that service start up when the device boots.

    It would only launch the SWF (AIR) app when the application is active.

    I wanted to attempt this because from what I understand, you can’t create a service to run on Android with AIR, and I am hoping this might be a way to get around that?

    Thanks

  3. NativeProcess und Android. - Flashforum Says:

    [...] app to allow AIR access unavailable APIs | Deep Dive Into Flash Ein anderer Ansatz ist das hier: Extending your Android Air Application using Java Rosario Conti __________________ mfg [...]

  4. Yjo Says:

    Brilliant work, thanks so much for putting this online! One thing I’ve noticed is that the built applications don’t detect whether AIR is installed and take to you its app page if not – do you have any suggestions for how this could be added to an application, e.g. using .smali files from an APK produced by ADT?

    Thanks & all best!

    • rozdog Says:

      Nessuna problema :).
      Detecting if AIR is installed is more simple of what you think. Just make a check to see if the directory/package “com.adobe.air” exist if so…you can execute your app.
      I don’t think it was relevant at this point to put that check in here but you can add that :) , this is just a very simple example.
      Enjoy.

  5. saurabh Says:

    HI,
    I am able to run the hello world application.I have one question correct me if I am wrong.Here the android framework is launching the code written in flex from the file –> app.swf right?? Which has the code of hello World inside it.Now suppose if I want to run another .swf file being created from the Flex what changes and and which files I have to change to make it run similairly like hello world app in eclipse(inside android).I did try it by replacing the app.swf with the myflexapp.swf and app with the myflexapp word in the application.xml file but it doesn’t work.Any way to make this run.Also I need to pass the variables/data to this flex code and finally run it and then come back to the android code(activity).Plz assist or direct me to the useful pointers which could solve my problem.

    Zillion Thanks in advance

    Best Rgds,

    Saurabh

    • rozdog Says:

      hi Saurabh,
      make sure when you add you own file to have the same filename inside the XML otherwise ti will never load because it cannot find it.
      The quick change you can do is to rename your swf to app.swf or whatever I called the swf (I don’t rememebr right now exactly).

      It is important to pass th right values to AIR otherwise it will never run.

      Another tip is if you do this change and it is still not loading or loading and nothing appears , remove the RSL digest from you app.

      Btw the best you can do to me to understand what r u doing wrong os to pass me the ADB logcat.

      Ciao!

  6. Pohan Says:

    Hi Rosario,
    I managed to get the swf displayed but the buttons were somehow missing. Do you mind to give me some hints what might go wrong?

    Grazie!

    • rozdog Says:

      somehow ? :D

      well the only 2 things you should check if you MODIFIED something… which I guess so… it is
      the option menu item in the java code and inside the manifest the “theme” used which COULD interfere with the screen.

      If you didn’t change anything then… tell me on what device are you testing and if you can add the log cat.

      non c’e’ di che! ;)
      Rosario

      • Pohan Says:

        Hi Rosario, thanks for the quick response. I tried many different virtual machines from 2.1 to 2.3. Then the swf finally came up on 2.2 and 2.3 after I installed AIR runtime onto the virtual machines. Actually, I even tried it on a real Sensation but only the swf was displayed. Do you mind to give me your email since the log is a bit long.

  7. saurabh Says:

    Hi Rosario
    Thanks for this , i am able to run it now.I have a question is it possible to pass the arguments to .swf file via android or java code example – hello .I want the input to be done from the other programming language side like (java and android))
    Rgds,
    Saurabh

    • rozdog Says:

      Yes you can, from anywhere you want .
      From java you can actually pass the value by adb then the java app read the values passed then you need to set those values to the air args “-nodebug ” + …the argumetns passed by adb.
      In flash you simply use the way you always did to read arguments.

      If you want the code you need to wait because I’m kind busy right now but I already have done this.

    • rozdog Says:

      From Java to get the arguments use to send:
      adb shell am start
      -a android.intent.action.MAIN
      -n com.what.EVERISTHENAMEOFYOURAPP/.YOURAPPNAME
      -d ACODETOFILTER
      –es args param1##00param2

      final Intent intent = this.getIntent();
      Uri mUri = intent.getData();
      Object strs[] = new Object[2];
      String convStr =” “;

      if (mUri != null) {
      String uri = mUri.toString().trim().toLowerCase();
      Log.d(“[extra_args_uri]“,”” + uri );

      if (uri.contentEquals(“ACODETOFILTER“)){

      Bundle bundle = intent.getExtras();
      String _args = bundle.getString(“args“);
      //bundle.size()
      if (_args != null){
      String[] __args = _args.split(“##00″);
      int c=0;
      convStr = ” — “;
      while (c < __args.length) {
      convStr += getString(R.string.amp) + __args[c] ;
      Log.d("[extra_args args]","["+c + "] = " + __args[c]);
      c++;
      }
      strs[0] = convStr;
      strs[1] = __args;

      } else {
      Log.d("[Arguments Info 2]","You must specify arguments. No arguments found.");
      }
      } else {
      Log.d("[Arguments Info 1]","You must specify: -d ACODETOFILTER in order to activate the arguments.");

      }

      } else {
      Log.d("[Arguments Info 0]","No arguments found.");
      }

      return strs;
      }

      in the air instantiatio use:
      String args[] = {lAppXmlPath, lAppRootDir , lAppExtraArgsDefault + " " + lAppExtraArgs….

      Then try to use an intent to filter calls:

      final Intent intent = this.getIntent();
      final String action = intent.getAction();

      // For an edit action:
      if (Intent.ACTION_MAIN.equals(action)) {
      uf.setVar( "myargs", getString(R.string.extraargs));

      } else if (Intent.ACTION_INSERT.equals(action)){
      // For an insert or paste action:
      Object[] args = (Object[]) getArguments();
      String inlineStr = ((String) args[0]);
      String[] arrayStr = ((String[]) args[1]);
      lEditor.putString("myargs", "" + inlineStr);
      lEditor.commit();
      reboot(); your reboot function
      }

      in FLash:
      NativeApplication.nativeApplication.addEventListener ( InvokeEvent.INVOKE , handleArgs );

      private function handleArgs ( event : InvokeEvent ) : void
      {
      _urlArgs = "?" + ( ( event.arguments[0] != undefined ) ? event.arguments[0] : "" );
      addEventListener( Event.ADDED_TO_STAGE , addToStage );
      }

      ENJOY

  8. betabeat.com Says:

    I’m really enjoying the design and layout of your website. It’s a very
    easy on the eyes which makes it much more enjoyable for me to come here and
    visit more often. Did you hire out a developer to create
    your theme? Excellent work!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


Follow

Get every new post delivered to your Inbox.

%d bloggers like this: