-1

How can I write a URL to a NFC tag so that the link automatically opens on read?

Currently, I am using the following intent:

 <activity
        android:name="com.myapp.ReadTagActivity"
        android:screenOrientation="portrait"
        android:label="@string/title_activity_readtag"
        android:parentActivityName=".MainActivity">

        <intent-filter>
            <action android:name="android.nfc.action.NDEF_DISCOVERED" />
            <category android:name="android.intent.category.DEFAULT" />
            <data android:mimeType="application/com.myapp" />
        </intent-filter>          
  </activity> 

If the write operation enters the URL www.google.com, the read will only display the string. I would like the URL to open in a browser instead. How can I fix this?

4

3 回答 3

2

您是否使用 NDEF 消息中的 URL 编写了正确的 NDEF 记录?

比如使用helper方法:http: //developer.android.com/reference/android/nfc/NdefRecord.html#createUri%28android.net.Uri%29

如果您的 NDEF 记录只是纯文本,它将被读取为纯文本。

于 2013-02-15T01:23:15.443 回答
2
NfcAdapter mNfcAdapter = NfcAdapter.getDefaultAdapter(this);
Intent intent = getIntent();       
Tag mytag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
Uri uri =Uri.parse("Your Url");
NdefRecord recordNFC =NdefRecord.createUri(uri);
NdefMessage message = new NdefMessage(recordNFC ); 
Ndef ndef = Ndef.get(tag);
ndef.connect();
ndef.writeNdefMessage(message);
ndef.close();
于 2014-04-13T12:35:27.627 回答
0

这是在 NFC 标签中写入 Link 的代码。

ndef.connect();
NdefRecord mimeRecord = NdefRecord.createUri(linkPrefix + pageLink);
ndef.writeNdefMessage(new NdefMessage(mimeRecord));
ndef.close();

您可以将below链接前缀写入linkPrefix字段

"http://www."
"https://www."
"ftps://"
"sftp://"
"smb://"
"nfs://"
"ftp://"
"dav://"
"file://"

并将页面链接写入pageLink字段

  • google.com
  • stackoverflow.com 等
于 2020-03-04T12:32:38.360 回答