ML Kit提供两种集成SDK方式,您可以参见概述(Full SDK和基础SDK),根据您的应用场景选择不同的集成方式。
先集成SDK基础包,再集成应用所需的算法包。算法包信息如下:
| 包类型 | 包名 | 包大小 | 坐标名称 |
|---|---|---|---|
| 语种检测算法包 | ml-computer-language-detection-model | 5.4M | com.huawei.hms:ml-computer-language-detection-model:2.0.0.303 |
Full SDK方式集成的示例代码如下:
- dependencies{
- // 引入基础SDK
- implementation 'com.huawei.hms:ml-computer-language-detection:2.0.0.303'
- // 引入语种检测算法包
- implementation 'com.huawei.hms:ml-computer-language-detection-model:2.0.0.303'
- }
示例代码如下:
- dependencies{
- implementation 'com.huawei.hms:ml-computer-language-detection:2.0.0.303'
- }
用上述两种方式之一集成SDK后,在文件头添加配置。
- apply plugin: 'com.huawei.agconnect'
此项配置需要在如下配置项后添加。
- apply plugin: 'com.android.application'
添加如下语句到AndroidManifest.xml文件中,用户从华为应用市场安装您的应用后,将自动更新机器学习模型到设备:
- <manifest
- ...
- <meta-data
- android:name="com.huawei.hms.ml.DEPENDENCY"
- android:value= "langdetect"/>
- ...
- </manifest>