2014-02-14 35 views
1

我有一个带ANE的flex移动应用程序。这ANE有启动Flex手机应用程序的广播接收器,当它接收到一个事件:将附加费从ANE传递到Flex应用程序

public class BroadcastEventHandler extends BroadcastReceiver{ 

@Override 
public void onReceive(Context context, Intent intent) { 
    Log.d(Constants.TAG, "BROADCAST EVENT RECEIVED!");  
    try { 
     Intent i = new Intent(context, 
         Class.forName(context.getPackageName()+".AppEntry")); 

     i.addCategory(Intent.CATEGORY_LAUNCHER); 
     i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
     i.putExtra("nameKey", "value"); 
     context.startActivity(i); 

    } catch (ClassNotFoundException e) { 
     e.printStackTrace(); 
     Log.d(Constants.TAG, "Error on starting Intent: "+e.getMessage()); 
    } 
} 

在Flex应用程序,我有以下代码:

protected function view1_preinitializeHandler(event:FlexEvent):void 
{ 
NativeApplication.nativeApplication.addEventListener(
    InvokeEvent.INVOKE, onInvoke); 
} 

private function onInvoke(event:InvokeEvent):void 
{ 
    trace("Arguments: " + event.arguments); 
} 

我想要做的就是通过

跟踪:

012从广播接收器的Flex应用程序时,它被执行(你可以看到我添加的ANE代码一个Bundle对象,但我不Flex应用程序得到了什么)附加功能
Arguments: 

你知道一种方式来启动一些参数/额外的活动(在android本机),并让他们在flex应用程序?

回答

1

最后,我不能通过本地代码中的Bundle对象来做到这一点。将参数传递给应用程序必须使用清单中的<data android:scheme="my-scheme"/>标记。 但是,

一个需要注意的是,使用AIR应用程序中的自定义URL方案调用其他应用程序是不可能的。 AIR安全模型更具限制性,它将方案限制为:http :, https :, sms:,tel:,mailto :, file :, app :, app-storage:,vipaccess:和connectpro :.你可以在这里和这里找到更多关于它的信息。

从这个伟大的教程:

http://www.riaspace.com/2011/08/defining-custom-url-schemes-for-your-air-mobile-applications/

到目前为止,我所做的就是实现与成员数据的类。在那里,我存储了稍后想要处理的数据(这与我想通过Bundle直接传递的数据相同)。

public class DataModel { 
    //data I will get after in the actionscript side of the code 
    private int notificationCode; 

    public int getNotificationCode(){ 
    return notificationCode; 
    } 

    public void setNotificationCode(int notificationCode){ 
    this.notificationCode=notificationCode; 
    } 
} 

当我收到我设置了notificationCode的新值的广播接收器的通知,然后我开始活动(像以前一样,但增加setNotificationCode函数的调用)。

然后,在动作方面,在方法onInvoke,我做以下电话:

//call native functions: 
//broadcastevent is the EventDispatcher that connects to the ANE 
notificationCode=broadcastevent.getCode(); 

switch(notificationCode) 
{ 
case Constants.DEFAULT_NOTIFICATION_CODE: 
{ 
    notificationMessage="THERE ARE NO NOTIFICATIONS"; 
    break; 
} 
case Constants.UPDATE_APP_CODE: 
{ 
    notificationMessage="UPDATE APP NOTIFICATION"; 
    break; 
} 
case Constants.SHOW_ALERT_CODE: 
{ 
    notificationMessage="SHOW ALERT NOTIFICATION"; 
    break; 
} 
default: 
     break; 

这是不是我正好一直在寻找,但我还没有发现其他的方式做同样的事情,它的工作原理!

相关问题