简体   繁体   English

Android NFC:启动了应用程序,但无意采取任何行动

[英]Android NFC: App launched, but action is not in intent

I am trying to handle URI open for a specific domain through NFC. 我正在尝试通过NFC处理为特定域打开的URI。

The manifest has: 清单具有:

<activity android:name="HistoryActivity"
        android:theme="@android:style/Theme.Light.NoTitleBar"
        android:screenOrientation="portrait">
        <intent-filter>
            <action android:name="android.nfc.action.NDEF_DISCOVERED" />
            <category android:name="android.intent.category.DEFAULT" />
            <data android:scheme="https"
                android:host="mydomain.me"
                android:pathPrefix="/x" />
        </intent-filter>
        <intent-filter>
            <action android:name="android.nfc.action.NDEF_DISCOVERED" />
            <category android:name="android.intent.category.DEFAULT" />
            <data android:scheme="http"
                android:host="mydomain.me"
                android:pathPrefix="/x" />
        </intent-filter>
    </activity>

onResume and onNewIntent look like: onResume和onNewIntent看起来像:

@Override
protected void onResume() {
    super.onResume();
    Intent intent = new Intent(this, this.getClass());
    //intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);

    this.handleNfcBeam(intent);
}

@Override
protected void onNewIntent(Intent intent) 
{
    setIntent(intent);

    this.handleNfcBeam(intent);
}

and handleNfcBeam looks like: 和handleNfcBeam看起来像:

protected boolean handleNfcBeam(Intent intent)
{
    String action = intent.getAction();

    if (action != null &&
            action.equalsIgnoreCase("android.nfc.action.NDEF_DISCOVERED"))
    {

        return true; // todo: process URL
    }

    return false;
}

When I beam the right URL, the app is being launched. 当我发送正确的URL时,该应用程序正在启动。 HOWEVER, action is always null!! 但是,动作始终为空!

I haven't event gotten to the point where I can actually process the message... 我还没有达到可以实际处理消息的地步...

What am I doing wrong? 我究竟做错了什么?

Thanks, Daniel 谢谢,丹尼尔

You could place a breakpoint on each of the two lines of this.handleNfcBeam(intent); 您可以在this.handleNfcBeam(intent);的两行中分别放置一个断点this.handleNfcBeam(intent); to see which route your intent is coming. 看看你的意图是走哪条路。 Then inspect the intent data to see what kind of intent you received. 然后检查意图数据,以查看收到的意图类型。

Does your tag contain a NDEF message with the right content, matching your definition in the manifest? 您的标签是否包含内容正确的NDEF消息,是否与清单中的定义匹配? When you define scheme, host and pathPrefix, then all three of them must be met to trigger the intent. 在定义方案,主机和pathPrefix时,必须同时满足这三个条件才能触发意图。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM