gpt4 book ai didi

java - 如何将数据从android Activity 发送到java 类?

转载 作者:行者123 更新时间:2023-12-05 00:12:52 25 4
gpt4 key购买 nike

<分区>

我正在做一个简单的应用程序,它从 editText 获取数据,然后获取该文本并发送到 java 类(在类中我需要它将字符串转换为 utf8 编码)。我应该怎么做才能从 Activity 发送数据以及如何在 java 类中接收它?

这是我的 UTFencoder 类:

public class UTFencoder {

public void main(String[] args) {

String testString = encodeStringToUTF8("this is my app ... eskadenia");
System.out.println(testString);
}

public static String encodeStringToUTF8(String stringToEncode) {
String newValue = "";
List<String> charactersCode = new ArrayList<String>();
try {
byte[] stringBytes = stringToEncode.getBytes("UTF-8");
for (int i = 0; i < stringBytes.length; i++) {
//System.out.println("utf value is " + stringBytes[i]);
String value = String.valueOf(stringBytes[i]);

int no = Integer.parseInt(value);
String hex = Integer.toHexString(no);
//System.out.println("Hex value is " + hex);
for (int j = 0; j < hex.length(); j++) {
charactersCode.add(String.valueOf(hex.charAt(j)));
}

}
} catch (UnsupportedEncodingException e) {
System.out.println("Cannot encode " + stringToEncode
+ " to UTF-8, UnsupportedEncodingException");
}

Iterator iterator =charactersCode.iterator();

while(iterator.hasNext()){
Object element= iterator.next();
System.out.print(element+" ");




}

return newValue;
}

}

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com