2014년 11월 21일 금요일

JAVA 한글 깨질경우 인코딩 확인하기

한글이 깨질경우 간단하게 자바에서 인코딩을 확인해본다.


String originalStr = "Å×½ºÆ®"; // 테스트 
String [] charSet = {"utf-8","euc-kr","ksc5601","iso-8859-1","x-windows-949"};
  
for (int i=0; i<charSet.length; i++) {
 for (int j=0; j<charSet.length; j++) {
  try {
   System.out.println("[" + charSet[i] +"," + charSet[j] +"] = " + new String(originalStr.getBytes(charSet[i]), charSet[j]));
  } catch (UnsupportedEncodingException e) {
   e.printStackTrace();
  }
 }
}


OutPut

[utf-8,utf-8] = Å×½ºÆ®
[utf-8,euc-kr] = ��쩍쨘�짰
[utf-8,ksc5601] = ��쩍쨘�짰
[utf-8,iso-8859-1] = Å×½ºÆ®
[utf-8,x-windows-949] = 횇횞쩍쨘횈짰
[euc-kr,utf-8] = ?����������
[euc-kr,euc-kr] = ?×½ºÆ®
[euc-kr,ksc5601] = ?×½ºÆ®
[euc-kr,iso-8859-1] = ?¡¿¨ö¨¬¨¡¢ç
[euc-kr,x-windows-949] = ?×½ºÆ®
[ksc5601,utf-8] = ?����������
[ksc5601,euc-kr] = ?×½ºÆ®
[ksc5601,ksc5601] = ?×½ºÆ®
[ksc5601,iso-8859-1] = ?¡¿¨ö¨¬¨¡¢ç
[ksc5601,x-windows-949] = ?×½ºÆ®
[iso-8859-1,utf-8] = �׽�Ʈ
[iso-8859-1,euc-kr] = 테스트
[iso-8859-1,ksc5601] = 테스트
[iso-8859-1,iso-8859-1] = Å×½ºÆ®
[iso-8859-1,x-windows-949] = 테스트
[x-windows-949,utf-8] = ?����������
[x-windows-949,euc-kr] = ?×½ºÆ®
[x-windows-949,ksc5601] = ?×½ºÆ®
[x-windows-949,iso-8859-1] = ?¡¿¨ö¨¬¨¡¢ç
[x-windows-949,x-windows-949] = ?×½ºÆ®


2014년 11월 17일 월요일

Android 웹 브라우저 링크로 앱 실행 방법

안드로이드 자체 브라우저로 특정 앱을 실행 하는 것이 가능하다.

이것은 안드로이드 OS가 가진 intent의 특징으로 가능 한것 같다.

Intent 의 자세한 내용은 안드로이드 API Guide에 있는  Intents and Intent Filters 를 보면 알수 있다.


1. 먼저 실행 하고자 하는 앱의 AndroidManifest.xml 파일에서 실행하고자 하는 Activity아래에 Intent-filter를 선언해준다.


<activity android:name="SearchActionActivity">
             <intent-filter>  
                <action android:name="android.intent.action.VIEW"/>  
                <category android:name="android.intent.category.DEFAULT"/>  
                <category android:name="android.intent.category.BROWSABLE"/>  
                <data android:scheme="callMyApp" android:host="search"/>  
            </intent-filter>
</activity>


2. 웹 브라우저 상에서 링크 설정 방법
- 웹에서 특정 URL형태로 설정을 해줘야 해당 앱이 호출되어 실행 되어 진다.

<a href="callMyApp://search"> 나의 앱 검색 실행 </a>

위와같이 웹페이지에서 링크를 설정해 두면 해당 앱이 설치되어 있으면 해당 SearchActionActivity가 바로 실행 되어지는 걸 알수 있다.

따라서, 다른 액션의 Activity를 실행하고 싶다면 다른 Activity에 intent-filter만 추가해주면 가능하다.

<activity android:name="TakePhotoActionActivity">
             <intent-filter>  
                <action android:name="android.intent.action.VIEW"/>  
                <category android:name="android.intent.category.DEFAULT"/>  
                <category android:name="android.intent.category.BROWSABLE"/>  
                <data android:scheme="callMyApp" android:host="takePhoto"/>  
            </intent-filter>
</activity>

웹에서 호출 방법은

<a href="callMyApp://takePhoto"> 나의 앱 사진 찍기 실행 </a>


3. 필요에 따라서 앱이 설치 되어 있으면 실행하고 설치 되어 있지 않으면 구글 플레이 마켓으로 이동 하고 싶다고 한다면 intent 전달 방식으로 호출 하면 된다.(Android Only)

기본 형식은 아래와 같다.

Intent://[host명]?파라미터=파리미터값
#Intent;scheme=callMyApp;action=android.intent.action.VIEW;category=android.intent.category.BROWSABLE;package=com.test.myapp;end


간단한 호출 예
<a href="Intent://takePhoto#Intent;scheme=callMyApp;package=com.test.myapp;end">
나의 앱 사진 찍기 실행 </a>




3. 앱에서 파라메터 값 받아서 처리 하기
- 앱에서 호출되어진 Activity 에서 Intent를 통해서 들어온 데이터에서 파라메터 값을 받아서 처리 할수도 있다.

Uri uriData = getIntent().getData();
String photoNumber = uriData.getQueryParameter("photoNumber ");

웹에서 호출
<a href="callMyApp://takePhoto?photoNumber=1"> 나의 앱 1번 사진 보기 </a>


이상으로 웹에서 링크로 안드로이드 앱의 호출을 알아보았습니다.

이것이 되는 것은 Android OS상에서 기본적으로 Intent 호출 방식을 지원하기 때문에 가능하지 않나 생각됩니다.



참고 사이트
http://developer.android.com/guide/components/intents-filters.html
http://developer.naver.com/wiki/pages/UrlScheme