В ChromeActivity.Java я настроил некоторый код, но он не работает как addJavascriptInterface webview, который я сделал:
import org.chromium.content.browser.JavascriptInterface;
@SuppressLint("JavascriptInterface")
@Override
public void createContextualSearchTab(String searchUrl) {
Tab currentTab = getActivityTab();
if (currentTab == null) return;
Class<? extends Annotation> requiredAnnotation = JavascriptInterface.class;
currentTab.getWebContents().addPossiblyUnsafeJavascriptInterface(new MyJavaScriptInterface(this), "MyJS", requiredAnnotation);
TabCreator tabCreator = getTabCreator(currentTab.isIncognito());
if (tabCreator == null) return;
tabCreator.createNewTab(
new LoadUrlParams(searchUrl, PageTransition.LINK),
TabModel.TabLaunchType.FROM_LINK, currentTab);
}
public class MyJavaScriptInterface {
ChromeActivity context;
public MyJavaScriptInterface(ChromeActivity activity) {
this.context = activity;
}
@JavascriptInterface
@SuppressWarnings("unused")
public void closeApp(){
this.context._closeApp();
}
}
Chromium для Android Studio Исходный код: https://github.com/kuoruan/Chromium-Android