Android NFC NDEF MIME类型文本/html
我试图在NFC标签上存储一个非常小(1K)的html文件。 当手机阅读时,它应该会触发浏览器打开它 可悲的是,我有这些限制:Android NFC NDEF MIME类型文本/html,android,nfc,ndef,Android,Nfc,Ndef,我试图在NFC标签上存储一个非常小(1K)的html文件。 当手机阅读时,它应该会触发浏览器打开它 可悲的是,我有这些限制: 存储在标签上的HTML文件(1kb)。不仅仅是一个url。(用户没有互联网) 不是text/plain,它应该是text/html 它应该由默认浏览器打开,而不是定制的应用程序 我是这样创建标签的: tagdetectedtag=intent.getParcelableExtra(NfcAdapter.EXTRA_标记); NdefRecord=NdefRecord.
- 存储在标签上的HTML文件(1kb)。不仅仅是一个url。(用户没有互联网)
- 不是text/plain,它应该是text/html李>
- 它应该由默认浏览器打开,而不是定制的应用程序
tagdetectedtag=intent.getParcelableExtra(NfcAdapter.EXTRA_标记);
NdefRecord=NdefRecord.createMime(“text/html”,“helloworld in html!”);
NdefMessage message=新的NdefMessage(新的NdefRecord[]{record});
if(writeTag(消息、检测到的标记)){
Toast.makeText(这是“成功:将placeid写入nfc标记”,Toast.LENGTH\u LONG)
.show();
}
但由于某些原因,当读取标记时,默认浏览器不会打开。即使浏览器具有正确的意图过滤器:
我做错什么了吗
谢谢 您需要将记录创建为URI。例如:
NdefRecord rtdUriRecord1=NdefRecord.createUri(“http://example.com");代码>嗯
显然这是不可能的,清单规定了:
我需要将HTML页面存储在标记本身上,在我的用户案例中,我可以假设用户没有internet。
Tag detectedTag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
NdefRecord record = NdefRecord.createMime( "text/html", "Hello world in <b>HTML</b> !");
NdefMessage message = new NdefMessage(new NdefRecord[] { record });
if (writeTag(message, detectedTag)) {
Toast.makeText(this, "Success: Wrote placeid to nfc tag", Toast.LENGTH_LONG)
.show();
}
<!-- For these schemes where any of these particular MIME types have been supplied, we are a good candidate. -->
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="http" />
<data android:scheme="https" />
<data android:mimeType="text/html"/>
<data android:mimeType="text/plain"/>
<data android:mimeType="application/xhtml+xml"/>
<data android:mimeType="application/vnd.wap.xhtml+xml"/>
</intent-filter>
<!-- Accept inbound NFC URLs at a low priority -->
<intent-filter android:priority="-101">
<action android:name="android.nfc.action.NDEF_DISCOVERED" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="http" />
<data android:scheme="https" />
</intent-filter>