【问题标题】:Passing extras from ANE to Flex app将附加功能从 ANE 传递到 Flex 应用程序
【发布时间】:2014-02-14 12:29:06
【问题描述】:

我有一个带有 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);
}

我想要做的是在执行时将 Extras 从广播接收器传递给 flex 应用程序(如您所见,我在 ANE 代码中添加了一个 Bundle 对象,但我在 flex 应用程序中没有收到任何内容) :

追踪:

Arguments: 

你知道用一些参数/附加项启动 Activity(在 android native 中)并在 flex 应用程序中获取它们的方法吗?

【问题讨论】:

    标签: android actionscript-3 apache-flex air flex-mobile


    【解决方案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;
    

    这不是我真正想要的,但我还没有找到其他方法来做类似的事情,而且它有效!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-06-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多