在 Android 启动时启动 Flex Mobile 应用程序 [英] Start Flex Mobile Application on Android startup

查看:32
本文介绍了在 Android 启动时启动 Flex Mobile 应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 android 启动时启动应用程序时遇到问题,问题是如何将侦听器放在android.permission.RECEIVE_BOOT_COMPLETED"清单上(在 Flash Builder 的移动应用程序项目上)到本机扩展??

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;
    }
}

我的问题是:

  • EXTENSION_PACKAGE"是原生项目的包名还是扩展名?
  • .application"是指应用程序还是我不需要它?

希望您理解这种情况,并提前谢谢您.

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

-----------------------------------------编辑----------------------------------------

经过几次尝试和测试后,我更改了这些值:

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">

还有:

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

现在它似乎可以工作了,现在唯一的问题是它在 android 启动时崩溃,我收到一条警告说:不幸的是,应用程序‘应用程序名称’已停止"当然,如果我启动应用程序,它就可以工作,...

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

推荐答案

首先仔细检查您使用的包名称是否正确,因为您将包列为 EXTENSION_PACKAGE,然后添加 application.receivers 到清单中的定义.它可能应该如下所示:

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>

现在当接收器被调用时,我假设您只想启动您的 AIR 应用程序?要做到这一点,比仅使用您指定的操作创建 Intent 稍微复杂一些.Android 没有办法处理您正在调用的操作.您需要做的是从上下文中找到您的应用程序条目并以此开始一个意图,如下所示:

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

这篇关于在 Android 启动时启动 Flex Mobile 应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆