0

I am having an issue to start the application on android startup, the problem is how to put the listeners on the "android.permission.RECEIVE_BOOT_COMPLETED" from the manifest ( on the mobile application project from Flash builder) to the native extension ??

basically on the manifest I have something like this :

<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
    <application>
       <receiver android:enabled="true" android:name="EXTENSION_PACKAGE.application.receivers.ApplicationStartupReceiver" android:permission="android.permission.RECEIVE_BOOT_COMPLETED">
        <intent-filter>
            <action android:name="android.intent.action.BOOT_COMPLETED" />
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
       </receiver>
    </application>

And on the native side : the listener should be like :

package EXTENSION_PACKAGE;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;

import com.adobe.fre.FREContext;
import com.adobe.fre.FREFunction;
import com.adobe.fre.FREObject;

public class ApplicationStartupReceiver extends BroadcastReceiver implements FREFunction {

     @Override
        public void onReceive(Context context, Intent intent) {
            if ("android.intent.action.BOOT_COMPLETED".equals(intent.getAction())) {
                Intent serviceIntent = new Intent("com.myapp.MySystemService");
                context.startService(serviceIntent);
            }
        }

    @Override
    public FREObject call(FREContext arg0, FREObject[] arg1) {
        // TODO Auto-generated method stub
        return null;
    }
}

My questions are :

  • The "EXTENSION_PACKAGE" is the package name from the native project or the extension id ?
  • The ".application" refers to the application or I don't need it ?

I hope that you understand this situation and Thank you in advance.

-----------------------------------------EDIT----------------------------------------

After few attempts and tests, I have changed these values :

<receiver android:enabled="true" android:name="NATIVEPROJECTPACKAGE.application.receiver.ApplicationStartupReceiver" android:permission="android.permission.RECEIVE_BOOT_COMPLETED">

And :

Intent serviceIntent = new Intent("air.APPLICATION_ID"); // from the APPLICATION.XML

and now it seems to work, the only problem now, is that it crashes on the android startup, I recieve an alert saying : "Unfortunately the application 'APPLICATION NAME' has stopped" And of course, if I launch the application, it works, ...

Khalil Bhm
  • 394
  • 3
  • 13
  • what i understand is in your broadcast receiver you are receiving the BOOT_COMPLETED intent and started a Service and what do you need now? Sorry if i missed the point – ruben Sep 04 '13 at 17:56
  • 1
    well, i can't set the receiver for the BOOT_COMPLETED because, the manifest is on the flex application, and the listener itself on the native side, because we can't do it with flex, – Khalil Bhm Sep 04 '13 at 18:00

1 Answers1

1

Firstly just double check that you're using the correct package names as you've got the package listed as EXTENSION_PACKAGE but then add application.receivers to the definition in your manifest. It probably should read like the following:

<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<application>
   <receiver android:enabled="true" android:name="EXTENSION_PACKAGE.ApplicationStartupReceiver" android:permission="android.permission.RECEIVE_BOOT_COMPLETED">
    <intent-filter>
        <action android:name="android.intent.action.BOOT_COMPLETED" />
        <category android:name="android.intent.category.DEFAULT" />
    </intent-filter>
   </receiver>
</application>

Now when the receiver is called I'm assuming you want to simply start your AIR application? To do this is a little more complex than just creating an Intent with the actions you are specifying. Android hasn't got way of handling the actions you are calling. What you need to do is find your application entry from the context and start an intent with that, as below:

if (Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction()))
{
    String componentName = context.getPackageName() + "/.AppEntry";
    Intent i = new Intent( Intent.ACTION_MAIN );
    i.setComponent(ComponentName.unflattenFromString( componentName ));
    i.addCategory( Intent.CATEGORY_LAUNCHER );
    i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    context.startActivity( i );
}
Michael
  • 3,776
  • 1
  • 16
  • 27
  • Just a question, on the "/.AppEntry" I put the name of the mxlm file, right ? – Khalil Bhm Sep 09 '13 at 12:59
  • The thing is I got this error message after I reboot the device : Unfortunately, the application " ... " stopped. – Khalil Bhm Sep 09 '13 at 18:56
  • No, leave the above code as is, don't change the "/.AppEntry". This code is determining the correct entry point for the application that contains the context so you shouldn't need to change anything. – Michael Sep 09 '13 at 21:11
  • Would it be possible that the problem that I'm having is because the listener is working, but I have made a mistake while building the ANE so it can't find the receiver ? – Khalil Bhm Sep 10 '13 at 12:41
  • Listen, I have the package of the native project, le package from the native extension, and the one that I put into `ExtensionContext.createExtensionContext(, );` which is also the ID in the extension.xml, right ? which one is the EXTENSION_PACKAGE here ? that I put into the receiver in the manifest ? – Khalil Bhm Sep 10 '13 at 20:49
  • EXTENSION_PACKAGE in your usage above is the java package name of the receiver you've created. That is the package at the top of the ApplicationStartupReceiver.java file. It is separate from the Extension ID and from the actionscript package. I suggest you add in some simple log outputs and follow the adb logcat outputs. – Michael Sep 10 '13 at 21:34