Android和LT;意向滤光器&gt;工程&LT;活动/&GT;但不为&lt;接收/&GT; [英] Android <intent-filter> works for <activity /> but not for <receiver />
问题描述
我有一个活动
有多个&LT;意向滤光器&gt;
标签:
&LT;活动
机器人:名字=。NFCActivity
机器人:标签=@字符串/ title_activity_nfc&GT; &所述;意图滤光器&gt;
&lt;作用机器人:名字=android.nfc.action.TRANSACTION_DETECTED/&GT; &LT;类机器人:名字=android.intent.category.DEFAULT/&GT; &lt;数据
机器人:主机=安全
机器人:路径preFIX =/ a000000004
机器人:端口=0
机器人:计划=NFC/&GT;
&所述; /意图滤光器&gt; &所述;意图滤光器&gt;
&lt;作用机器人:名字=com.gsma.services.nfc.action.TRANSACTION_EVENT/&GT; &LT;类机器人:名字=android.intent.category.DEFAULT/&GT; &lt;数据机器人:计划=NFC/&GT;
&所述; /意图滤光器&gt;
&所述;意图滤光器&gt;
&lt;作用机器人:名字=com.gsma.services.nfc.action.TRANSACTION_EVENT/&GT; &LT;类机器人:名字=android.intent.category.DEFAULT/&GT;
&所述; /意图滤光器&gt;&LT; /活性GT;
本作品如预期,该活动将启动被检测到的事务。
与广播接收器
,不调用的onReceive
方法时同样的事情不能说:
&lt;接收
机器人:名字=carta.NfcReceiver
机器人:启用=真正的&GT; &所述;意图滤光器&gt;
&lt;作用机器人:名字=android.nfc.action.TRANSACTION_DETECTED/&GT; &LT;类机器人:名字=android.intent.category.DEFAULT/&GT; &lt;数据
机器人:主机=安全
机器人:路径preFIX =/ a000000004
机器人:端口=0
机器人:计划=NFC/&GT;
&所述; /意图滤光器&gt; &所述;意图滤光器&gt;
&lt;作用机器人:名字=com.gsma.services.nfc.action.TRANSACTION_EVENT/&GT; &LT;类机器人:名字=android.intent.category.DEFAULT/&GT; &lt;数据机器人:计划=NFC/&GT;
&所述; /意图滤光器&gt;
&所述;意图滤光器&gt;
&lt;作用机器人:名字=com.gsma.services.nfc.action.TRANSACTION_EVENT/&GT; &LT;类机器人:名字=android.intent.category.DEFAULT/&GT;
&所述; /意图滤光器&gt;&LT; /接收器&GT;
我缺少的东西吗?
感谢
同样的事情不能说有一个BroadcastReceiver时,该方法的onReceive不调用:
块引用>这是因为这些操作在
正在使用的一些其他进程startActivity()
或startActivityForResult()
。你不能以startActivity()
或startActivityForResult()
与广播接收器$ C响应$ C>。
I have an
Activity
with multiple<intent-filter>
tags:<activity android:name=".NFCActivity" android:label="@string/title_activity_nfc" > <intent-filter> <action android:name="android.nfc.action.TRANSACTION_DETECTED" /> <category android:name="android.intent.category.DEFAULT" /> <data android:host="secure" android:pathPrefix="/a000000004" android:port="0" android:scheme="nfc" /> </intent-filter> <intent-filter> <action android:name="com.gsma.services.nfc.action.TRANSACTION_EVENT" /> <category android:name="android.intent.category.DEFAULT" /> <data android:scheme="nfc" /> </intent-filter> <intent-filter> <action android:name="com.gsma.services.nfc.action.TRANSACTION_EVENT" /> <category android:name="android.intent.category.DEFAULT" /> </intent-filter> </activity>
This works as expected, the activity launches as a transaction is detected.
The same thing can't be said when working with a
BroadcastReceiver
, theonReceive
method is not invoked:<receiver android:name="carta.NfcReceiver" android:enabled="true" > <intent-filter> <action android:name="android.nfc.action.TRANSACTION_DETECTED" /> <category android:name="android.intent.category.DEFAULT" /> <data android:host="secure" android:pathPrefix="/a000000004" android:port="0" android:scheme="nfc" /> </intent-filter> <intent-filter> <action android:name="com.gsma.services.nfc.action.TRANSACTION_EVENT" /> <category android:name="android.intent.category.DEFAULT" /> <data android:scheme="nfc" /> </intent-filter> <intent-filter> <action android:name="com.gsma.services.nfc.action.TRANSACTION_EVENT" /> <category android:name="android.intent.category.DEFAULT" /> </intent-filter> </receiver>
am I missing something ?
Thanks
解决方案The same thing can't be said when working with a BroadcastReceiver, the onReceive method is not invoked:
That is because those actions are being used by some other process in
startActivity()
orstartActivityForResult()
. You cannot respond tostartActivity()
orstartActivityForResult()
with aBroadcastReceiver
.这篇关于Android和LT;意向滤光器&gt;工程&LT;活动/&GT;但不为&lt;接收/&GT;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!