Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.example.ai_sdk_test;
- import android.annotation.SuppressLint;
- import android.content.Context;
- import android.webkit.JavascriptInterface;
- import android.webkit.WebView;
- import androidx.appcompat.app.AppCompatActivity;
- import android.os.Bundle;
- public class MainActivity extends AppCompatActivity {
- public WebView webview;
- @SuppressLint("SetJavaScriptEnabled")
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- this.webview = this.findViewById(R.id.webview_1);
- this.webview.getSettings().setJavaScriptEnabled(true);
- this.webview.addJavascriptInterface(new WebAppInterface(this), "NativeApp");
- this.webview.loadUrl("file:///android_asset/index.html");
- }
- }
- class WebAppInterface {
- Context mContext;
- /**
- * Instantiate the interface and set the context
- */
- WebAppInterface(Context c) {
- mContext = c;
- }
- /**
- * Show a toast from the web page
- */
- @JavascriptInterface
- public void getFrame(int maxWidth, int maxHeight) {
- /*
- 1) Retrieve a frame from camera
- 2) resize it to maxWidth x maxHeight (mantaining the aspect ration)
- 3) Convert the frame to Base64
- 4) return the Base64 String
- */
- return res;
- }
- @JavascriptInterface
- /**
- * @type: String-enum in ["AGE","GENDER","EMOTION","FEATURES","POSE","AROUSAL_VALENCE","ATTENTION"]
- * @value: Json-stringified of of the result
- */
- public void onData(String type, String value) {
- /*
- send data to the serve
- */
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement