Android和LT;意向滤光器>工程<活动/>但不为<接收/> [英] Android <intent-filter> works for <activity /> but not for <receiver />

查看:356
本文介绍了Android和LT;意向滤光器>工程<活动/>但不为<接收/>的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个活动有多个<意向滤光器> 标签:

 <活动
    机器人:名字=。NFCActivity
    机器人:标签=@字符串/ title_activity_nfc>    &所述;意图滤光器>
        <作用机器人:名字=android.nfc.action.TRANSACTION_DETECTED/>        <类机器人:名字=android.intent.category.DEFAULT/>        <数据
            机器人:主机=安全
            机器人:路径preFIX =/ a000000004
            机器人:端口=0
            机器人:计划=NFC/>
    &所述; /意图滤光器>    &所述;意图滤光器>
        <作用机器人:名字=com.gsma.services.nfc.action.TRANSACTION_EVENT/>        <类机器人:名字=android.intent.category.DEFAULT/>        <数据机器人:计划=NFC/>
    &所述; /意图滤光器>
    &所述;意图滤光器>
        <作用机器人:名字=com.gsma.services.nfc.action.TRANSACTION_EVENT/>        <类机器人:名字=android.intent.category.DEFAULT/>
    &所述; /意图滤光器>< /活性GT;

本作品如预期,该活​​动将启动被检测到的事务。

广播接收器,不调用的onReceive 方法时同样的事情不能说:

 <接收
        机器人:名字=carta.NfcReceiver
        机器人:启用=真正的>    &所述;意图滤光器>
        <作用机器人:名字=android.nfc.action.TRANSACTION_DETECTED/>        <类机器人:名字=android.intent.category.DEFAULT/>        <数据
            机器人:主机=安全
            机器人:路径preFIX =/ a000000004
            机器人:端口=0
            机器人:计划=NFC/>
    &所述; /意图滤光器>    &所述;意图滤光器>
        <作用机器人:名字=com.gsma.services.nfc.action.TRANSACTION_EVENT/>        <类机器人:名字=android.intent.category.DEFAULT/>        <数据机器人:计划=NFC/>
    &所述; /意图滤光器>
    &所述;意图滤光器>
        <作用机器人:名字=com.gsma.services.nfc.action.TRANSACTION_EVENT/>        <类机器人:名字=android.intent.category.DEFAULT/>
    &所述; /意图滤光器>< /接收器>

我缺少的东西吗?

感谢


解决方案

  

同样的事情不能说有一个BroadcastReceiver时,该方法的onReceive不调用:


这是因为这些操作在正在使用的一些其他进程startActivity() startActivityForResult()。你不能以 startActivity() startActivityForResult()广播接收器

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, the onReceive 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() or startActivityForResult(). You cannot respond to startActivity() or startActivityForResult() with a BroadcastReceiver.

这篇关于Android和LT;意向滤光器&gt;工程&LT;活动/&GT;但不为&lt;接收/&GT;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆