判断编码格式

判断字符的编码格式(处理中文乱码)


					String subject = cursor.getString(1);
					if (!TextUtils.isEmpty(subject)) {
						try {
							if (java.nio.charset.Charset.forName("UTF-8")
									.newEncoder().canEncode(subject)
									&& java.nio.charset.Charset
											.forName("ISO-8859-1").newEncoder()
											.canEncode(subject)) {
								subject = new String(
										subject.getBytes("ISO-8859-1"), "UTF-8");
							} else if (java.nio.charset.Charset
									.forName("UTF-8").newEncoder()
									.canEncode(subject)) {
								subject = new String(subject.getBytes(),
										"UTF-8");
							} else if (java.nio.charset.Charset
									.forName("ISO-8859-1").newEncoder()
									.canEncode(subject)) {
								subject = new String(subject.getBytes(),
										"ISO-8859-1");
							} else {
								EncodedStringValue v = new EncodedStringValue(
										cursor.getInt(2),
										PduPersister.getBytes(subject));
								subject = v.getString();
							}

						} catch (Exception e) {
							EncodedStringValue v = new EncodedStringValue(
									cursor.getInt(2),
									PduPersister.getBytes(subject));
							subject = v.getString();
						}
					}


你可能感兴趣的:(android)