모바일 프로그램 - 안드로이드(언어번역기)
- 최초 등록일
- 2010.02.20
- 최종 저작일
- 2009.10
- 7페이지/ 한컴오피스
- 가격 2,000원
소개글
안드로이드를 이용하여 언어번역기(GOOGLE TRANSLATE) 프로그램 제작,
캡쳐화면과 소스코드, 해설 내용이 담겨 있는 레포트입니다.
언어번역기는 Google의 API를 이용하여 수행됩니다.
"헬로 안드로이드"책에 빠져 있는 클래스에 대해서도 첨부 하였습니다.
목차
1. 프로그램 실행 모습
2. 프로그램 소스 코드
3. 프로그램 소스 코드 해설
4. 기타
본문내용
private String doTranslate(String original, String from, String to) {
String result = translate.getResources().getString(R.string.translation_error);
HttpURLConnection con = null;
Log.d(TAG, "doTranslate(" + original + ", " + from + ", " + to + ")");
try {
if (Thread.interrupted())
throw new InterruptedException();
String q = URLEncoder.encode(original, "UTF-8");
URL url = new URL("http://ajax.googleapis.com/ajax/services/language/translate"
+ "?v=1.0" + "&q=" + q + "&langpair=" + from + "%7C" + to);
con = (HttpURLConnection) url.openConnection();
con.setReadTimeout(10000);
con.setConnectTimeout(15000);
con.setRequestMethod("GET");
con.setDoInput(true);
con.connect();
if (Thread.interrupted())
throw new InterruptedException();
BufferedReader reader = new BufferedReader(new InputStreamReader(
con.getInputStream(), "UTF-8"));
String payload = reader.readLine();
reader.close();
JSONObject jsonObject = new JSONObject(payload);
result = jsonObject.getJSONObject("responseData").getString("translatedText").replace
("`", "`").replace("&","&");
if (Thread.interrupted())
throw new InterruptedException();
} catch (IOException e) {
Log.e(TAG, "IOException", e);
} catch (JSONException e) {
Log.e(TAG, "JSONException", e);
} catch (InterruptedException e) {
Log.d(TAG, "InterruptedException", e);
result = translate.getResources().getString(
참고 자료
http://pragprog.com/titles/eband (본 사이트에서 제공되는 소스코드에는 문제점을 가지고 있으며, 본 레포트에서 그 문제점에 대한 해결책을 제시 합니다.)