Unity3D Facebook SDK for Android Integration - 6. 친구에게 자랑하기

 유니티3D 페이스북 안드로이드 친구에게 앱 요청하기에 이어 친구에게 게임 상태 자랑하기를 연동해보겠습니다.


    private void showDialogWithoutNotificationBar(String action, Bundle params) {
    // Create the dialog
        dialog = new WebDialog.Builder(UnityPlayer.currentActivity
        , Session.getActiveSession()
        , action
        , params).setOnCompleteListener(
                        new WebDialog.OnCompleteListener() {
                       
               @Override
               public void onComplete(Bundle values, FacebookException error) {
                       if (error != null && !(error instanceof FacebookOperationCanceledException)) {
                             
                       }
                       dialog = null;
                       dialogAction = null;
                       dialogParams = null;
               }
                        }).build();
     
   // Hide the notification bar and resize to full screen
   Window dialog_window = dialog.getWindow();
   dialog_window.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
 
   // Store the dialog information in attributes
   dialogAction = action;
   dialogParams = params;
 
   // Show the dialog
   dialog.show();
}

 먼저 자랑하기 다이얼로그를 띄워주는 자바 소스입니다. 기존에 친구에게 앱 요청하기와 WebDialog.OnCompleteListener의 onComplete 처리가 겹치므로 아래와 같이 따로 멤버 변수로 만들어서 인자로 넘겨 받아 처리하는 식으로 하면 되겠습니다.

private WebDialog.OnCompleteListener inviteFriendComplate = new WebDialog.OnCompleteListener() {

@Override
public void onComplete(Bundle arg0, FacebookException arg1) {
...
                }
};

 다음은 유니티3D에서 호출하는 함수입니다.

    public void requestBrag_U(final String strTitle, final String strCaption, final String strDescription, final String strPicture) {
    runOnUiThread(new Runnable() {

@Override
public void run() {
// TODO Auto-generated method stub
Bundle params = new Bundle();
params.putString("name", strTitle);
params.putString("caption", strCaption);
params.putString("description", strDescription);
params.putString("picture", strPicture);
showDialogWithoutNotificationBar("feed", params);
}
    });
    }

 친구에게 자랑할 때 필요한 인자값은 name, caption, description, picture가 있습니다. 이것을 Bundle로 만들어 처리하면 됩니다. 추가적으로 상호 작용을 위한 딥 링크 작업에 필요한 link가 있지만 이번 포스팅에서는 제외합니다.

 이하는 유니티3D에서 처리하는 함수들입니다.

public void RequestBrag(string strTitle, string strCaption, string strDescription, string strPicture)
{
curActivity.Call("requestBrag_U", strTitle, strCaption, strDescription, strPicture);
}


fYpos += 50;
if (GUI.Button (new Rect(fXpos, fYpos, 100, 50), "Brag!") == true)
{
FacebookManager.GetInstance().RequestBrag("WestWoodForever"
                                         , "Unity3D Facebook Android"
                                         , "Request Brag!!"
                                         , "http://lh4.googleusercontent.com/-DrSTrtL3Pl8/AAAAAAAAAAI/AAAAAAAANbQ/8wxo_-667bM/s512-c/photo.jpg");
}

 간단하게 인자에 스트링을 처리했지만 자신의 점수등을 잘 조합해서 친구에게 자랑하면 되겠죠.

 Brag! 버튼을 눌러 자랑하기 창을 띄웠습니다. name과 caption, description, picture가 모두 설정 되었고 추가적인 내용을 입력할 수 있습니다.

 웹에서 확인해보면 이렇게 피드에 남겨진 것을 확인할 수 있죠. 웹에서는 클릭해봐야 이미지만 나오고 안드로이드 페이스북 앱에서 클릭하면 게임이 안깔려 있다면 구글 플레이로 깔려있다면 게임이 실행됩니다.


참고
페이스북 개발자 센터
깃허브 페이스북 안드로이드 smash 샘플

댓글

이 블로그의 인기 게시물

'xxx.exe' 프로그램을 시작할 수 없습니다. 지정된 파일을 찾을 수 없습니다.

goorm IDE에서 node.js 프로젝트로 Hello World Simple Server 만들어 띄워보기

애드센스 수익을 웨스턴 유니온으로 수표대신 현금으로 지급 받아보자.