package kr.method.papaya;

import org.apache.cordova.CallbackContext;
import org.apache.cordova.CordovaPlugin;
import org.apache.cordova.LOG;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import com.kakao.KakaoLink;
import com.kakao.KakaoParameterException;
import com.kakao.KakaoTalkLinkMessageBuilder;

public class KakaoLinkPlugin extends CordovaPlugin {
	private final String LINK = "link";
	KakaoLink kakaoLink;

	public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
		//서비스 시작
		if (action.equals(LINK)) {
			final JSONObject options = args.getJSONObject(0);
			this.link(options);
		}
		
		return false;
	}
	
	/**
	 * 카카오 링크 열기
	 */
	private void link(JSONObject options){
		LOG.d("KakaoLinkPlugin", "link");
		String message;
		String image;
		String url;
		String label;
		int width;
		int height;
		try {
			kakaoLink = KakaoLink.getKakaoLink(cordova.getActivity().getApplicationContext());
			final KakaoTalkLinkMessageBuilder kakaoTalkLinkMessageBuilder = kakaoLink.createKakaoTalkLinkMessageBuilder();

			try{
				message = options.getString("label");
				kakaoTalkLinkMessageBuilder.addText(message);
			}catch(JSONException e){
				
			}
			
			try{
				image = options.getString("image");
				width = options.getInt("width");
				height = options.getInt("height");
				kakaoTalkLinkMessageBuilder.addImage(image, width, height);
			}catch(JSONException e){
				
			}
			
			try{
				url = options.getString("webButtonUrl");
			}catch(JSONException e){
				url = "";
			}
			
			try{
				label = options.getString("webButtonText");
			}catch(JSONException e){
				label = "앱으로 이동";
			}
			
			if(!url.equals("") && !label.equals("")){
				kakaoTalkLinkMessageBuilder.addWebButton(label,url);
			}else if(url.equals("") && !label.equals("")){
				kakaoTalkLinkMessageBuilder.addWebButton(label);
			}
			
			kakaoLink.sendMessage(kakaoTalkLinkMessageBuilder.build(), cordova.getActivity().getApplicationContext());
		} catch (KakaoParameterException e) {
			e.printStackTrace();
		}
	}
}

@@ -222,16 +222,42 @@
 bject;%0A%0A
+import android.util.Log;%0A%0A
 import c
@@ -276,16 +276,16 @@
 aoLink;%0A
-
 import c
@@ -849,16 +849,21 @@
  message
+ = %22%22
 ;%0A%09%09Stri
@@ -870,16 +870,21 @@
 ng image
+ = %22%22
 ;%0A%09%09Stri
@@ -889,16 +889,21 @@
 ring url
+ = %22%22
 ;%0A%09%09Stri
@@ -910,16 +910,21 @@
 ng label
+ = %22%22
 ;%0A%09%09int 
@@ -928,16 +928,20 @@
 nt width
+ = 0
 ;%0A%09%09int 
@@ -946,16 +946,20 @@
 t height
+ = 0
 ;%0A%09%09try 
@@ -959,16 +959,60 @@
 %0A%09%09try %7B
+Log.d(%22KakaoLinkPlugin%22,options.toString());
 %0A%09%09%09kaka
@@ -1329,32 +1329,72 @@
 ception e)%7B%0A%09%09%09%09
+Log.d(%22KakaoLinkPlugin%22,e.getMessage());
 %0A%09%09%09%7D%0A%09%09%09%0A%09%09%09try
@@ -1603,20 +1603,60 @@
 ion e)%7B%0A
-
 %09%09%09%09
+Log.d(%22KakaoLinkPlugin%22,e.getMessage());
 %0A%09%09%09%7D%0A%09%09

Update KakaoLinkPlugin.java