HarmonyOS ArkWeb 嵌入H5页面,原有的功能未能实现

1、在嵌入的页面上,通过a标签调起电话功能,在HarmonyOS的webview里面能否直接生效

2、input标签调起相册选择图片,在HarmonyOS的webview里面能否直接生效

HarmonyOS
1天前
浏览
收藏 0
回答 1
待解决
回答 1
按赞同
/
按时间
put_get

1.对于第一个问题请参考以下代码:

// xxx.ets
import web_webview from '@ohos.web.webview';
import call from '@ohos.telephony.call';

@Entry
@Component
struct WebComponent {
  webviewController: web_webview.WebviewController = new web_webview.WebviewController();

  build() {
    Column() {
      Web({ src: $rawfile('call.html'), controller: this.webviewController })
        .onLoadIntercept((event) => {
          if (event) {
            let url: string = event.data.getRequestUrl();
            // 判断链接是否为拨号链接
            if (url.indexOf('tel://') === 0) {
              // 跳转拨号界面
              call.makeCall(url.substring(6), (err) => {
                if (!err) {
                  console.info('make call succeeded.');
                } else {
                  console.info('make call fail, err is:' + JSON.stringify(err));
                }
              });
              return true;
            }
          }
          return false;
        })
    }
  }
}

2.对于第二个问题,请参考以下代码:

@Entry
@Component
struct photo {
  controller: web_webview.WebviewController = new web_webview.WebviewController();
  @State webPickImage: pickImage = new pickImage();
  @State webCameraImage: cameraImage = new cameraImage();

  aboutToAppear() {
    // 配置Web开启调试模式
    web_webview.WebviewController.setWebDebuggingAccess(true);
  }

  build() {
    Column() {
      Button('refresh')
        .onClick(() => {
          try {
            this.controller.refresh();
          } catch (error) {
            let e: business_error.BusinessError = error as business_error.BusinessError;
            console.error(`ErrorCode: ${e.code},  Message: ${e.message}`);
          }
        })
      Button('Register JavaScript To Window')
        .onClick(() => {
          try {
            this.controller.registerJavaScriptProxy(this.webPickImage, "pickImageName", ["testPickImage"]);
            this.controller.registerJavaScriptProxy(this.webCameraImage, "cameraImageName", ["testCameraImage"]);
          } catch (error) {
            let e: business_error.BusinessError = error as business_error.BusinessError;
            console.error(`ErrorCode: ${e.code},  Message: ${e.message}`);
          }
        })
      Web({ src: $rawfile('Test1128.html'), controller: this.controller })
        .javaScriptAccess(true)
    }
  }
}

class pickImage {
  constructor() {
  }

  testPickImage(): string {
    try {

      let PhotoSelectOptions = new picker.PhotoSelectOptions();
      PhotoSelectOptions.MIMEType = picker.PhotoViewMIMETypes.IMAGE_TYPE;
      PhotoSelectOptions.maxSelectNumber = 5;
      let photoPicker = new picker.PhotoViewPicker();
      photoPicker.select(PhotoSelectOptions).then((PhotoSelectResult: picker.PhotoSelectResult) => {
        console.info('PhotoViewPicker.select successfully, PhotoSelectResult uri: ' +
        JSON.stringify(PhotoSelectResult));
      }).catch((err: BusinessError) => {
        console.error('PhotoViewPicker.select failed with err: ' + JSON.stringify(err));
      });
    } catch (error) {
      let err: BusinessError = error as BusinessError;
      console.error('PhotoViewPicker failed with err: ' + JSON.stringify(err));
    }
    return '121';

  }
}

class cameraImage {
  constructor() {
  }

  testCameraImage(): string {
    const context = getContext(this) as common.UIAbilityContext
    context.startAbilityForResult({
      action: "ohos.want.action.imageCapture",
      parameters: {
        callBundleName: "com.hm.imageshow"
      }
    }, (err, data) => {
      console.info("imageCapture:" + `${JSON.stringify(data)}`)
    })
    return '1221';
  }
}
分享
微博
QQ
微信
回复
1天前
相关问题
HarmonyOS h5页面缩放问题
538浏览 • 0回复 待解决
HarmonyOS H5页面加载缓存机制
272浏览 • 1回复 待解决
HarmonyOS Web组件加载在线H5页面
220浏览 • 1回复 待解决
如何在HarmonyOS中调试h5页面
926浏览 • 1回复 待解决
HarmonyOS h5页面是否可以适配Harmony OS
503浏览 • 1回复 待解决
如何使H5页面适配多设备?
757浏览 • 1回复 待解决
app内嵌入H5登录储存
447浏览 • 1回复 待解决
升级API11后h5页面字体变小了
1861浏览 • 1回复 待解决
HarmonyOS h5返回上一页面时会闪一下
434浏览 • 1回复 待解决