cordova android kakaolink 실행 문제 cordova



cordova 의 기본 웹뷰에서는 kakaolink가 실행이 안되거나 오류가 난다

cordova android MainActivity.java 파일을 열어서

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);

}

MyWebViewClient.java

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;
}
}
}

덧글

댓글 입력 영역