通过 ANE(Adobe Native Extension) 启动Andriod服务 推送消息(五)
这一节,用个简单的例子来调用下之前生成的service.ane
首先建一个flex手机项目
然后在构建路径中把ane引进来
可以看到此ane支持Android平台。
serviceMobile.mxml如下:
<?xml version="1.0" encoding="utf-8"?> <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" applicationDPI="160" xmlns:mx="library://ns.adobe.com/flex/mx" backgroundColor="0" applicationComplete="init()"> <fx:Declarations> <!-- 将非可视元素(例如服务、值对象)放在此处 --> </fx:Declarations> <fx:Script> <![CDATA[ import nav.wenbo.service.ServiceController; public var sCtrl:ServiceController; private function init():void { sCtrl = ServiceController.instance; } public function startService(event:Event):void { sCtrl.startAndriodService(); trace("start"); } public function stopService(event:Event):void { sCtrl.stopAndriodService() trace("stop"); } public function sendMessage(event:Event):void { sCtrl.setNotification(msginput.text); trace("init"); } ]]> </fx:Script> <s:Button name="init" label="sendMessage" click="sendMessage(event)" y="100"> </s:Button> <s:Button name="startService" label="startService" click="startService(event)" y="0"> </s:Button> <s:Button name="stopService" label="stopService" click="stopService(event)" y="50"> </s:Button> <s:TextInput name="msg" text="输入消息" id="msginput" y="150"> </s:TextInput> </s:Application>
最后一步,你需要在air -app.xml里配置上service的权限
<android> <colorDepth>16bit</colorDepth> <manifestAdditions><![CDATA[ <manifest android:installLocation="auto"> <!--See the Adobe AIR documentation for more information about setting Google Android permissions--> <!--删除 android.permission.INTERNET 权限将导致无法调试设备上的应用程序--> <uses-permission android:name="android.permission.INTERNET"/> ...... <application> <service android:enabled="true" android:exported="true" android:name="nav.wenbo.service.NotificationService" /> </application> </manifest> ]]></manifestAdditions> </android>
然后你可以,调试或是装到真机上测试它。这里我装在模拟器上测试它
先占击startService
可以输入一条信息测试
往下拉通知
so, enjoy it!
分类:
air-for-android
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!