I have a flex mobile application with an ANE. This ANE has a broadcast receiver that starts the flex mobile application when it receives an event:
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());
}
}
On the flex application I have the following code:
protected function view1_preinitializeHandler(event:FlexEvent):void
{
NativeApplication.nativeApplication.addEventListener(
InvokeEvent.INVOKE, onInvoke);
}
private function onInvoke(event:InvokeEvent):void
{
trace("Arguments: " + event.arguments);
}
What I want to do is to pass Extras from the broadcastreceiver to the flex application when it is executed (as you can see I added a Bundle object in the ANE code, but I don't receive anything in the flex application):
Trace:
Arguments:
Do you know a way to start activity (in android native) with some parameters/extras and get them in the flex application?
Finally, I could not do this via Bundle object from native code. Passing arguments to an application must be with the <data android:scheme="my-scheme"/>
tag in the manifest.
However,
One caveat is that invoking other apps with the custom URL schemes from AIR apps is not possible. The AIR security model is more restrictive and it limits schemes to: http:, https:, sms:, tel:, mailto:, file:, app:, app-storage:, vipaccess: and connectpro:. You can find more about it here and here.
From this great tutorial:
http://www.riaspace.com/2011/08/defining-custom-url-schemes-for-your-air-mobile-applications/
So far, what I have done is implement a class with member data. There, I store the data that I want to handle later (which is the same data that I wanted to pass directly via the 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;
}
}
When I receive a notification in the broadcastreceiver I set the new value of the notificationCode, and then I start the activity (same as before but adding a call to setNotificationCode function).
Then, in the actionscript side, on the method onInvoke, I do the following call:
//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;
It is not what I exactly was looking for but I have not found other way to do something similar, and it works!