(최신) cordova 코르도바 카카오링크 실행

Kakao.Link.sendDefault({
               objectType: 'feed',
               content: {
                  title: title,
                  description: "",
                  imageUrl: "file_upload/"+img,
                  imageWidth: 800,
                  imageHeight: 400,
                  link: {
                     mobileWebUrl: url,
                     webUrl: url
                  }
               }
            });

 

위 코드가 cordova에서 실행이 안되서 해결방법을 찾아봄

 

 

해결방법

http://egloos.zum.com/usanflower/v/4149576

 

cordova android kakaolink 실행 문제

cordova 의 기본 웹뷰에서는 kakaolink가 실행이 안되거나 오류가 난다 cordova android MainActivity.java 파일을 열어서 public class MainActivity extends CordovaActivity{ @Override public void onCreate(Bundle savedInstanceSt

egloos.zum.com

 

public class MainActivity extends CordovaActivity
{
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);

// enable Cordova apps to be started in the background
Bundle extras = getIntent().getExtras();
if (extras != null && extras.getBoolean("cdvStartInBackground", false)) {
moveTaskToBack(true);
}
super.init();
SystemWebViewEngine systemWebViewEngine = (SystemWebViewEngine) appView.getEngine();
WebViewClient myWebViewClient = new MyWebViewClient(systemWebViewEngine);

WebView webView = (WebView) systemWebViewEngine.getView();
webView.setWebViewClient(myWebViewClient);

loadUrl(launchUrl);

}

 

 

import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.net.Uri;
import android.webkit.WebView;

import org.apache.cordova.engine.SystemWebViewClient;
import org.apache.cordova.engine.SystemWebViewEngine;

/**
* Created by kkb on 2018-02-14.
*/

class MyWebViewClient extends SystemWebViewClient {

public MyWebViewClient(SystemWebViewEngine systemWebViewEngine) {
super(systemWebViewEngine);
}

public static final String INTENT_PROTOCOL_START = "intent:";
public static final String INTENT_PROTOCOL_INTENT = "#Intent;";
public static final String INTENT_PROTOCOL_END = ";end;";
public static final String GOOGLE_PLAY_STORE_PREFIX = "market://details?id=";
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (url.startsWith(INTENT_PROTOCOL_START)) {
final int customUrlStartIndex = INTENT_PROTOCOL_START.length();
final int customUrlEndIndex = url.indexOf(INTENT_PROTOCOL_INTENT);
if (customUrlEndIndex < 0) {
return false;
} else {
final String customUrl = url.substring(customUrlStartIndex, customUrlEndIndex);
try {
view.getContext().startActivity(
new Intent(Intent.ACTION_VIEW, Uri.parse(customUrl)));
} catch (ActivityNotFoundException e) {
final int packageStartIndex = customUrlEndIndex + INTENT_PROTOCOL_INTENT.length();
final int packageEndIndex = url.indexOf(INTENT_PROTOCOL_END);

final String packageName = url.substring(packageStartIndex, packageEndIndex < 0 ? url.length() : packageEndIndex);
view.getContext().startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(GOOGLE_PLAY_STORE_PREFIX + packageName)));
}
return true;
}
}
else {
return false;
}
}
}

댓글

Designed by JB FACTORY