[Huawei Developers] Sherlock F:
More information like this, you can visit HUAWEI Developer Forum​

Introduction

Online food ordering is process to deliver food from restaurants. In this article will do how to Integrate Analytics, App-Messaging in food applications.

Steps

1. Create App in Android.

2. Configure App in AGC.

3. Integrate the SDK in our new Android project.

4. Integrate the dependencies.

5. Sync project.

Analytics Module

Huawei Analytics will helps to understand how people using mobile application. Analytics model help you gain a deeper insight into your user, products and contents.

1. Collect and report custom events.

2. Set a maximum of 25 user attributes

3. Automate event collection and session calculation with predefined event ID’s and parameter.

Use Cases

1. Analyze user behaviour using both predefined and custom events.

2. Use audience building to tailor your marketing activity to your users’ behaviour and preferences.

3. Use dashboards and analytics to measure your marketing activity and identify areas to improve.

Function Restrictions

Device restrictions: The following automatically collected events of analytics kit depend on HMS Core (APK). Therefore, which are not supported on third-party devices where HMS Core is not installed including but not limited to Oppo, Vivo, Xiaomi, Samsung and Oneplus.

Event quantity restriction: Each app can analyze a maximum of 500 events.

Event parameter restrictions: You can define a maximum of 25 parameters for each event, and maximum of 100 event parameter for each app.

AGC Configuration

1. Create an app adding an app to the project.

2. Enable Analytics Choose My Projects> Huawei Analytics

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/767/951/2640091000001767951.20200925080706.47733494575479384433822715255285:50511013022126:2800:1067FAD773A31C792D9E34A996734AC11D36E77CE68BD46FDC12B5C4CB89146F.png"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/767/951/2640091000001767951.20200925080706.47733494575479384433822715255285:50511013022126:2800:1067FAD773A31C792D9E34A996734AC11D36E77CE68BD46FDC12B5C4CB89146F.png[/IMG]

3. Enable Analytics API Choose My Projects > Project settings > Manage APIs

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/767/951/2640091000001767951.20200925080940.99139806850941953348272814427975:50511013022126:2800:82730A31A775F51232225F9419ECB409F3E718F6378826EA0E44CBB02877A79F.png"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/767/951/2640091000001767951.20200925080940.99139806850941953348272814427975:50511013022126:2800:82730A31A775F51232225F9419ECB409F3E718F6378826EA0E44CBB02877A79F.png[/IMG]

Integration

Create Application in Android Studio.

App level gradle dependencies.

apply plugin: 'com.android.application'
apply plugin: 'com.huawei.agconnect'

Gradle dependencies

implementation 'com.huawei.hms:hianalytics:5.0.3.300'

Root level gradle dependencies

maven {url 'https://developer.huawei.com/repo/'}
classpath 'com.huawei.agconnect:agcp:1.3.1.300'

1. Create Instance for HiAnalyticsInstance in the onCreate method

HiAnalyticsTools.enableLog();
HiAnalyticsInstance instance = HiAnalytics.getInstance(this);

2. Create method for report an event.

private void reportevent() {
Bundle bundle = new Bundle();
bundle.putString("Name", signInResult.getUser().getDisplayName());
mInstance.onEvent("SIGNIN", bundle);
}

Output

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/767/951/2640091000001767951.20200925081019.53144971774860613660107053121263:50511013022126:2800:E5996EBC99FDEF6C254E5C227E840BD710AF4CC1E37E043ECAAAE88C9D73856E.png"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/767/951/2640091000001767951.20200925081019.53144971774860613660107053121263:50511013022126:2800:E5996EBC99FDEF6C254E5C227E840BD710AF4CC1E37E043ECAAAE88C9D73856E.png[/IMG]

App Messaging Module

Huawei App messaging is one of the power full tool to promote information to audience. This will help when you are trying to get more attention to your application. We can target active users to encourage them to use this app.

App Messaging allows to customize your messages visuals and the way they will be sent, and define events for triggering message sending to your users at the right moment.

Message Types

1. Pop-up Message: Title, body and contain an image, and up to two buttons.

2. Banner Message: Message is displayed on top of the screen, containing a thumbnail and the message title and body. user can tap the banner to access specified page.

3. Image: It contains only image. An image message can be a poster well designed to promote an activity. User can tap the image to access the activity details.

AGC Configuration

1. Enable App Messaging Api Choose My Projects > Project settings > Manage APIs

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/767/951/2640091000001767951.20200925081317.41842847702967129149548263656626:50511013022126:2800:B996CF3F53069BE067B89F2380CC770786168DD5DB434CE1AA40F3BC879D1AF7.png"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/767/951/2640091000001767951.20200925081317.41842847702967129149548263656626:50511013022126:2800:B996CF3F53069BE067B89F2380CC770786168DD5DB434CE1AA40F3BC879D1AF7.png[/IMG]

2. Enable App Messaging Choose My Projects > Growing > App Messaging Click Enable Now.

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/767/951/2640091000001767951.20200925081723.42776414929753032300817530333233:50511013022126:2800:C9EC46F6D66673413A882AAA421B0AABDBCD9574BF801511AAD61B5422C79EC8.png"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/767/951/2640091000001767951.20200925081723.42776414929753032300817530333233:50511013022126:2800:C9EC46F6D66673413A882AAA421B0AABDBCD9574BF801511AAD61B5422C79EC8.png[/IMG]

3. Click New button and enter the required information.

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/767/951/2640091000001767951.20200925081352.13943729952311616297838890963642:50511013062635:2800:B965686D6D46C2077F8743217DC0B534DEB172FB1EF013590DD9FAED592118E9.png"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/767/951/2640091000001767951.20200925081352.13943729952311616297838890963642:50511013062635:2800:B965686D6D46C2077F8743217DC0B534DEB172FB1EF013590DD9FAED592118E9.png[/IMG]

4. Enter required details, and then click Next button.

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/767/951/2640091000001767951.20200925081418.27077328617483470579816713213499:50511013022126:2800:BF354147114F75C5AF289CD1ECEC2D8B9E37A19A7F6C57206CFCAAF92E4E508C.png"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/767/951/2640091000001767951.20200925081418.27077328617483470579816713213499:50511013022126:2800:BF354147114F75C5AF289CD1ECEC2D8B9E37A19A7F6C57206CFCAAF92E4E508C.png[/IMG]

5. In Select Sending Target node, click New condition for matching target users.

Select conditions in Select drop-down, and then click Next

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/767/951/2640091000001767951.20200925081439.39050251570044518529476671742721:50511013022126:2800:ED9ED7F9625AF5C587D15B40AEE79A972BBA121DE9B204E615A18B6BFAE3FB19.png"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/767/951/2640091000001767951.20200925081439.39050251570044518529476671742721:50511013022126:2800:ED9ED7F9625AF5C587D15B40AEE79A972BBA121DE9B204E615A18B6BFAE3FB19.png[/IMG]

6. In Set Sending Time node, select Started and Ended drop-downs.

Select required options in Trigger event and Frequency limit, and then click Next

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/767/951/2640091000001767951.20200925081506.46993207482384956564522363761926:50511013022126:2800:1FAB59CA161B2AE0909E69E840C70E18DE27B5AE56877684C1CE95C866AA5DA1.png"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/767/951/2640091000001767951.20200925081506.46993207482384956564522363761926:50511013022126:2800:1FAB59CA161B2AE0909E69E840C70E18DE27B5AE56877684C1CE95C866AA5DA1.png[/IMG]

7. Once all the required information filled, and then click Save button

8. Navigate to Operation tab, and then click Test option to perform the App Messaging publishing

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/767/951/2640091000001767951.20200925081536.62396877713900304301351436735377:50511013022126:2800:BEEDBE74EDF9D3BA4B14A6C7264E447BAED9A2D303F73E4D849D5F6C5E678417.png"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/767/951/2640091000001767951.20200925081536.62396877713900304301351436735377:50511013022126:2800:BEEDBE74EDF9D3BA4B14A6C7264E447BAED9A2D303F73E4D849D5F6C5E678417.png[/IMG]

Integration

Gradle dependencies

implementation 'com.huawei.agconnect:agconnect-appmessaging:1.4.0.300'

1. Generate AAID, this AAID will help you to sending App-Messages.

private void generateAAID(){
HmsInstanceId inst = HmsInstanceId.getInstance(this);
Task<AAIDResult> idResult = inst.getAAID();
idResult.addOnSuccessListener(aaidResult -> Log.d("AAID", "getAAID success:" + aaidResult.getId() ))
.addOnFailureListener(e -> Log.d("AAID", "getAAID failure:" + e));
}

2. For displaying messages we need to call AGConnectAppMessaging Instance.

3. setFetchMessageEnable() To allow data synchronization from the app gallery connect server.

4. setDisplayEnable() To Enable message display.

5. setForceFetch() To specify that the in-app message data must be obtained from App Gallery connect server.

private void initializeInAppMessage(){
AGConnectAppMessaging appMessaging = AGConnectAppMessaging.getInstance();
appMessaging.setFetchMessageEnable(true);
appMessaging.setDisplayEnable(true);
appMessaging.setForceFetch();
}

Result:

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/767/951/2640091000001767951.20200925083218.87913176282877856063358489757629:50511013062635:2800:066C8A5CAA651B864D273C5CE4E8F344A180C6D1BB04B53BDBE165E163E2F188.png"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/767/951/2640091000001767951.20200925083218.87913176282877856063358489757629:50511013062635:2800:066C8A5CAA651B864D273C5CE4E8F344A180C6D1BB04B53BDBE165E163E2F188.png[/IMG]

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/767/951/2640091000001767951.20200925083132.08914416659867782408912088871313:50511013022126:2800:A23807B4BC1D823A1905C11397D2FCB15DDCB7393826185D9FF151FD9F4A1E89.png"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/767/951/2640091000001767951.20200925083132.08914416659867782408912088871313:50511013022126:2800:A23807B4BC1D823A1905C11397D2FCB15DDCB7393826185D9FF151FD9F4A1E89.png[/IMG]

Conclusion

In this Article, I have explained how to integrate App Messaging and Analytics Kit on food application.

Reference:

Analytics kit:

https://developer.huawei.com/consumer/en/doc/development/HMSCore-Guides/introduction-0000001050745149

App Messaging:

https://developer.huawei.com/consumer/en/doc/development/AppGallery-connect-Guides/agc-appmessage-introduction