开发者

Combining JAVA and AIR codes for Android app

How can we combine JAVA code and AIR codes for an app development in android here is an example, http://rosarioconti.wordpress.com/2010/10/03/extending-your-android-air-application-using-java/ but will it work???i need to call some air codes in my android app??

EDIT

i need this code in the AIR 开发者_Python百科to be called from JAVA is it possible? http://coenraets.org/blog/2010/07/video-chat-for-android-in-30-lines-of-code/ or basically i need is a service like this,is this possible in JAVA?


Adobe AIR has no native way to use Java on the client.

However, you could try http://www.merapiproject.net/index.php

Merapi acts as a "middle man", passing objects between AIR and Java.

The code looks like this:

Sending a message from ActionScript:

var message : Message = new Message();

message.data = "Hello from Merapi Flex.";

message.type = "Reply";

Bridge.instance.sendMessage( message );

Sending a message from Java:

Bridge bridge = Bridge.getInstance();

Message message = new Message();

message.setData("Hello from Merapi Java.");

bridge.sendMessage(message);

Receiving a message in Flex:

<merapi:BridgeInstance

id="bridge" result="handleResult(event)" />



<mx:Script>

<![CDATA[

private function handleResult( event : ResultEvent ) : void

{

var message : IMessage = event.result as IMessage;

Receiving a message in Java:

Bridge.getInstance().registerMessageHandler("Reply", messageHandlerInstance );

public void handleMessage( IMessage message )

{

System.out.println( message.getData() );

}

NOTE:

While not tested by me - one can add a custom Java class to Android. Just make sure that the custom class is public, has a public zero-argument constructor, and that the constructor chains to the superclass constructor.

Having the code for Merapi (it's open source) will give you the ability to customize it for Android.

You can add the class to your Android Java Code and compile just like any other Android application. The AIR code will have to be a separate application. There may be some security issues to overcome to communicate between the two.

This is one potential option but may not work. The best way is to write a test application and see if you can get it working. Then ask other questions as needed.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜