2016-04-21 78 views
1

我使用Delphi 10为我的android手机创建一个mediaplayer应用程序。我用下面的组件包括一个BroadcastReceiver到我的应用程序: https://github.com/barisatalay/delphi-android-broadcast-receiver-componentDelphi 10 Android Broadcastreceiver for Headset Plugin不起作用。我错了什么?

这完美的作品,如果我请求消息电话来电(如在演示程序),我使用:android.intent.action.PHONE_STATE

但是,如果我添加了耳机插件消息的请求: android.intent.action.ACTION_HEADSET_PLUG 我的应用程序没有收到消息。

任何想法我可能会做错什么?

+0

你的意思是德尔福10.0西雅图,或Delphi 10.1柏林?您的应用程序首先表现为接受“ACTION_HEADSET_PLUG”意图吗? –

+0

在柏林(不清楚西雅图),你可以通过['IFMXApplicationEventService.SetApplicationEventHandler()']获得一个Android'Intent'(http://docwiki.embarcadero.com/Libraries/en/FMX.Platform.IFMXApplicationEventService.SetApplicationEventHandler )和['TMessageManager.SubscribeToMessage()'](http://docwiki.embarcadero.com/Libraries/en/System.Messaging.TMessageManager.SubscribeToMessage)['TMessageReceivedNotification'](http://docwiki.embarcadero.com /RADStudio/en/List_of_FireMonkey_Message_Types#FMX.Platform.TMessageReceivedNotification.Android)消息。 –

+0

请参阅Embarcadero的[AndroidIntents](https://sourceforge.net/p/radstudiodemos/code/HEAD/tree/branches/RADStudio_Berlin/Object%20Pascal/Mobile%20Snippets/AndroidIntents/)示例。 –

回答

2

正确的意图动作的名字是

android.intent.action.HEADSET_PLUG 

android.intent.action.ACTION_HEADSET_PLUG 

这是Intent文档中介绍了ACTION_HEADSET_PLUG

public static final String ACTION_HEADSET_PLUG 

在API级别1

广播动作:插入或拔下有线耳机。与ACTION_HEADSET_PLUG相同,需要咨询价值和文档。

如果您的应用程序的最低SDK版本为LOLLIPOP,建议在您的接收器注册码中引用AudioManager常数。

常数值: “android.intent.action.HEADSET_PLUG”

+0

这样做了!非常感谢你。 –

+0

你能指点一下我能找到Intent动作名称的列表吗?我没有在文档中找到任何内容,这将有助于避免这种错误... –

+0

再次感谢您。 –

相关问题