1.) 尝试像往常一样使用意图过滤器启动 Activity。如果匹配 Intent 的 Activity 也匹配 AAR,则启动 Activity。
这意味着活动 A 有一个 NDEF_DISCOVERED 意图过滤器匹配标签上的 NDEF 消息的 first NDEF 记录的数据类型 和 AAR 与活动 A 所属的应用程序包名称匹配。
2.) 如果过滤 Intent 的 Activity 与 AAR 不匹配,如果多个 Activity 可以处理该 Intent,或者如果没有 Activity 处理该 Intent,则启动 AAR 指定的应用程序。
这意味着有
- 带有
NDEF_DISCOVERED 意图过滤器的活动 A 与 AAR 匹配的标签 和 上 NDEF 消息的 first NDEF 记录的数据类型不匹配Activity A 所属的应用包名,
- 一个活动 A 和一个活动 B 都有一个
NDEF_DISCOVERED 意图过滤器匹配标签上 NDEF 消息的 first NDEF 记录的数据类型 并且 AAR 与活动 A 和 B 所属的应用程序包名称匹配,或者
- 与 AAR 匹配的应用的任何活动都没有
NDEF_DISCOVERED 意图过滤器。
在这种情况下,具有与 AAR 中的包名称相匹配的包名称的应用通过发送意图操作 MAIN 和类别为 LAUNCHER 的应用程序中具有此类意图过滤器的第一个活动来启动。因此,应用程序被“启动”,就像单击了该活动的启动器图标一样。
3.) 如果没有应用程序可以通过 AAR 启动,请转到 Google Play 下载基于 AAR 的应用程序。
这意味着如果没有应用程序包名称与 AAR 中的应用程序匹配,则打开 Play 商店。
例如,如果您有 NDEF 消息
+------------------------------+----------------------+
| URI: http://www.example.com/ | AAR: com.example.app |
+------------------------------+----------------------+
那么您将需要一个包名称为 com.example.app 的应用程序,该应用程序具有一个带有类似意图过滤器的活动
<intent-filter>
<action android:name="android.nfc.action.NDEF_DISCOVERED" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="http" android:host="www.example.com" android:pathPrefix="/" />
</intent-filter>
场景 1(匹配活动 A):
<manifest package="com.example.app" ... >
<uses-permission android:name="android.permission.NFC" />
<application ...>
<activity android:name="MAIN" ...>
<intent-filter>
<action android:name="android.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="A" ...>
<intent-filter>
<action android:name="android.nfc.action.NDEF_DISCOVERED" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="http" android:host="www.example.com" android:pathPrefix="/" />
</intent-filter>
</activity>
</application>
</manifest>
场景 2a(活动 A 不匹配,启动 MAIN):
<manifest package="com.example.app" ... >
<uses-permission android:name="android.permission.NFC" />
<application ...>
<activity android:name="MAIN" ...>
<intent-filter>
<action android:name="android.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="A" ...>
<intent-filter>
<action android:name="android.nfc.action.NDEF_DISCOVERED" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
</intent-filter>
</activity>
</application>
</manifest>
场景 2b(活动 A 和 B 匹配,启动 MAIN):
<manifest package="com.example.app" ... >
<uses-permission android:name="android.permission.NFC" />
<application ...>
<activity android:name="MAIN" ...>
<intent-filter>
<action android:name="android.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="A" ...>
<intent-filter>
<action android:name="android.nfc.action.NDEF_DISCOVERED" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="http" android:host="www.example.com" android:pathPrefix="/" />
</intent-filter>
</activity>
<activity android:name="B" ...>
<intent-filter>
<action android:name="android.nfc.action.NDEF_DISCOVERED" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="http" android:host="www.example.com" android:pathPrefix="/" />
</intent-filter>
</activity>
</application>
</manifest>
场景 2c(无 NDEF_DISCOVERED 意图过滤器,启动 MAIN):
<manifest package="com.example.app" ... >
<uses-permission android:name="android.permission.NFC" />
<application ...>
<activity android:name="MAIN" ...>
<intent-filter>
<action android:name="android.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>