2013년 10월 3일 목요일

[구글인앱]Preparing Your In-app Billing Application(인앱 빌링 어플리케이션준비) #2

 던전워즈

Preparing Your In-app Billing Application(인앱 어플리케이션준비)

THIS LESSON TEACHES YOU TO

  1. Download the Sample App(샘플앱 다운로드)
  2. Add Your App to the Developer Console(개발자콘솔에앱등록)
  3. Add the In-app Billing Library(인앱빌링라이브러리추가)
  4. Set the Billing Permission(빌링권한추가)
  5. Initiate a Connection with Google Play(구글플레이 연결 초기화)

YOU SHOULD ALSO READ

Before you can start using the In-app Billing service, you'll need to add the library that contains the In-app Billing Version 3 API to your Android project. 
인앱 빌링 서비스를 사용하기 전에, 인앱빌링3 API를 담고 있는 라이브러리를 안드로이드 프로젝트에 추가해야 한다.
You also need to setting the permissions for your application to communicate with Google Play. 
또한 구글플레이와 통신하기 위해서 당신의 애플리케이션에 권한을 설정해야한다.
In addition, you'll need to establish a connection between your application and Google Play. You should also verify that the In-app Billing API version that you are using in your application is supported by Google Play.
부가적으로, 구글플레이와 당신의 앱 사이에서 연결을 수립해야 한다. 또한 애플리케이션에서 사용하고자 하는 인앱 빌링 API버전을 구글플레이가 지원하는지 검증해야 할것이다.

Download the Sample Application(샘플 애플리케이션 받기)


In this training class, you will use a reference implementation for the In-app Billing Version 3 API called the TrivialDrive sample application. The sample includes convenience classes to quickly set up the In-app Billing service, marshal and unmarshal data types, and handle In-app Billing requests from the main thread of your application.
이 훈련 수업에서,  인앱 버전 3 API 구현 참조에 TrivialDrive 이라 불리는 샘플 어플리케이션을 사용할 것이다.
샘플에서는 구글인앱 빌링 서비스를 빠르게 설정하기위한 편의 기능 클래스와, marshal 및 unmarshal 데이터 타입들, 애플리케이션의 메인쓰레드에서 인앱빌링 요청을 다루는 방법을 포함하고 있다.
To download the sample application:(샘플 애플리케이션다운로드를하기)
  1. Open the Android SDK Manager.(안드로이드 SDK 매니저 열기)
  2. In the SDK Manager, expand the Extras section.(SDK매니저에서 Extras 색션을 확장한다)
  3. Select Google Play Billing Library.(Google Play Billing Library를 선택)
  4. Click Install packages to complete the download.(다운로드 완료를 위해 인스톨 패키지 클릭)
The sample files will be installed to <sdk>/extras/google/play_billing/.
샘플파일들은 <sdk>/extras/google/play_billing/ 위치에 인스톨 될것이다.

Add Your Application to the Developer Console(앱을 개발자 콘솔에 등록)


The Google Play Developer Console is where you publish your In-app Billing application and manage the various digital goods that are available for purchase from your application. When you create a new application entry in the Developer Console, it automatically generates a public license key for your application. You will need this key to establish a trusted connection from your application to the Google Play servers. You only need to generate this key once per application, and don’t need to repeat these steps when you update the APK file for your application.
구글플레이 개발자 콘솔은 당신의 인앱 빌링 앱을 게시하고 앱에서 구매 가능한 다양한 디지털 상품을 관리하는 장소다. 당신이 새로운 앱을 개발자 콘솔에 생성했을때, 자동적으로 당신의 앱을 위한 공개 라이센스 키가 발급된다.
당신은 앱에서 구글플레이로 신뢰된 연결을 수립하기 위해 이 키가 필요하다. 오직 단한번 앱을 위한 키생성이 필요하며, 당신의 앱을 갱신시에 다시 이과정을 반복할 필요는 없다.
To add your application to the Developer Console:(앱을 개발자 콘솔에 등록하기)
  1. Go to the Google Play Developer Console site and log in. You will need to register for a new developer account, if you have not registered previously. To sell in-app items, you also need to have a Google Walletmerchant account.
  2. 구글 플레이 개발자 콘솔 사이트로 이동 후 로그인한다. 만일 이전에 등록하지 않았다면, 새로운 개발자 계정 등록이 필요할 것이다. 또한 인앱 아이템 판매를 위해, Google Walletmerchant  계정이 필요하다.
  3. Click on Try the new design to access the preview version of the Developer Console, if you are not already logged on to that version.  
  4. In the All Applications tab, add a new application entry.(All Applications 탭에서 새로운 앱 시작점을 추가한다)
    1. Click Add new application. (새애플리케이션추가클릭)
    2. Enter a name for your new In-app Billing application.(새 인앱 빌링 앱 이름추가)
    3. Click Prepare Store Listing.(상점목록 준비 클릭)
  5. In the Services & APIs tab, find and make a note of the public license key that Google Play generated for your application. This is a Base64 string that you will need to include in your application code later.(서비스와 API탭에서, 구글플레이가 당신의 앱에 생성한 공개 라이센스키 기록을 찾거나 만들 수 있다. 이것은 이후에 당신의 애플리케이션 코드에 포함할 필요가 있는 Base64 문자열이다.)
Your application should now appear in the list of applications in Developer Console.
이제 개발자 콘솔의 애플리케이션 목록에 당신의 앱이 나타날것이다.

Add the In-app Billing Library(인앱빌링라이브러리추가)


To use the In-app Billing Version 3 features, you must add the IInAppBillingService.aidl file to your Android project. This Android Interface Definition Language (AIDL) file defines the interface to the Google Play service.
인앱빌링 버전3기능을 사용하기 위해, 반드시 IInAppBillingService.aidl  파일을 안드로이드 프로젝트에 추가해야한다. 이 안드로이드 인터페이스 선언 언어 파일은(AIDL) 구글 플레이 서비스를 위한 인터페이스를 선언한다.
You can find the IInAppBillingService.aidl file in the provided sample app. Depending on whether you are creating a new application or modifying an existing application, follow the instructions below to add the In-app Billing Library to your project.
IInAppBillingService.aidl 파일은 제공된 샘플 앱에서 찾을 수 있다. 당신이 새로운 애플리케이션을 생성하는지, 기존의 애플리케이션을 수정하는지에 따라서, 아래의 인앱 빌링 라이브러리를 추가 방법을 따라가면된다.

New Project(새프로젝트)

To add the In-app Billing Version 3 library to your new In-app Billing project:(새 프로젝트에 인앱빌링 버전3 추가)
  1. Copy the TrivialDrive sample files into your Android project.(TrivialDrive 샘플 파일을 당신의 안드로이드 프로젝트에 복사한다.)
  2. Modify the package name in the files you copied to use the package name for your project. In Eclipse, you can use this shortcut: right-click the package name, then select Refactor > Rename. (복사된 파일들의 패키지 이름을 당신의 어플리케이션이 사용하는 패키지 이름으로 바꾼다. 이클립스에서, 당신은 이 단축법을 사용할 수 있다 : 패키지이름에서 우클릭, 그때 Refactor > Rename 선택.)
  3. Open the AndroidManifest.xml file and update the package attribute value to use the package name for your project.(AndroidManifest.xml 파일을 열고 패키지 속성값을 당신의 프로젝트에서 사용하는 패키지 이름으로 업데이트한다.)
  4. Fix import statements as needed so that your project compiles correctly. In Eclipse, you can use this shortcut: press Ctrl+Shift+O in each file showing errors.(프로젝트가 제대로 컴파일되도록 프로젝트 임포트 명세를 고친다. 이클립스에서, 다음 숏컷을 사용할 수 있다 : 각파일에서 Ctrl + Shift + O를 누를 경우 오류를 보여준다.)
  5. Modify the sample to create your own application. Remember to copy the Base64 public license key for your application from the Developer Console over to your MainActivity.java.(샘플을 수정해서 당신 자신의 애플리케이션을 만든다. 개발자 콘솔에서 얻은 앱의 Base64 공개키를 MainActivity.java에 복사하는 것을 기억하라.)

Existing Project(기존프로젝트)

To add the In-app Billing Version 3 library to your existing In-app Billing project:
인앱 빌링 버전 3 라이브러리를 당신의 기존 프로젝트에 추가하기:
  1. Copy the IInAppBillingService.aidl file to your Android project.(IInAppBillingService.aidl 파일을 안드로이드 프로젝트에 복사한다.)
    • If you are using Eclipse: Import the IInAppBillingService.aidl file into your /src directory.
    • If you are developing in a non-Eclipse environment: Create the following directory/src/com/android/vending/billing and copy the IInAppBillingService.aidl file into this directory.
    • 이클립스를 사용하는경우: IInAppBillingService.aidl 파일을 프로젝트의 /src 디렉터리에 임포트 한다.
    • 이클립스 환경이 아니경우 : /src/com/android/vending/billing 디렉터리를 만들고 IInAppBillingService.aidl 파일을 이 디렉터리에 복사한다.
  2. Build your application. You should see a generated file named IInAppBillingService.java in the /gendirectory of your project.(앱을 빌드한다. 프로젝트 /gen 디렉토리에 IInAppBillingService.java 이름의 파일이 생성된것이 보일것이다.)
  3. Add the helper classes from the /util directory of the TrivialDrive sample to your project. Remember to change the package name declarations in those files accordingly so that your project compiles correctly.(TrivialDrive 샘플의 /util 디렉터리에 있는 헬퍼클래스들을 프로젝트에 추가한다. 프로젝트가 올바르게 컴파일되도록 패키지 이름 선언들을 변경해야 한다는 하는것을 기억하라.)
Your project should now contain the In-app Billing Version 3 library.
당신의 프로젝트는 이제 인앱 빌링 3 라이브러리를 담고 있을 것이다.

Set the Billing Permission(빌링 권한 설정)


Your app needs to have permission to communicate request and response messages to the Google Play’s billing service. To give your app the necessary permission, add this line in your AndroidManifest.xml manifest file:(당신의 앱은 구글 플레이 빌링 서비스와 통신하여 요청하고 응답 메시지를 받기 위한 권한을 가져야한다. 앱에 필요한 권한을 주기 위해서, 다음 라인을 앱의 AndroidManifest.xml 파일에 추가한다.)
<uses-permission android:name="com.android.vending.BILLING" />

Initiate a Connection with Google Play(구글플레이와 연결시작)


You must bind your Activity to Google Play’s In-app Billing service to send In-app Billing requests to Google Play from your application. The convenience classes provided in the sample handles the binding to the In-app Billing service, so you don’t have to manage the network connection directly.
당신의 앱에서 구글 플레이에 인앱 빌링 요청을 보내기 위해서 구글 플레이의 인앱 빌링 서비스에 당신의 액티비티를 반드시 연결해야한다. 샘플에서 다루어지는 편의 기능 클래스들은 인앱빌링 서비스에 연결을 제공한다, 그렇기 떄문에 직접적으로 네트워크 연결을 다룰 필요는 없다.
To set up synchronous communication with Google Play, create an IabHelper instance in your activity'sonCreate method. In the constructor, pass in the Context for the activity, along with a string containing the public license key that was generated earlier by the Google Play Developer Console.
구글플레이와 동기화된 통신 설정을 위해서, IabHelper 인스턴스를 액티비티의  onCreate 메소드에서 생성한다. 생성자에서 액티비티를 위한 컨텍스트와 이전에 구글 플레이 개발자 콘솔에서 생성한 라이센스키가 전달된다. 
Security Recommendation: It is highly recommended that you do not hard-code the exact public license key string value as provided by Google Play. Instead, you can construct the whole public license key string at runtime from substrings, or retrieve it from an encrypted store, before passing it to the constructor. This approach makes it more difficult for malicious third-parties to modify the public license key string in your APK file.
보안 권고: 구글플레일 부터 제공된 공개 라이센스키를 변경없이 하드코딩 형태로 소스에 포함하지 말것을 강력하게 권장한다. 그대신 생성자에 전달전, 런타임에 일련의 스트링으로 부터 공개 라이센스키를 생성하거나, 암호화된 저장소로 부터 회수할 수 있다. 이러한 접근은 악의 적인 목적을 가진 사람들이 당신의 apk파일로 부터 공개 라이센스키를 변경하는 것을 좀더 어렵게 만든다.(역자주: 어짜피 생성자에 전달하는 키만 교체 하면 끝인데 내키를 암호화 해본들 무슨소용???)
IabHelper mHelper;
@Override
public void onCreate(Bundle savedInstanceState) {
   // ...
   String base64EncodedPublicKey;
   
   // compute your public key and store it in base64EncodedPublicKey(공개 키를 계산하고 base64EncodedPublicKey에 저장한다)
   mHelper = new IabHelper(this, base64EncodedPublicKey);
}
Next, perform the service binding by calling the startSetup method on the IabHelper instance that you created. Pass the method an OnIabSetupFinishedListener instance, which is called once the IabHelper completes the asynchronous setup operation. As part of the setup process, the IabHelper also checks if the In-app Billing Version 3 API is supported by Google Play. If the API version is not supported, or if an error occured while establishing the service binding, the listener is notified and passed an IabResult object with the error message.
다음으로, 당신이 생성한 IabHelper 인스턴스의 startSetup 메소드를 호출하여 서비스와 바인딩을 실행한다.메소드에 전달된 OnIabSetupFinishedListener 인스턴스는, IabHelper 의 비동기 작업처리가 완료될때 한번 호출된다. 또한 셋업 프로세스의 한 부분으로 IabHelper 는 구글플레이로 부터 인앱 빌링 버전3이 지원되는지 확인한다. 만일 API버전이 지원되지 않거나, 서비스바인딩중 오류가 발생한다면,  리스너는 오류 메시지와 함께 IabResult 를 포함한 통지를 받게 된다.
mHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() { //OnIabSetupFinishedListener는 IabHelper에정의된 인터페이스로, 인앱 빌링 설정의 결과를 통지 받기 위한 용도를 가지고 있다
   public void onIabSetupFinished(IabResult result) {
      if (!result.isSuccess()) {
         // Oh noes, there was a problem. 아 젠장, 뭔가 문제 있다.
         Log.d(TAG, "Problem setting up In-app Billing: " + result);
      }            
         // Hooray, IAB is fully set up!  아싸, IAB가 완전히 설정됐다!
   }
});
If the setup completed successfully, you can now use the mHelper reference to communicate with the Google Play service. When your application is launched, it is a good practice to query Google Play to find out what in-app items are owned by a user. This is covered further in the Query Purchased Items section.
만일 설정이 완전히 성공한다면, 이제부터  mHelper 레퍼런스를 사용하여 구글 플레이 서비스와 통신할 수 있다. 당신의 애플리케이션이 시작될때, 유저가 어떤 인앱 아이템을 소유하고 있는지 찾기위해 구글플레이로 부터 조회 하는 것은 좋은 방법이다. 이것은 이후에 Query Purchased Items 부분에서 다룰것이다.
Important: Remember to unbind from the In-app Billing service when you are done with your activity. If you don’t unbind, the open service connection could cause your device’s performance to degrade. To unbind and free your system resources, call the IabHelper's dispose method when your Activity gets destroyed.
중요 : 당신의 액티비티가 종료될때 인앱 빌링 서비스로 부터 언바인드 해야하는것을 기억하라. 언바인드 하지 않으경우, 열려진 서비스 연결은 디바이스의 성능 저하의 원인이 될 수 있다. 언바인드하고 시스템 리소를 해제하기 위해서, IabHelper 의 dispose 메소드를 액티비티 종료 신호시 호출한다.
@Override
public void onDestroy() {
   super.onDestroy();
   if (mHelper != null) mHelper.dispose();
   mHelper = null;
}

댓글 없음:

댓글 쓰기