Advertisement
Guest User

Untitled

a guest
Jun 25th, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.72 KB | None | 0 0
  1. package com.example.ai_sdk_test;
  2.  
  3. import android.annotation.SuppressLint;
  4. import android.content.Context;
  5. import android.webkit.JavascriptInterface;
  6. import android.webkit.WebView;
  7. import androidx.appcompat.app.AppCompatActivity;
  8. import android.os.Bundle;
  9.  
  10. public class MainActivity extends AppCompatActivity {
  11. public WebView webview;
  12.  
  13. @SuppressLint("SetJavaScriptEnabled")
  14. @Override
  15. protected void onCreate(Bundle savedInstanceState) {
  16. super.onCreate(savedInstanceState);
  17. setContentView(R.layout.activity_main);
  18. this.webview = this.findViewById(R.id.webview_1);
  19. this.webview.getSettings().setJavaScriptEnabled(true);
  20. this.webview.addJavascriptInterface(new WebAppInterface(this), "NativeApp");
  21. this.webview.loadUrl("file:///android_asset/index.html");
  22. }
  23. }
  24.  
  25. class WebAppInterface {
  26. Context mContext;
  27.  
  28. /**
  29. * Instantiate the interface and set the context
  30. */
  31. WebAppInterface(Context c) {
  32. mContext = c;
  33. }
  34.  
  35. /**
  36. * Show a toast from the web page
  37. */
  38. @JavascriptInterface
  39. public void getFrame(int maxWidth, int maxHeight) {
  40. /*
  41. 1) Retrieve a frame from camera
  42. 2) resize it to maxWidth x maxHeight (mantaining the aspect ration)
  43. 3) Convert the frame to Base64
  44. 4) return the Base64 String
  45. */
  46. return res;
  47. }
  48.  
  49. @JavascriptInterface
  50. /**
  51. * @type: String-enum in ["AGE","GENDER","EMOTION","FEATURES","POSE","AROUSAL_VALENCE","ATTENTION"]
  52. * @value: Json-stringified of of the result
  53. */
  54. public void onData(String type, String value) {
  55. /*
  56. send data to the serve
  57. */
  58. }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement