공유 환경 설정 메뉴에 UTF8이 사용되도록하려면 어떻게해야합니까? 나는 사용자가 다른 것들 사이에서 그들의 이름을 설정할 수있는 안드로이드 환경 설정 메뉴가 있습니다.android, UTF8 - 공유 환경 설정에 UTF8이 사용되도록하려면 어떻게해야합니까?
내가 선호 메뉴가 파일에 고해상도/XML 폴더라는 설정을 UTF8 인코딩을 사용하여 XML에 배치하고이처럼 보이는
UTF8 형식으로 공유 환경 설정에 저장된 데이터를 변환하는 방법을 알고 있어야합니다 :
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen
xmlns:android="http://schemas.android.com/apk/res/android">
<EditTextPreference
android:key="@string/name_key"
android:title="@string/hof_name_title"
android:summary="@string/hof_name_summary"
android:defaultValue="Anonymous" />
<CheckBoxPreference
android:key="@string/new_game_preference_key"
android:title="@string/new_game_preference_title"
android:summary="@string/new_game_preference_summary"
android:defaultValue="false" />
</PreferenceScreen>
이
public class PrefsActivity extends PreferenceActivity implements OnSharedPreferenceChangeListener{
@Override
protected void onCreate(Bundle savedInstanceState) {
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.settings);
}
@Override
protected void onPause() {
super.onPause();
// Unregister the listener whenever a key changes
getPreferenceScreen().getSharedPreferences()
.unregisterOnSharedPreferenceChangeListener(this);
}
@Override
protected void onResume() {
super.onResume();
// Set up a listener whenever a key changes
getPreferenceScreen().getSharedPreferences()
.registerOnSharedPreferenceChangeListener(this);
}
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences,
String key) {
// Util.log_debug_message("@@@@ Changed prefrence key = " + key);
if (key.equalsIgnoreCase(getString(R.string.name_key))){
update_webserver();
}else if (key.equalsIgnoreCase(getString(R.string.new_game_preference_key))){
update_webserver();
}
}
protected void update_webserver(){
Intent webServerReg = new Intent(this, RegService.class);
webServerReg.putExtra(Config.C2DM_REG_ID_EXTRA, C2DMessaging.getRegistrationId(this));
startService(webServerReg);
}
}
난 그 텍스트를 보장 할 <?xml version="1.0" encoding="utf-8"?>
을 설정하면 fo를 UTF8로 인코딩 될 것으로 가정 처리하는 클래스 rmat하지만 이것이 항상 그런 것은 아닙니다. 나는 모든 종류의 형식으로 가치를 얻고있다. 몇 가지 예
"\ NFE \ xF1a", "L \ xFAcia", "$ '\ xE5이 xEE \'",
또는
"- $ B- O : -) : - P = -OB -) : - D : -Q : -X : - : - | \ n : '(: - XDo_O : -X : -C : -X : O : - X : -O : -) : -) : -) - :) : - D : OX- (o_O : -V : - @ : -V : -X : -Do_O :: -C \ xBF \ xA1 \ xA1 \ xA2 \ xA5 \ xA1 \ xAE \ xA7> < [\ xA3 ~? = ~
\xB0]\xA3?\xA7\xA1\\\xAB\xBB\xAE^``]]||||}{_|
] | || \ xB0 \ xB0? "
예. 마지막 예에서 하나의 루비 (rubish) 집합입니다.
문제는 내가 유효한 기대
public void update(String regId) throws AuthenticationException {
JSONObject mu_to_send = createJsonToPost(regId, false);
HttpResponse response;
try {
response = HttpRequest.httpPutJSONObject(this,
Config.UPDATE_USER_URL, mu_to_send);
int responseCode = response.getStatusLine().getStatusCode();
String responseJson;
try {
responseJson = EntityUtils.toString(response.getEntity());
String msg = "";
if (responseCode == 201) {
// mobile_user = new
// JSONObject(responseJson).getJSONObject("mobile_user");
// Broadcast.sendBroadcast(this,
// ResponseReceiver.ACTION_RESP,
// Intent.CATEGORY_DEFAULT, Config.C2DM_MESSAGE_EXTRA,
// Config.BROADCAST_WEBSERVER_USER_CREATED);
} else {
msg = "Failed to register with server! HTTP response code = "
+ responseCode;
}
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} catch (ClientProtocolException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
public JSONObject createJsonToPost(String regId, boolean set_password) {
JSONObject holder = new JSONObject();
JSONObject data = new JSONObject();
try {
data.put("auth", regId);
data.put("name", C2DMessaging.getName(this));
data.put("receive_new_game_notification",
C2DMessaging.getGameStartedNotificationPreference(this));
holder.put("mobile_user", data);
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return holder;
}
public static HttpResponse httpPutJSONObject(Context context, String url,
JSONObject data) throws ClientProtocolException, IOException,
AuthenticationException {
DefaultHttpClient httpclient = getHttpClient(context);
HttpPut httpput = new HttpPut(url);
httpput.addHeader("User-Agent", Config.USER_AGENT);
httpput.addHeader("Accept", "application/json");
httpput.addHeader("Content-type", "application/json");
httpput.addHeader(new BasicScheme().authenticate(
getCredentials(context), httpput));
StringEntity se = new StringEntity(data.toString());
httpput.setEntity(se);
return httpclient.execute(httpput);
}
이 내 웹 서버에 문제가 모든 종류의 원인이 다음 코드를 사용하여 내 웹 서버에 json으로 HTTP의 POST와 같은 신물질 또는 PUT 요청을 보내려고 할 때 시작했다 JSON (즉, UTF8) JSON은 UTF8로 인코딩 된 상태로 보내야합니다.
그래서
1) 당사 <?xml version="1.0" encoding="utf-8"?>
실제로 설정하지 않습니다 UTF8 인코딩? 레이아웃에서 사용될 때?
2) 유효한 UTF8 형식의 문자를 웹 서버에 보내려면 어떻게해야합니까? 이 작업은 put 요청이나 공유 환경 설정에 저장되는 코드 또는 json 개체를 채우는 코드 또는 아마도 위의 의 조합으로 처리해야합니까? 또는 다른 것?
이것은이 RoR에 질문 Rails 3 - How to handle PG Error incomplete multibyte character
을 참고하시기 바랍니다 - 나는 믿는다 설정이 " XML 버전 ="1.0 "인코딩 = 'UTF-8 '?> "는 레이아웃 파일 내용이 utf-8로 인코딩되었음을 모든 xml 파서에 지시하는 것입니다. 즉, 그것은 전적으로 XML 레이아웃 파일 자체의 속성이며 레이아웃을 사용할 때 안드로이드의 동작에 어떤 영향을 미치지 않는다고 생각합니다. –