开始在Android启动Flex移动应用 [英] Start Flex Mobile Application on Android startup

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

问题描述

我有一个问题,启动应用程序在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;
    }
}

我的问题是:

My questions are :

  • 在EXTENSION_PACKAGE是从本地项目的包名或扩展ID?
  • 的。应用指的是应用程序或我并不需要它?

我希望你理解这种情况,并感谢你在前进。

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

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应用程序?要做到这一点不仅仅是创建与所指定动作的意图有点复杂。 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移动应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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