iBlogger

Android、Flex 开发者,专注于Adobe AIR 客户端、Android客户端开发。擅长基于Adobe Flex + FMS的音视频应用程序的开发。

博客园 首页 联系 订阅 管理

在工作中遇到这么一个问题,要在android系统中实现音视频聊天,用android SDK来做的话会很麻烦,考虑用Flex 实现音视频功能,然后主程序(java APK)调用Flex APK实现音视频聊天功能。这就牵扯到两种不同开发工具做出来的APK互相调用的问题。解决方法如下:

在Flex APK的配置文件中,<intent-filter>部分加入一个android:scheme, 比如 :<data android:scheme="FLVURI"/>

然后可以在JAVA APK中这样调用:

  

protected void call(String flvUrl)
{
String url = "FLVURI://?url=http://www.sina.com.cn&type=play&view=apkView";
Uri uri = Uri.parse(url);
Intent _intent = new Intent(Intent.ACTION_VIEW, uri);
activity.startActivity(_intent);
}


在 Flex APK中接收传过来的参数:

<?xml version="1.0" encoding="utf-8"?>
<s:View xmlns:fx="http://ns.adobe.com/mxml/2009"
initialize
="init();"
removing
="view1_removingHandler(event)"
xmlns:s
="library://ns.adobe.com/flex/spark"
title
="FlexAPK">
<fx:Declarations>
<!-- 将非可视元素(例如服务、值对象)放在此处 -->
</fx:Declarations>
<fx:Script>
<![CDATA[
import flash.desktop.NativeApplication;
import flash.events.Event;

import mx.utils.URLUtil;

import spark.events.ViewNavigatorEvent;

public function init():void
{
NativeApplication.nativeApplication.addEventListener(InvokeEvent.INVOKE, doInvokeEvent);
}

public function doInvokeEvent(event:InvokeEvent):void
{
trace("args="+event.arguments.toString());
}

protected function view1_removingHandler(event:ViewNavigatorEvent):void
{
NativeApplication.nativeApplication.removeEventListener(InvokeEvent.INVOKE, doInvokeEvent);

}
]]>
</fx:Script>
</s:View>

这样就得到了所需要的参数。在FLEX APK中,可以根据接收到的参数的不同,跳转到不同的View:

 this.navigator.pushView(views.apkPlayer);

接收参数时有个问题,那就是event.arguments本来是一个array,但这个array的length总是一,传递过来的整个url都放在

event.arguments[0]中,如果需要将各个参数分拆开来,必须自己写代码实现,很是麻烦。不知道有没有其它更好的办法。
 public function doInvokeEvent(event:InvokeEvent):void
{
trace("args="+event.arguments.toString());
}





posted on 2011-11-10 20:25  iBlogger  阅读(2742)  评论(10)    收藏  举报