Starting a specific activity through NFC tag
Is it possible to launch a specific activity in an app using NFC tag?
I want to start an activity called MainMap which is not the main activity. I've tried using a tag writer for writing mime record and still failing.
Here's the manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.km.parkit"
android:versionCode="1"
android:versionName="1.0" >
<uses-permission android:name="android.permission.NFC" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-feature
android:name="android.hardware.nfc"
android:required="true" />
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="21" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".MainMap"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.nfc.action.NDEF_DISCOVERED" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="application/com.km.ParkIT" />
</intent-filter>
</activity>
<activity
android:name="com.km.parkit.parka"
android:label="@string/app_name" />
<activity
android:name="com.km.parkit.parkb"
android:label="@string/app_name" />
<activity
android:name="com.km.parkit.parkc"
android:label="@string/app_name" />
<activity
android:name="com.km.parkit.parkd"
android:label="@string/app_name" />
<!-- Google Maps API Key -->
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyBf-0hUDrDTK-NOveZrnT8wec5TTTLqjAw" />
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
</application>
</manifest>
I wrote the MIME type "application/com.km.parkit" into the NFC tag using https://github.com/balloob/Android-NFC-Tag-Writer
What am I missing here?
Oh my problem is that the app doesn't get started when I tap it to the NFC tag, when I tap the tag, it shows the usual popup box showing the programs which I can use to access the NFC tag or read the datas, namely NFC Tag Info and New Tag Collected.
The NDEF_DISCOVERED intent filter should use an all lower-case MIME type name (and that's also how you should store the type name on the tag):
<intent-filter>
<action android:name="android.nfc.action.NDEF_DISCOVERED" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="application/com.km.parkit" />
</intent-filter>
The problem is that MIME types are case-insensitive as per the RFC while Android's intent filter matching is case-sensitive. As a consequence, the helper methods for handling MIME type records on Android will automatically convert type names to lower-case letters only and you should therefore only use all lower-case letters for MIME type names.
For instance, using the method NdefRecord.createMime()
with a mixed-case type name will always result into the creation of a lower-case only MIME type name:
NdefRecord r1 = NdefRecord.createMime("application/ThisIsMyMIMEType", ...);
NdefRecord r2 = NdefRecord.createMime("application/thisismymimetype", ...);
will both result into the creation of the same MIME type record type:
+----------------------------------------------------------+
| MIME:application/thisismymimetype | ... |
+----------------------------------------------------------+
链接地址: http://www.djcxy.com/p/70148.html
上一篇: TI RF430FRL152HEVM NFC NDEF格式
下一篇: 通过NFC标签开始特定活动