Access native Android methods with JavaScript through Tealeaf customized WebView
Overview
When you create hybrid applications, you can access native Android methods with JavaScript using the customized WebView.
Before you begin
- Install and implement the most recent Tealeaf Android SDK.
- Include the most recent UI Capture j2 JavaScript source file.
Add WebView to your application
Specify a length, height, weight, and ID that suits your application:
<WebView
android:id="@+id/my_webview"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" />Load the HTML file
In your activity, locate the WebView and load your HTML file:
public class MainActivity extends ActionBarActivity {
private UICWebView mUICWebView;
private String logicalPageName = "BridgeAppActivity";
@Override
protected void onCreate(Bundle savedInstanceState) {
// Initialize tealeaf with a reference to application
Tealeaf tealeaf = new Tealeaf(this.getApplication());
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Load HTML file from local resource in the UICWebview
mUICWebView = (UICWebView) findViewById(R.id.uic_webview);
// Modify the Url for your hybrid app
mUICWebView.loadUrl("file:///android_asset/www/test.html");
WebSettings webSettings = mUICWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
}Copy the application's files
Copy the application's HTML and JavaScript files to the /assets/www folder in your Android project.
Updated 18 days ago
