(최신) cordova 코르도바 카카오링크 실행
- 프로그래밍/하이브리드앱
- 2020. 2. 29.
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
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;
}
}
}
'프로그래밍 > 하이브리드앱' 카테고리의 다른 글
코도바2. cordova 실행 테스트 (0) | 2022.06.13 |
---|---|
코도바1. 윈도우에 cordova 설치 실행 build까지 (0) | 2022.06.13 |
윈도우에 react native 개발 환경 구축하기 (0) | 2022.05.31 |
cordova 애드몹 구현 (0) | 2020.03.26 |
코르도바 이미지 공유 cordova-plugin-file-opener2 간단 예제 (0) | 2020.03.23 |