增加获取字符串大小
This commit is contained in:
@@ -180,6 +180,7 @@ public class WriteMessageActivity extends AppCompatActivity {
|
||||
if (ndefMessage != null) {
|
||||
// 提取第一条记录的文本
|
||||
NdefRecord record = ndefMessage.getRecords()[0];
|
||||
Log.e(TAG, "onNewIntent: size = " + record.getPayload().length);
|
||||
String payload = new String(record.getPayload(), StandardCharsets.UTF_8);
|
||||
String text = payload.substring(1);
|
||||
Log.e(TAG, "parseNdefData: NDEF Text: " + text); // 跳过编码头
|
||||
@@ -234,6 +235,7 @@ public class WriteMessageActivity extends AppCompatActivity {
|
||||
}
|
||||
|
||||
private void setContactInfo(ContactInfo contactInfo) {
|
||||
mUploadImageUrl = contactInfo.getAvatar();
|
||||
mBinding.setContactInfo(contactInfo);
|
||||
Glide.with(this)
|
||||
.load(contactInfo.getAvatar())
|
||||
|
||||
@@ -11,6 +11,7 @@ import android.util.Log;
|
||||
import com.hjq.toast.Toaster;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
public class WriteMessageUtils {
|
||||
private static final String TAG = "WriteMessageUtils";
|
||||
@@ -43,6 +44,8 @@ public class WriteMessageUtils {
|
||||
|
||||
public static void writeUrlAddPackage(Tag tag, String url, String pkg) throws Exception {
|
||||
Log.e(TAG, "writeUrlAddPackage: url = " + url);
|
||||
Log.e(TAG, "writeUrlAddPackage: url size = " + url.getBytes(StandardCharsets.UTF_8).length);
|
||||
|
||||
String fixedUrl = url.replace("+", "%2B"); // 替换 + 为 %2B
|
||||
// 1. 创建HTTP Record(HTTPS链接)
|
||||
Uri uri = Uri.parse(fixedUrl);
|
||||
@@ -50,7 +53,9 @@ public class WriteMessageUtils {
|
||||
// 2. 创建Android应用包名Record
|
||||
NdefRecord androidRecord = NdefRecord.createApplicationRecord(pkg);
|
||||
// 3. 按顺序组合记录
|
||||
NdefMessage message = new NdefMessage(new NdefRecord[]{httpRecord, androidRecord});
|
||||
NdefRecord[] ndefRecord = new NdefRecord[]{httpRecord, androidRecord};
|
||||
Log.e(TAG, "writeUrlAddPackage: ndefRecord size = " + ndefRecord.length);
|
||||
NdefMessage message = new NdefMessage(ndefRecord);
|
||||
// 4. 写入NFC标签
|
||||
Ndef ndef = Ndef.get(tag); // 获取标签对象
|
||||
ndef.connect();
|
||||
|
||||
Reference in New Issue
Block a user