Start Flex Mobile Application on Android startup

≡放荡痞女 提交于 2019-12-11 19:44:03

问题


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, ...


回答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 );
}


来源:https://stackoverflow.com/questions/18620442/start-flex-mobile-application-on-android-startup

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!