If you want your app to support ML Kit, complete the integration preparation by referring to Preparations.
Google API | To HMS API |
|---|---|
FirebaseVision.getInstance(com.google.firebase.FirebaseApp app) | com.huawei.hms.mlsdk.MLAnalyzerFactory.getInstance (com.huawei.hms.mlsdk.common.MLApplication app) You need to manually add code to create the parameter app. Originally, the com.google.firebase.FirebaseApp parameter is created by using FirebaseApp.getInstance() to obtain the default FirebaseApp instance or using FirebaseApp.getInstance(String appName) to obtain the FirebaseApp instance based on the app name. Now, you can use MLApplication.getInstance() to obtain the default MLApplication instance. |
To HMS API sample code:
com.huawei.hms.mlsdk.common.MLApplication app = com.huawei.hms.mlsdk.common.MLApplication.getInstance("appName");
com.huawei.hms.mlsdk.MLAnalyzerFactory factory = com.huawei.hms.mlsdk.MLAnalyzerFactory.getInstance(app); Google API | To HMS API |
|---|---|
com.google.android.gms.vision.face.FaceDetector.finalize() | com.huawei.hms.mlsdk.face.MLFaceAnalyzer.stop() MLFaceAnalyzer does not support overriding the finalize method. The stop method can be called to free resources. |
Google API | Add HMS API | To HMS API |
|---|---|---|
com.google.firebase.ml.vision.face.FirebaseVisionFace.INVALID_ID | Not provided | Not provided |
com.google.firebase.ml.vision.label.FirebaseVisionImageLabeler.ON_DEVICE_AUTOML | Not provided | Not provided |
If the switch-case statement is used in the Google API code, convert it to the if-else statement in the Add HMS API scenario. The following is the sample code.
Google API code:
int rotation;// Set rotation.
int rotationDegree = 0;
switch (rotation) {
case FirebaseVisionImageMetadata.ROTATION_90:
rotationDegree = 90;
break;
case FirebaseVisionImageMetadata.ROTATION_180:
rotationDegree = 180;
break;
case FirebaseVisionImageMetadata.ROTATION_270:
rotationDegree = 270;
break;
default:
break;
} int rotation;// Set rotation.
int rotationDegree = 0;
if (rotation == ExtensionVisionImageMetadata.getROTATION_90()) {
rotationDegree = 90;
} else if (rotation == ExtensionVisionImageMetadata.getROTATION_180()) {
rotationDegree = 180;
} else if (rotation == ExtensionVisionImageMetadata.getROTATION_270()) {
rotationDegree = 270;
} else {
Log.i("rotation Degree","Unknown rotation");
}