我正在使用Adobe AIR编写应用程序并尝试使用本机扩展将其部署到Android。该应用程序需要能够使用Google的C2DM服务(相当于Apple的推送通知服务)。这需要设置BroadcastReceiver才能从Google接收设备注册。我能够在独立的原生Android应用程序(没有AIR)中正常工作,但似乎无法让它在AIR应用程序中运行。我想我必须设置清单XML错误,但我看不出如何。
以下是AIR应用程序中清单文件中XML的相关部分:
<android>
<manifestAdditions><![CDATA[
<manifest android:installLocation="auto">
<permission android:protectionLevel="signature" android:name="com.example.znotification.permission.C2D_MESSAGE" />
<uses-permission android:name="com.example.znotification.permission.C2D_MESSAGE" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="android.permission.INTERNET" />
<application android:enabled="true">
<receiver android:name="com.example.znotification.C2DMBroadcastReceiver" android:permission="com.google.android.c2dm.permission.SEND">
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
</intent-filter>
<intent-filter>
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
</intent-filter>
</receiver>
</application>
</manifest>
]]></manifestAdditions>
</android>
在标记中引用的本机Java类C2DMBroadcastReceiver中,它所做的只是注销一条消息,表明它已收到广播。我已经验证我正确设置了Intent(参见下面的Java代码),但是BroadcastReceiver永远不会被命中。
Context appContext = context.getActivity().getApplicationContext();
Intent registrationIntent = new Intent("com.google.android.c2dm.intent.REGISTER");
registrationIntent.putExtra("app",PendingIntent.getBroadcast(appContext, 0, new Intent(), 0));
registrationIntent.putExtra("sender", args[0].getAsString());
appContext.startService(registrationIntent);
通常,如何在AIR应用程序的清单XML中设置BroadcastReceiver?另外,在XML中如何告诉应用程序在接收到给定广播时运行正确的BroadcastReceiver?显然,我所做的不正确......
答案 0 :(得分:0)
你快到了。我想你只是让AIR组件的android名称略有错误。试试下面的内容,注意几个类的“空气”前缀。
<android>
<manifestAdditions><![CDATA[
<manifest android:installLocation="auto">
<permission android:protectionLevel="signature" android:name="air.com.example.znotification.permission.C2D_MESSAGE" />
<uses-permission android:name="air.com.example.znotification.permission.C2D_MESSAGE" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="android.permission.INTERNET" />
<application android:enabled="true">
<receiver android:name="com.example.znotification.C2DMBroadcastReceiver" android:permission="com.google.android.c2dm.permission.SEND">
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<category android:name="air.com.example.znotification" />
</intent-filter>
<intent-filter>
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<category android:name="air.com.example.znotification" />
</intent-filter>
</receiver>
</application>
</manifest>
]]></manifestAdditions>