Android 将URL写入NFC?

Android 将URL写入NFC?,android,nfc,Android,Nfc,如何将URL写入NFC标记,以便在读取时自动打开链接 目前,我使用以下意图: <activity android:name="com.myapp.ReadTagActivity" android:screenOrientation="portrait" android:label="@string/title_activity_readtag" android:parentActivityName=".MainActivit

如何将URL写入NFC标记,以便在读取时自动打开链接


目前,我使用以下意图:

 <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> 

如果写入操作进入URL www.google.com, 读取将只显示字符串。我想要网址
改为在浏览器中打开。如何修复此问题?

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

例如,使用帮助器方法:


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

以下是在NFC标记中写入链接的代码

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();
ndef.connect();
NdefRecord mimeRecord = NdefRecord.createUri(linkPrefix + pageLink);
ndef.writeNdefMessage(new NdefMessage(mimeRecord));
ndef.close();
您可以将
下面的
链接前缀写入linkPrefix字段

"http://www."
"https://www."
"ftps://"
"sftp://"
"smb://"
"nfs://"
"ftp://"
"dav://"
"file://"
并将页面链接写入pageLink字段

"http://www."
"https://www."
"ftps://"
"sftp://"
"smb://"
"nfs://"
"ftp://"
"dav://"
"file://"
  • 谷歌网站
  • stackoverflow.com,etx

“目前,我正在使用以下意图”——这与写入NFC标签无关。“如果写操作”——考虑为“写操作”发布源代码,具体地说明如何构造<代码> nFordStistabor >代码>。