0

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

基本上在清单上我有这样的东西:

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

而在本机方面:听众应该是这样的:

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”是指应用程序还是我不需要它?

我希望您了解这种情况,并在此先感谢您。

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

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

<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 启动时崩溃了,我收到一条警报:“不幸的是,应用程序 'APPLICATION NAME' 已停止”当然,如果我启动该应用程序,它就可以工作, ...

4

1 回答 1

1

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

<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 无法处理您调用的操作。您需要做的是从上下文中找到您的应用程序条目并以此开始一个意图,如下所示:

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 );
}
于 2013-09-08T22:54:17.880 回答