<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: MuraliAkula1</title>
    <description>The latest articles on DEV Community by MuraliAkula1 (@muraliakula1).</description>
    <link>https://dev.to/muraliakula1</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F808435%2Fb144a6d2-3d46-4cec-adbe-1b8fc5c79164.png</url>
      <title>DEV Community: MuraliAkula1</title>
      <link>https://dev.to/muraliakula1</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/muraliakula1"/>
    <language>en</language>
    <item>
      <title>Log in via SMS and Forgot password? Features using Huawei Account Kit in Attendance Tracker Android app (Kotlin) – Part 2</title>
      <dc:creator>MuraliAkula1</dc:creator>
      <pubDate>Sun, 06 Mar 2022 08:48:06 +0000</pubDate>
      <link>https://dev.to/muraliakula1/log-in-via-sms-and-forgot-password-features-using-huawei-account-kit-in-attendance-tracker-android-app-kotlin-part-2-15ie</link>
      <guid>https://dev.to/muraliakula1/log-in-via-sms-and-forgot-password-features-using-huawei-account-kit-in-attendance-tracker-android-app-kotlin-part-2-15ie</guid>
      <description>&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--cTZMGSY5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mzkroaq6r7qfwez8frfg.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--cTZMGSY5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mzkroaq6r7qfwez8frfg.jpg" alt="Image description" width="800" height="500"&gt;&lt;/a&gt;&lt;br&gt;
&lt;strong&gt;Introduction&lt;/strong&gt;&lt;br&gt;
In this article, we can find the &lt;strong&gt;Huawei Account Kit&lt;/strong&gt; of &lt;strong&gt;Log in via SMS&lt;/strong&gt; and &lt;strong&gt;Forgot password?&lt;/strong&gt; features in Attendance Tracker app. The Log in via SMS is an alternative way of login with Huawei ID, instead of providing password user can enter SMS code from registered Phone Number. Forgot password? can be used when you forgot your password, you can reset the password using the Huawei ID and SMS code will be sent for verification. So, I will provide the series of articles on this Attendance Tracker App, in upcoming articles I will integrate other Huawei Kits.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Account Kit&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;Huawei Account Kit&lt;/strong&gt; provides for developers with &lt;strong&gt;simple&lt;/strong&gt;, &lt;strong&gt;secure&lt;/strong&gt;, and &lt;strong&gt;quick sign-in&lt;/strong&gt; and authorization functions. User is not required to enter accounts, passwords and waiting for authorization. User can click on &lt;strong&gt;Sign In with HUAWEI ID&lt;/strong&gt; button to quickly and securely sign in to the app.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Requirements&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Any operating system (MacOS, Linux and Windows).&lt;/li&gt;
&lt;li&gt;Must have a Huawei phone with HMS 4.0.0.300 or later.&lt;/li&gt;
&lt;li&gt;Must have a laptop or desktop with Android Studio, Jdk 1.8, SDK platform 26 and Gradle 4.6 and above installed.&lt;/li&gt;
&lt;li&gt;Minimum API Level 24 is required.&lt;/li&gt;
&lt;li&gt;Required EMUI 9.0.0 and later version devices.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;How to integrate HMS Dependencies&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;First register as Huawei developer and complete identity verification in Huawei developers website, refer to register a &lt;a href="https://developer.huawei.com/consumer/en/doc/start/registration-and-verification-0000001053628148"&gt;Huawei ID&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;Create a project in android studio, refer &lt;a href="https://developer.huawei.com/consumer/en/codelab/HMSPreparation/index.html#1"&gt;Creating an Android Studio Project&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;Generate a &lt;strong&gt;SHA-256 certificate fingerprint&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;To generate &lt;strong&gt;SHA-256 certificate fingerprint&lt;/strong&gt;. On right-upper corner of android project click &lt;strong&gt;Gradle&lt;/strong&gt;, choose &lt;strong&gt;Project Name &amp;gt; Tasks &amp;gt; android&lt;/strong&gt;, and then click &lt;strong&gt;signingReport&lt;/strong&gt;, as follows.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--BA2Q-eyJ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zevcc8czjmz2o1cuc16n.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--BA2Q-eyJ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zevcc8czjmz2o1cuc16n.png" alt="Image description" width="880" height="516"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Note: Project Name depends on the user created name.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://developer.huawei.com/consumer/en/codelab/HMSPreparation/index.html#0"&gt;Create an App in AppGallery Connect&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Download the &lt;strong&gt;agconnect-services.json&lt;/strong&gt; file from &lt;strong&gt;App information&lt;/strong&gt;, copy and paste in android **Project **under **app **directory, as follows.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Q9uB1vzm--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2ibxp1l0fb1exwrgvuud.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Q9uB1vzm--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2ibxp1l0fb1exwrgvuud.png" alt="Image description" width="464" height="616"&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Enter &lt;strong&gt;SHA-256 certificate fingerprint&lt;/strong&gt; and click **Save **button, as follows.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--tcNH8GRD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/g3fi1juoy379r3cppnm7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--tcNH8GRD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/g3fi1juoy379r3cppnm7.png" alt="Image description" width="880" height="298"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Click &lt;strong&gt;Manage APIs&lt;/strong&gt; tab and enable &lt;strong&gt;Account Kit&lt;/strong&gt;.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Zsc2Hxco--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2if64cmq7icxkv2xbudc.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Zsc2Hxco--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2if64cmq7icxkv2xbudc.jpg" alt="Image description" width="880" height="150"&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Add the below maven URL in &lt;strong&gt;build.gradle(Project)&lt;/strong&gt; file under the repositories of &lt;strong&gt;buildscript&lt;/strong&gt;, &lt;strong&gt;dependencies&lt;/strong&gt; and &lt;strong&gt;allprojects&lt;/strong&gt;, refer &lt;a href="https://developer.huawei.com/consumer/en/codelab/HMSPreparation/index.html#6"&gt;Add Configuration&lt;/a&gt;.&lt;br&gt;
&lt;code&gt;maven { url 'http://developer.huawei.com/repo/' }&lt;br&gt;
classpath 'com.huawei.agconnect:agcp:1.6.0.300'&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Add the below plugin and dependencies in &lt;strong&gt;build.gradle(Module)&lt;/strong&gt; file.&lt;br&gt;
&lt;code&gt;apply plugin: id 'com.huawei.agconnect'&lt;br&gt;
// Huawei AGC&lt;br&gt;
implementation 'com.huawei.agconnect:agconnect-core:1.6.0.300'&lt;br&gt;
// Huawei Account Kit&lt;br&gt;
implementation 'com.huawei.hms:hwid:6.3.0.301'&lt;br&gt;
// Huawei Ads Kit&lt;br&gt;
implementation 'com.huawei.hms:ads:3.4.51.300'&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Now Sync the gradle.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Add the required permission to the &lt;strong&gt;AndroidManifest.xml&lt;/strong&gt; file.&lt;br&gt;
&lt;code&gt;// Account Kit&lt;br&gt;
&amp;lt;uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /&amp;gt;&lt;br&gt;
&amp;lt;uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /&amp;gt;&lt;br&gt;
// Ads Kit&lt;br&gt;
&amp;lt;uses-permission android:name="android.permission.INTERNET" /&amp;gt;&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Let us move to development&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;I have created a project on Android studio with empty activity let us start coding.&lt;/p&gt;

&lt;p&gt;In the &lt;strong&gt;MainActivity.kt&lt;/strong&gt; we can find the business logic for ads.&lt;br&gt;
`class MainActivity : AppCompatActivity() {&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.activity_main)

    // Initialize the Huawei Ads SDK
    HwAds.init(this)
    loadDefaultBannerAd()
}

// To get Banner view from the activity_main.xml. It will display at bottom of the page.
private fun loadDefaultBannerAd() {
    val bottomBannerView = findViewById&amp;lt;BannerView&amp;gt;(R.id.hw_banner_view)
    val adParam = AdParam.Builder().build()
    bottomBannerView.adId = getString(R.string.banner_ad_id) // banner_ad_id is testw6vs28auh3
    bottomBannerView.bannerAdSize = BannerAdSize.BANNER_SIZE_SMART
    bottomBannerView.loadAd(adParam)
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;}`&lt;/p&gt;

&lt;p&gt;In the &lt;strong&gt;activity_main.xml&lt;/strong&gt; we can create the UI screen.&lt;br&gt;
`&amp;lt;?xml version="1.0" encoding="utf-8"?&amp;gt;&lt;br&gt;

    xmlns:app="http://schemas.android.com/apk/res-auto"&lt;br&gt;
    xmlns:tools="http://schemas.android.com/tools"&lt;br&gt;
    android:layout_width="match_parent"&lt;br&gt;
    android:layout_height="match_parent"&lt;br&gt;
    android:orientation="vertical"&lt;br&gt;
    tools:context=".MainActivity"&amp;gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;com.huawei.hms.ads.banner.BannerView
    android:id="@+id/hw_banner_view"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_marginTop="10dp"
    android:layout_marginBottom="10dp"/&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;`&lt;/p&gt;

&lt;p&gt;In the &lt;strong&gt;Home.kt&lt;/strong&gt; we can find the business logic for logout.&lt;br&gt;
`class Home : AppCompatActivity() {&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;private var mAuthManager: AccountAuthService? = null
private var mAuthParam: AccountAuthParams? = null

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.activity_home)

    img_logout.setOnClickListener(mOnClickListener)

}

private fun signOut() {
    mAuthParam = AccountAuthParamsHelper(AccountAuthParams.DEFAULT_AUTH_REQUEST_PARAM)
                 .createParams()
    mAuthManager = AccountAuthManager.getService(this@Home, mAuthParam)
    val signOutTask = mAuthManager?.signOut()
    signOutTask?.addOnSuccessListener {
        Toast.makeText(this, "signOut Success", Toast.LENGTH_SHORT).show()
        val intent = Intent(this@Home, MainActivity::class.java)
        startActivity(intent)
    }?.addOnFailureListener {
        Toast.makeText(this, "signOut fail", Toast.LENGTH_SHORT).show()
    }
}

private val mOnClickListener: View.OnClickListener = object : View.OnClickListener {
    override fun onClick(v: View?) {
        when (v?.id) {
            R.id.img_logout -&amp;gt; signOut()
        }
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;}`&lt;/p&gt;

&lt;p&gt;In the &lt;strong&gt;activity_home.xml&lt;/strong&gt; we can create the UI screen.&lt;br&gt;
`&amp;lt;?xml version="1.0" encoding="utf-8"?&amp;gt;&lt;br&gt;

    xmlns:app="http://schemas.android.com/apk/res-auto"&lt;br&gt;
    xmlns:tools="http://schemas.android.com/tools"&lt;br&gt;
    android:layout_width="match_parent"&lt;br&gt;
    android:layout_height="match_parent"&lt;br&gt;
    android:orientation="vertical"&lt;br&gt;
    tools:context=".Home"&amp;gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:gravity="center"
    android:padding="10dp"
    android:layout_marginTop="20dp"&amp;gt;
    &amp;lt;ImageView
        android:id="@+id/img_logout"
        android:layout_width="150dp"
        android:layout_height="60dp"
        android:layout_marginRight="20dp"
        android:layout_marginTop="20dp"
        android:src="@drawable/logout"/&amp;gt;
    &amp;lt;TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textColor="@color/black"
        android:layout_marginRight="20dp"
        android:layout_marginTop="10dp"
        android:textSize="18sp"
        android:text="Logout"/&amp;gt;
&amp;lt;/LinearLayout&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;`&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Demo&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Log in via SMS&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--NmwrTvob--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mklfj3q7rvqh9qdajk8t.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--NmwrTvob--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mklfj3q7rvqh9qdajk8t.jpg" alt="Image description" width="720" height="1600"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s---u8WsKoB--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6n4j4imr702j1n0dh141.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s---u8WsKoB--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6n4j4imr702j1n0dh141.jpg" alt="Image description" width="352" height="759"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--6xk-FlaC--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zwekx330s4wgy1j2z4ta.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--6xk-FlaC--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zwekx330s4wgy1j2z4ta.jpg" alt="Image description" width="880" height="1859"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Forgot password?&lt;/strong&gt;&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--RbTgaYUV--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/p763kkhfnyhwh11d4wy7.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--RbTgaYUV--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/p763kkhfnyhwh11d4wy7.jpg" alt="Image description" width="720" height="1600"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--BYvs3avC--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/liqktil5mr7hanxfkopv.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--BYvs3avC--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/liqktil5mr7hanxfkopv.jpg" alt="Image description" width="720" height="1600"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--txL4GWDi--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hqel8dqk3m5bl2eh0lj8.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--txL4GWDi--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hqel8dqk3m5bl2eh0lj8.jpg" alt="Image description" width="720" height="1600"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--mL4NgiRf--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3h0t7c2t6m3vwtoalo1a.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--mL4NgiRf--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3h0t7c2t6m3vwtoalo1a.jpg" alt="Image description" width="720" height="1600"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--beStJOsB--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/r8lu67f4wj60py91nk0m.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--beStJOsB--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/r8lu67f4wj60py91nk0m.jpg" alt="Image description" width="378" height="832"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tips and Tricks&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Make sure you are already registered as Huawei developer.&lt;/li&gt;
&lt;li&gt;Set minSDK version to &lt;strong&gt;24&lt;/strong&gt; or later, otherwise you will get &lt;strong&gt;AndriodManifest&lt;/strong&gt; merge issue.&lt;/li&gt;
&lt;li&gt;Make sure you have added the &lt;strong&gt;agconnect-services.json&lt;/strong&gt; file to app folder.&lt;/li&gt;
&lt;li&gt;Make sure you have added &lt;strong&gt;SHA-256 fingerprint&lt;/strong&gt; without fail.&lt;/li&gt;
&lt;li&gt;Make sure all the dependencies are added properly.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;br&gt;
In this article, we have learned about the &lt;strong&gt;Huawei Account Kit&lt;/strong&gt; features of &lt;strong&gt;Log in via SMS&lt;/strong&gt; and &lt;strong&gt;Forgot password?&lt;/strong&gt; in Attendance Tracker app. The &lt;strong&gt;Log in via SMS&lt;/strong&gt; is an alternative way of login with Huawei ID, instead of providing password user can enter SMS code from registered Phone Number. &lt;strong&gt;Forgot password?&lt;/strong&gt; can be used when you forgot your password, you can reset the password using the Huawei ID and SMS code will be sent for verification.&lt;/p&gt;

&lt;p&gt;I hope you have read this article. If you found it is helpful, please provide likes and comments.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Reference&lt;/strong&gt;&lt;br&gt;
Account Kit – &lt;a href="https://developer.huawei.com/consumer/en/doc/development/HMSCore-Guides/get-channel-0000001074587201"&gt;Documentation&lt;/a&gt;&lt;br&gt;
Account Kit – &lt;a href="https://developer.huawei.com/consumer/en/training/course/video/101583015541549183"&gt;Training Video&lt;/a&gt;&lt;br&gt;
Ads Kit – &lt;a href="https://developer.huawei.com/consumer/en/doc/development/HMSCore-Guides/publisher-service-introduction-0000001070671805"&gt;Documentation&lt;/a&gt;&lt;br&gt;
Ads Kit – &lt;a href="https://developer.huawei.com/consumer/en/training/course/video/101582707399567035"&gt;Training Video&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Integration of Huawei Account Kit in Attendance Tracker Android app (Kotlin) - Part 1</title>
      <dc:creator>MuraliAkula1</dc:creator>
      <pubDate>Mon, 28 Feb 2022 06:31:48 +0000</pubDate>
      <link>https://dev.to/muraliakula1/integration-of-huawei-account-kit-in-attendance-tracker-android-app-kotlin-part-1-25pg</link>
      <guid>https://dev.to/muraliakula1/integration-of-huawei-account-kit-in-attendance-tracker-android-app-kotlin-part-1-25pg</guid>
      <description>&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--LQ_sr4yt--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fsxcx0utv4fz3ihhf5bj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--LQ_sr4yt--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fsxcx0utv4fz3ihhf5bj.png" alt="Image description" width="385" height="300"&gt;&lt;/a&gt;&lt;br&gt;
&lt;strong&gt;Introduction&lt;/strong&gt;&lt;br&gt;
In this article, we can learn how to integrate the &lt;strong&gt;Huawei Account Kit&lt;/strong&gt; of &lt;strong&gt;Obtaining Icon Resources&lt;/strong&gt; feature in Attendance Tracker app. So, I will provide the series of articles on this Attendance Tracker App, in upcoming articles I will integrate other Huawei Kits.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Account Kit&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;Huawei Account Kit&lt;/strong&gt; provides for developers with &lt;strong&gt;simple&lt;/strong&gt;, &lt;strong&gt;secure&lt;/strong&gt;, and &lt;strong&gt;quick sign-in&lt;/strong&gt; and authorization functions. User is not required to enter accounts, passwords and waiting for authorization. User can click on &lt;strong&gt;Sign In with HUAWEI ID&lt;/strong&gt; button to quickly and securely sign in to the app.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Requirements&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Any operating system (MacOS, Linux and Windows).&lt;/li&gt;
&lt;li&gt;Must have a Huawei phone with HMS 4.0.0.300 or later.&lt;/li&gt;
&lt;li&gt;Must have a laptop or desktop with Android Studio, Jdk 1.8, SDK platform 26 and Gradle 4.6 and above installed.&lt;/li&gt;
&lt;li&gt;Minimum API Level 24 is required.&lt;/li&gt;
&lt;li&gt;Required EMUI 9.0.0 and later version devices.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;How to integrate HMS Dependencies&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;First register as Huawei developer and complete identity verification in Huawei developers website, refer to register a &lt;a href="https://developer.huawei.com/consumer/en/doc/start/registration-and-verification-0000001053628148"&gt;Huawei ID&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Create a project in android studio, refer &lt;a href="https://developer.huawei.com/consumer/en/codelab/HMSPreparation/index.html#1"&gt;Creating an Android Studio Project&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Generate a &lt;strong&gt;SHA-256 certificate fingerprint&lt;/strong&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;To generate &lt;strong&gt;SHA-256 certificate fingerprint&lt;/strong&gt;. On right-upper corner of android project click &lt;strong&gt;Gradle&lt;/strong&gt;, choose &lt;strong&gt;Project Name &amp;gt; Tasks &amp;gt; android&lt;/strong&gt;, and then click &lt;strong&gt;signingReport&lt;/strong&gt;, as follows.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--tZJCpfJd--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0m38cnsagrz5kpyqae2y.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--tZJCpfJd--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0m38cnsagrz5kpyqae2y.png" alt="Image description" width="880" height="516"&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Note: Project Name depends on the user created name.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://developer.huawei.com/consumer/en/codelab/HMSPreparation/index.html#0"&gt;Create an App in AppGallery Connect&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Download the &lt;strong&gt;agconnect-services.json&lt;/strong&gt; file from &lt;strong&gt;App information&lt;/strong&gt;, copy and paste in android **Project **under **app **directory, as follows.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--IODuFbBP--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kl4tbutyqdgxsqghe9kk.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--IODuFbBP--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kl4tbutyqdgxsqghe9kk.png" alt="Image description" width="464" height="616"&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Enter &lt;strong&gt;SHA-256 certificate fingerprint&lt;/strong&gt; and click **Save **button, as follows.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--X-gZkAj1--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qqyrwosoo10aesfyst0g.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--X-gZkAj1--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qqyrwosoo10aesfyst0g.png" alt="Image description" width="880" height="298"&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Click &lt;strong&gt;Manage APIs&lt;/strong&gt; tab and enable &lt;strong&gt;Account Kit&lt;/strong&gt;.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--mjtbi8FE--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vgpm79sdvn8oyxuq9d4v.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--mjtbi8FE--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vgpm79sdvn8oyxuq9d4v.jpg" alt="Image description" width="880" height="150"&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Add the below maven URL in &lt;strong&gt;build.gradle(Project)&lt;/strong&gt; file under the repositories of &lt;strong&gt;buildscript&lt;/strong&gt;, &lt;strong&gt;dependencies&lt;/strong&gt; and &lt;strong&gt;allprojects&lt;/strong&gt;, refer &lt;a href="https://developer.huawei.com/consumer/en/codelab/HMSPreparation/index.html#6"&gt;Add Configuration&lt;/a&gt;.&lt;br&gt;
&lt;code&gt;maven { url 'http://developer.huawei.com/repo/' }&lt;br&gt;
classpath 'com.huawei.agconnect:agcp:1.6.0.300'&lt;br&gt;
&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Add the below plugin and dependencies in &lt;strong&gt;build.gradle(Module)&lt;/strong&gt; file.&lt;br&gt;
&lt;code&gt;apply plugin: id 'com.huawei.agconnect'&lt;br&gt;
// Huawei AGC&lt;br&gt;
implementation 'com.huawei.agconnect:agconnect-core:1.6.0.300'&lt;br&gt;
// Huawei Account Kit&lt;br&gt;
implementation 'com.huawei.hms:hwid:6.3.0.301'&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Now Sync the gradle.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Add the required permission to the &lt;strong&gt;AndroidManifest.xml&lt;/strong&gt; file.&lt;br&gt;
&lt;code&gt;&amp;lt;uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /&amp;gt;&lt;br&gt;
&amp;lt;uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /&amp;gt;&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Let us move to development&lt;/strong&gt;&lt;br&gt;
I have created a project on Android studio with empty activity let us start coding.&lt;br&gt;
In the &lt;strong&gt;MainActivity.kt&lt;/strong&gt; we can find the business logic for login icon.&lt;br&gt;
`class MainActivity : AppCompatActivity() {&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;lateinit var mAuthManager: AccountAuthService
private var mAuthParam: AccountAuthParams? = null

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.activity_main)

    btn_click.setOnClickListener(mOnClickListener)

}

private fun findResources() {
    mAuthParam = AccountAuthParamsHelper(AccountAuthParams.DEFAULT_AUTH_REQUEST_PARAM)
        .setIdToken()
        .setAccessToken()
        .setProfile()
        .createParams()
   mAuthManager = AccountAuthManager.getService(this@MainActivity, mAuthParam)
   startActivityForResult(mAuthManager?.signInIntent, 1002)
    // Obtain Icon steps
    val task : Task&amp;lt;AccountIcon&amp;gt; = mAuthManager.channel
    task.addOnSuccessListener { accountIcon -&amp;gt;
        // Obtain icon information
        Toast.makeText(this, "Display Name: " + accountIcon.description, Toast.LENGTH_LONG).show()
        // Log.i("TAG", "displayName:" + accountIcon.description)
    }
    task.addOnFailureListener { e -&amp;gt;
        // The information fails to be obtained.
        if (e is ApiException) {
            Log.i("TAG", "getChannelfailed status:" + e.statusCode)
        }
    }

}

private val mOnClickListener: View.OnClickListener = object : View.OnClickListener {
    override fun onClick(v: View?) {
        when (v?.id) {
            R.id.btn_click -&amp;gt; findResources()
        }
    }
}

override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
    super.onActivityResult(requestCode, resultCode, data)
    if (requestCode == 1002 ) {
        val authAccountTask = AccountAuthManager.parseAuthResultFromIntent(data)
        if (authAccountTask.isSuccessful) {
            Toast.makeText(this, "SigIn success", Toast.LENGTH_LONG).show()
            val intent = Intent(this@MainActivity, Home::class.java)
            startActivity(intent)
        }
        else {
            Toast.makeText(this, "SignIn failed: " + (authAccountTask.exception as ApiException).statusCode, Toast.LENGTH_LONG).show()
        }
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;}`&lt;/p&gt;

&lt;p&gt;In the &lt;strong&gt;activity_main.xml&lt;/strong&gt; we can create the UI screen.&lt;br&gt;
`&amp;lt;?xml version="1.0" encoding="utf-8"?&amp;gt;&lt;br&gt;

    xmlns:app="http://schemas.android.com/apk/res-auto"&lt;br&gt;
    xmlns:tools="http://schemas.android.com/tools"&lt;br&gt;
    android:layout_width="match_parent"&lt;br&gt;
    android:layout_height="match_parent"&lt;br&gt;
    android:orientation="vertical"&lt;br&gt;
    tools:context=".MainActivity"&amp;gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;TextView
    android:id="@+id/main_title"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center_horizontal"
    android:layout_marginTop="20dp"
    android:text="Welcome back! Login"
    android:textSize="28sp"
    android:textColor="@color/design_default_color_primary"
    android:textStyle="bold" /&amp;gt;

&amp;lt;TextView
    android:id="@+id/txt_username"
    android:layout_width="300dp"
    android:layout_height="wrap_content"
    android:layout_gravity="center_horizontal"
    android:layout_marginTop="40dp"
    android:text=" Username"
    android:textColor="@color/black"
    android:textSize="16sp" /&amp;gt;
&amp;lt;EditText
    android:id="@+id/edt_main_name"
    android:layout_width="300dp"
    android:layout_height="wrap_content"
    android:layout_gravity="center_horizontal"
    android:layout_marginTop="5dp"
    android:hint=" Enter your username"
    android:drawableLeft="@drawable/ic_baseline_person"
    android:drawablePadding="3dp"
    android:drawableTint="@color/design_default_color_primary"
    android:textSize="17sp" /&amp;gt;

&amp;lt;TextView
    android:id="@+id/txt_password"
    android:layout_width="300dp"
    android:layout_height="wrap_content"
    android:layout_gravity="center_horizontal"
    android:layout_marginTop="20dp"
    android:text=" Password"
    android:textColor="@color/black"
    android:textSize="16sp" /&amp;gt;
&amp;lt;EditText
    android:id="@+id/main_password"
    android:layout_width="300dp"
    android:layout_height="wrap_content"
    android:layout_gravity="center_horizontal"
    android:layout_marginTop="5dp"
    android:hint=" Enter your password"
    android:drawableTint="@color/design_default_color_primary"
    android:drawableLeft="@android:drawable/ic_lock_idle_lock"
    android:textSize="17sp" /&amp;gt;
&amp;lt;TextView
    android:id="@+id/forgot_password"
    android:layout_width="300dp"
    android:layout_height="wrap_content"
    android:layout_gravity="end"
    android:layout_marginEnd="35dp"
    android:textAlignment="textEnd"
    android:layout_marginTop="10dp"
    android:textColor="@color/black"
    android:text=" Forgot password?"
    android:textSize="16sp" /&amp;gt;

&amp;lt;Button
    android:id="@+id/click_login"
    android:layout_width="300dp"
    android:layout_height="wrap_content"
    android:layout_gravity="center_horizontal"
    android:layout_marginTop="30dp"
    android:padding="5dp"
    android:textColor="@color/black"
    android:text="LOGIN" /&amp;gt;

&amp;lt;TextView
    android:id="@+id/txt_signin"
    android:layout_width="300dp"
    android:layout_height="wrap_content"
    android:layout_gravity="center_horizontal"
    android:layout_marginTop="40dp"
    android:textAlignment="center"
    android:layout_marginBottom="10dp"
    android:text=" Or SigIn Using"
    android:textColor="@color/black"
    android:drawablePadding="3dp"
    android:textSize="17sp" /&amp;gt;
&amp;lt;ImageView
    android:id="@+id/btn_click"
    android:layout_width="50dp"
    android:layout_height="60dp"
    android:layout_gravity="center_horizontal"
    app:srcCompat="@drawable/hwid_auth_button_normal" /&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;`&lt;/p&gt;

&lt;p&gt;Find the &lt;strong&gt;ic_baseline_person.xml&lt;/strong&gt; for UI design.&lt;br&gt;
&lt;code&gt;&amp;lt;vector xmlns:android="http://schemas.android.com/apk/res/android"&lt;br&gt;
    android:width="24dp"&lt;br&gt;
    android:height="24dp"&lt;br&gt;
    android:viewportWidth="24"&lt;br&gt;
    android:viewportHeight="24"&lt;br&gt;
    android:tint="?attr/colorControlNormal"&amp;gt;&lt;br&gt;
  &amp;lt;path&lt;br&gt;
      android:fillColor="@android:color/white"&lt;br&gt;
      android:pathData="M12,12c2.21,0 4,-1.79 4,-4s-1.79,-4 -4,-4 -4,1.79 -4,4 1.79,4 4,4zM12,14c-2.67,0 -8,1.34 -8,4v2h16v-2c0,-2.66 -5.33,-4 -8,-4z"/&amp;gt;&lt;br&gt;
&amp;lt;/vector&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Demo&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--hLoBrlw2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zn4ps2l90m67urfi810h.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--hLoBrlw2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zn4ps2l90m67urfi810h.jpg" alt="Image description" width="373" height="767"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--QkeQ5WXi--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xiclzks1mix6p6ixf8rx.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--QkeQ5WXi--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xiclzks1mix6p6ixf8rx.jpg" alt="Image description" width="374" height="768"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--9QAP1LSC--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jaueljt3mpmbphja08yn.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--9QAP1LSC--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jaueljt3mpmbphja08yn.jpg" alt="Image description" width="369" height="761"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tips and Tricks&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Make sure you are already registered as Huawei developer.&lt;/li&gt;
&lt;li&gt;Set minSDK version to &lt;strong&gt;24&lt;/strong&gt; or later, otherwise you will get &lt;strong&gt;AndriodManifest&lt;/strong&gt; merge issue.&lt;/li&gt;
&lt;li&gt;Make sure you have added the &lt;strong&gt;agconnect-services.json&lt;/strong&gt; file to app folder.&lt;/li&gt;
&lt;li&gt;Make sure you have added &lt;strong&gt;SHA-256 fingerprint&lt;/strong&gt; without fail.&lt;/li&gt;
&lt;li&gt;Make sure all the dependencies are added properly.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;br&gt;
In this article, we have learned how to integrate the &lt;strong&gt;Huawei Account Kit&lt;/strong&gt; of &lt;strong&gt;Obtaining Icon Resources&lt;/strong&gt; feature in Attendance Tracker app. So, I will provide the series of articles on this Attendance Tracker App, in upcoming articles will integrate other Huawei Kits.&lt;/p&gt;

&lt;p&gt;I hope you have read this article. If you found it is helpful, please provide likes and comments.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Reference&lt;/strong&gt;&lt;br&gt;
Account Kit – &lt;a href="https://developer.huawei.com/consumer/en/doc/development/HMSCore-Guides/get-channel-0000001074587201"&gt;Documentation&lt;/a&gt;&lt;br&gt;
Account Kit – &lt;a href="https://developer.huawei.com/consumer/en/training/course/video/101583015541549183"&gt;Training Video&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Integration of Text to Speech feature of Huawei ML Kit in Book Reading Android app (Kotlin) - Part 4</title>
      <dc:creator>MuraliAkula1</dc:creator>
      <pubDate>Mon, 21 Feb 2022 08:51:13 +0000</pubDate>
      <link>https://dev.to/muraliakula1/integration-of-text-to-speech-feature-of-huawei-ml-kit-in-book-reading-android-app-kotlin-part-4-4g91</link>
      <guid>https://dev.to/muraliakula1/integration-of-text-to-speech-feature-of-huawei-ml-kit-in-book-reading-android-app-kotlin-part-4-4g91</guid>
      <description>&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Nn5bBd5S--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/a6a3l0p89vvpsy63pkg6.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Nn5bBd5S--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/a6a3l0p89vvpsy63pkg6.jpg" alt="Image description" width="300" height="168"&gt;&lt;/a&gt;&lt;br&gt;
&lt;strong&gt;Introduction&lt;/strong&gt;&lt;br&gt;
In this article, we can learn how to integrate the &lt;strong&gt;Text to Speech&lt;/strong&gt; feature of &lt;strong&gt;Huawei ML Kit&lt;/strong&gt; in Book Reading app. Text to speech (TTS) can convert text information into human voice in real time. This service uses &lt;strong&gt;Deep Neural Networks&lt;/strong&gt; in order to process the text and create a natural sound, rich timbers are also supported to enhance the result. TTS is widely used in &lt;strong&gt;broadcasting, news, voice navigation&lt;/strong&gt;, and &lt;strong&gt;audio reading&lt;/strong&gt;. For example, TTS can convert a large amount of text into speech output and highlight the content that is being played to free users eyes, bringing interests to users. TTS records a voice segment based on navigation data, and then synthesizes the voice segment into navigation voice, so that navigation is more personalized.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Precautions&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The text in a single request can contain a maximum of &lt;strong&gt;500 characters&lt;/strong&gt; and is encoded using UTF-8.&lt;/li&gt;
&lt;li&gt;Currently, TTS in French, Spanish, German, Italian, Russian, Thai, Malay, and Polish is deployed only in China, Asia, Africa, Latin America, and Europe.&lt;/li&gt;
&lt;li&gt;TTS depends on on-cloud APIs. During commissioning and usage, ensure that the device can access the Internet.&lt;/li&gt;
&lt;li&gt;Default specifications of the real-time output audio data are as follows: &lt;strong&gt;MP3 mono&lt;/strong&gt;, &lt;strong&gt;16-bit&lt;/strong&gt; depth, and &lt;strong&gt;16 kHz&lt;/strong&gt; audio sampling rate.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Requirements&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Any operating system (MacOS, Linux and Windows).&lt;/li&gt;
&lt;li&gt;Must have a Huawei phone with HMS 4.0.0.300 or later.&lt;/li&gt;
&lt;li&gt;Must have a laptop or desktop with Android Studio, Jdk 1.8, SDK platform 26 and Gradle 4.6 and above installed.&lt;/li&gt;
&lt;li&gt;Minimum API Level 24 is required.&lt;/li&gt;
&lt;li&gt;Required EMUI 9.0.0 and later version devices.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;How to integrate HMS Dependencies&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;First register as Huawei developer and complete identity verification in Huawei developers website, refer to register a &lt;a href="https://developer.huawei.com/consumer/en/doc/start/registration-and-verification-0000001053628148"&gt;Huawei ID&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;Create a project in android studio, refer &lt;a href="https://developer.huawei.com/consumer/en/codelab/HMSPreparation/index.html#1"&gt;Creating an Android Studio Project.&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Generate a &lt;strong&gt;SHA-256 certificate fingerprint&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;To generate &lt;strong&gt;SHA-256 certificate fingerprint&lt;/strong&gt;. On right-upper corner of android project click &lt;strong&gt;Gradle&lt;/strong&gt;, choose &lt;strong&gt;Project Name &amp;gt; Tasks &amp;gt; android&lt;/strong&gt;, and then click &lt;strong&gt;signingReport&lt;/strong&gt;, as follows.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--DAlf10pc--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hjk07mvnf0a0hggdf9vq.JPG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--DAlf10pc--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hjk07mvnf0a0hggdf9vq.JPG" alt="Image description" width="880" height="516"&gt;&lt;/a&gt;&lt;br&gt;
Note: Project Name depends on the user created name.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://developer.huawei.com/consumer/en/codelab/HMSPreparation/index.html#0"&gt;Create an App in AppGallery Connect&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;Download the &lt;strong&gt;agconnect-services.json&lt;/strong&gt; file from &lt;strong&gt;App information&lt;/strong&gt;, copy and paste in android &lt;strong&gt;Project **under **app directory&lt;/strong&gt;, as follows.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--AmwB3VwH--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/q9c5q6zqpcxx16n3yaj2.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--AmwB3VwH--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/q9c5q6zqpcxx16n3yaj2.jpg" alt="Image description" width="464" height="616"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Enter &lt;strong&gt;SHA-256 certificate fingerprint&lt;/strong&gt; and click **Save **button, as follows.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--fMnfiogQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mzj78curk6ix6ijjq7ow.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--fMnfiogQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mzj78curk6ix6ijjq7ow.jpg" alt="Image description" width="880" height="298"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Click &lt;strong&gt;Manage APIs&lt;/strong&gt; tab and enable &lt;strong&gt;ML Kit&lt;/strong&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--IBkiZGBG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bzr39tcsgypososs3pj3.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--IBkiZGBG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bzr39tcsgypososs3pj3.jpg" alt="Image description" width="880" height="149"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Add the below maven URL in &lt;strong&gt;build.gradle(Project)&lt;/strong&gt; file under the repositories of b*&lt;em&gt;uildscript, dependencies&lt;/em&gt;* and &lt;strong&gt;allprojects&lt;/strong&gt;, refer &lt;a href="https://developer.huawei.com/consumer/en/codelab/HMSPreparation/index.html#6"&gt;Add Configuration&lt;/a&gt;.
&lt;code&gt;maven { url 'http://developer.huawei.com/repo/' }
classpath 'com.huawei.agconnect:agcp:1.6.0.300'
&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Add the below plugin and dependencies in &lt;strong&gt;build.gradle(Module)&lt;/strong&gt; file.
`apply plugin: id 'com.huawei.agconnect'&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;dataBinding {&lt;br&gt;
    enabled = true&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;// Huawei AGC&lt;br&gt;
implementation 'com.huawei.agconnect:agconnect-core:1.6.0.300'&lt;br&gt;
// ML Kit - Text to Speech&lt;br&gt;
implementation 'com.huawei.hms:ml-computer-voice-tts:3.3.0.305'&lt;br&gt;
// Data Binding&lt;br&gt;
implementation 'androidx.databinding:databinding-runtime:7.1.1'&lt;br&gt;
`&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Now Sync the gradle.&lt;/li&gt;
&lt;li&gt;Add the required permission to the &lt;strong&gt;AndroidManifest.xml&lt;/strong&gt; file.
&lt;code&gt;&amp;lt;uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /&amp;gt;
&amp;lt;uses-permission android:name="android.permission.INTERNET" /&amp;gt;&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Let us move to development&lt;/strong&gt;&lt;br&gt;
I have created a project on Android studio with empty activity let us start coding.&lt;br&gt;
In the &lt;strong&gt;ListActivity.kt&lt;/strong&gt; to find the button click.&lt;br&gt;
`class ListActivity : AppCompatActivity() {&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.activity_list)

    btn_voice.setOnClickListener {
        val intent = Intent(this@ListActivity, TranslateActivity::class.java)
        startActivity(intent)
    }

}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;}`&lt;/p&gt;

&lt;p&gt;In the &lt;strong&gt;TranslateActivity.kt&lt;/strong&gt; to find the business logic for text translation.&lt;br&gt;
`class TranslateActivity : AppCompatActivity() {&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;private lateinit var binding: ActivityTranslateBinding
private lateinit var ttsViewModel: TtsViewModel
private var sourceText: String = ""
private lateinit var mlTtsEngine: MLTtsEngine
private lateinit var mlConfigs: MLTtsConfig
private val TAG: String = TranslateActivity::class.java.simpleName
private var callback: MLTtsCallback = object : MLTtsCallback {
    override fun onError(taskId: String, err: MLTtsError) {
    }
    override fun onWarn(taskId: String, warn: MLTtsWarn) {
    }
    override fun onRangeStart(taskId: String, start: Int, end: Int) {
        Log.d("", start.toString())
        img_view.setImageResource(R.drawable.on)
    }
    override fun onAudioAvailable(p0: String?, p1: MLTtsAudioFragment?, p2: Int, p3: android.util.Pair&amp;lt;Int, Int&amp;gt;?, p4: Bundle?) {
    }
    override fun onEvent(taskId: String, eventName: Int, bundle: Bundle?) {
        if (eventName == MLTtsConstants.EVENT_PLAY_STOP) {
            Toast.makeText(applicationContext, "Service Stopped", Toast.LENGTH_LONG).show()
        }
        img_view.setImageResource(R.drawable.off)
    }
}

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContentView(activity_translate)

    binding = setContentView(this, activity_translate)
    binding.lifecycleOwner = this
    ttsViewModel = ViewModelProvider(this).get(TtsViewModel::class.java)
    binding.ttsViewModel = ttsViewModel
    setApiKey()
    supportActionBar?.title = "Text to Speech Conversion"
    ttsViewModel.ttsService.observe(this, Observer {
        startTtsService()
    })
    ttsViewModel.textData.observe(this, Observer {
        sourceText = it
    })

}

private fun startTtsService() {
    mlConfigs = MLTtsConfig()
        .setLanguage(MLTtsConstants.TTS_EN_US)
        .setPerson(MLTtsConstants.TTS_SPEAKER_FEMALE_EN)
        .setSpeed(1.0f)
        .setVolume(1.0f)
    mlTtsEngine = MLTtsEngine(mlConfigs)
    mlTtsEngine.setTtsCallback(callback)
    // ID to use for Audio Visualizer.
    val id = mlTtsEngine.speak(sourceText, MLTtsEngine.QUEUE_APPEND)
    Log.i(TAG, id)
}

private fun setApiKey(){
    MLApplication.getInstance().apiKey = "DAEDAOB+zyB7ajg1LGcp8F65qxZduDjQ1E6tVovUp4lU/PywqhT4g+bxBCtStYAa33V9tUQrKvUp89m+0Gi/fPwfNN6WCJxcVLA+WA=="
}

override fun onDestroy() {
    super.onDestroy()
    mlTtsEngine.shutdown()
}
override fun onPause() {
    super.onPause()
    mlTtsEngine.stop()
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;}`&lt;/p&gt;

&lt;p&gt;In the &lt;strong&gt;activity_list.xml&lt;/strong&gt; we can create the UI screen.&lt;br&gt;
`&amp;lt;?xml version="1.0" encoding="utf-8"?&amp;gt;&lt;br&gt;

    xmlns:app="http://schemas.android.com/apk/res-auto"&lt;br&gt;
    xmlns:tools="http://schemas.android.com/tools"&lt;br&gt;
    android:layout_width="match_parent"&lt;br&gt;
    android:layout_height="match_parent"&lt;br&gt;
    android:orientation="vertical"&lt;br&gt;
    android:paddingTop="10dp"&lt;br&gt;
    android:paddingBottom="10dp"&lt;br&gt;
    tools:context=".ListActivity"&amp;gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    android:id="@+id/btn_voice"
    android:layout_width="310dp"
    android:layout_height="wrap_content"
    android:layout_marginTop="50dp"
    android:textAlignment="center"
    android:layout_gravity="center_horizontal"
    android:textSize="20sp"
    android:textColor="@color/black"
    android:padding="8dp"
    android:textAllCaps="false"
    android:text="Text to Voice" /&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;`&lt;/p&gt;

&lt;p&gt;In the &lt;strong&gt;activity_translate.xml&lt;/strong&gt; we can create the UI screen.&lt;br&gt;
`&amp;lt;?xml version="1.0" encoding="utf-8"?&amp;gt;&lt;br&gt;

    xmlns:app="http://schemas.android.com/apk/res-auto"&lt;br&gt;
    xmlns:tools="http://schemas.android.com/tools"&amp;gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;data&amp;gt;
    &amp;lt;variable
        name="ttsViewModel"
        type="com.example.huaweibookreaderapp1.TtsViewModel" /&amp;gt;
&amp;lt;/data&amp;gt;

&amp;lt;androidx.constraintlayout.widget.ConstraintLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/white"
    tools:context=".TranslateActivity"&amp;gt;

    &amp;lt;Button
        android:id="@+id/btn_click"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:onClick="@{() -&amp;gt; ttsViewModel.callTtsService()}"
        android:text="@string/speak"
        android:textSize="20sp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.498"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.43" /&amp;gt;
    &amp;lt;EditText
        android:id="@+id/edt_text"
        android:layout_width="409dp"
        android:layout_height="wrap_content"
        android:layout_marginBottom="36dp"
        android:ems="10"
        android:textSize="20sp"
        android:hint="@string/enter_text_here"
        android:inputType="textPersonName"
        android:onTextChanged="@{ttsViewModel.noDataChangedText}"
        android:paddingStart="70dp"
        app:layout_constraintBottom_toTopOf="@+id/btn_click"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="1.0"
        app:layout_constraintStart_toStartOf="parent"
        android:autofillHints="@string/enter_text_here" /&amp;gt;
    &amp;lt;ImageView
        android:id="@+id/img_view"
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:layout_marginTop="7dp"
        app:layout_constraintBottom_toTopOf="@+id/edt_text"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.498"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.8"
        app:srcCompat="@drawable/off"
        android:contentDescription="@string/speaker" /&amp;gt;
&amp;lt;/androidx.constraintlayout.widget.ConstraintLayout&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;`&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Demo&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--qu1S762c--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yk1htom084vpoz1ljvpr.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--qu1S762c--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yk1htom084vpoz1ljvpr.jpg" alt="Image description" width="355" height="716"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--L71egoq0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3ekc8kf88n05ev4tkipi.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--L71egoq0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3ekc8kf88n05ev4tkipi.jpg" alt="Image description" width="380" height="767"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--BiTFKl0D--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jj1aeont6btocfmcvqxr.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--BiTFKl0D--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jj1aeont6btocfmcvqxr.jpg" alt="Image description" width="376" height="768"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--IGe4OYpJ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5tioze860sxcl2sy6v1r.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--IGe4OYpJ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5tioze860sxcl2sy6v1r.jpg" alt="Image description" width="378" height="770"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tips and Tricks&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Make sure you are already registered as Huawei developer.&lt;/li&gt;
&lt;li&gt;Set minSDK version to &lt;strong&gt;24&lt;/strong&gt; or later, otherwise you will get &lt;strong&gt;AndriodManifest&lt;/strong&gt; merge issue.&lt;/li&gt;
&lt;li&gt;Make sure you have added the &lt;strong&gt;agconnect-services.json&lt;/strong&gt; file to app folder.&lt;/li&gt;
&lt;li&gt;Make sure you have added &lt;strong&gt;SHA-256 fingerprint&lt;/strong&gt; without fail.&lt;/li&gt;
&lt;li&gt;Make sure all the dependencies are added properly.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;br&gt;
In this article, we have learned how to integrate the &lt;strong&gt;Text to Speech&lt;/strong&gt; feature of &lt;strong&gt;Huawei ML Kit&lt;/strong&gt; in Book Reading app. Text to speech (TTS) can convert text information into human voice in real time. This service uses &lt;strong&gt;Deep Neural Networks&lt;/strong&gt; in order to process the text and create a natural sound, rich timbers are also supported to enhance the result.&lt;/p&gt;

&lt;p&gt;I hope you have read this article. If you found it is helpful, please provide likes and comments.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Reference&lt;/strong&gt;&lt;br&gt;
ML Kit – &lt;a href="https://developer.huawei.com/consumer/en/doc/development/hiai-Guides/ml-tts-0000001050068169"&gt;Text to Speech&lt;/a&gt;&lt;br&gt;
ML Kit – &lt;a href="https://developer.huawei.com/consumer/en/training/course/video/101582989856737152"&gt;Training Video&lt;/a&gt;&lt;/p&gt;

</description>
      <category>kotlin</category>
      <category>hmscore</category>
      <category>android</category>
      <category>mlkit</category>
    </item>
    <item>
      <title>Integration of Huawei Push Kit in Book Reading Android app (Kotlin) - Part 3</title>
      <dc:creator>MuraliAkula1</dc:creator>
      <pubDate>Mon, 14 Feb 2022 10:54:43 +0000</pubDate>
      <link>https://dev.to/muraliakula1/integration-of-huawei-push-kit-in-book-reading-android-app-kotlin-part-3-202g</link>
      <guid>https://dev.to/muraliakula1/integration-of-huawei-push-kit-in-book-reading-android-app-kotlin-part-3-202g</guid>
      <description>&lt;p&gt;&lt;strong&gt;Introduction&lt;/strong&gt;&lt;br&gt;
In this article, we can learn how to integrate the &lt;strong&gt;Huawei Push Kit&lt;/strong&gt; in Book Reading app to send the push message notification to users phone from the &lt;strong&gt;AppGallery Connect&lt;/strong&gt;. Push notifications offers a great way to increase your application’s user engagement and boost your retention rates by sending meaningful messages or by informing users about your application. These messages can be sent at any time and even if your app is not running at that time. So, I will provide the series of articles on this Book Reading App, in upcoming articles I will integrate other Huawei Kits.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Push Kit&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;Huawei Push Kit&lt;/strong&gt; is a messaging service developed by Huawei for developers to send messages to apps on users’ device in real time. Push Kit supports two types of messages: &lt;strong&gt;notification messages&lt;/strong&gt; and &lt;strong&gt;data messages&lt;/strong&gt;. You can send notifications and data messages to your users from your server using the &lt;a href="https://developer.huawei.com/consumer/en/doc/development/HMS-3-References/push-server-send"&gt;Push Kit APIs&lt;/a&gt; or directly from the &lt;a href="https://developer.huawei.com/consumer/en/doc/development/HMS-Guides/push-console"&gt;AppGallery Push Kit Console&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;AppGallery Connect&lt;/strong&gt;&lt;br&gt;
Find the &lt;strong&gt;Push Kit&lt;/strong&gt; message service in AppGallery connect dashboard.&lt;br&gt;
Choose &lt;strong&gt;My Projects &amp;gt; Grow &amp;gt; Push Kit&lt;/strong&gt;, and click &lt;strong&gt;Enable now&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--OcWgwiN3--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cn9y62qxgqox508ln2v2.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--OcWgwiN3--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cn9y62qxgqox508ln2v2.jpg" alt="Image description" width="880" height="360"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Follow the steps to send the notification message to device from AppGallery Connect, &lt;a href="https://developer.huawei.com/consumer/en/doc/development/HMSCore-Guides/msg-sending-android-0000001136294192"&gt;Sending a Notification Message&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Requirements&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Any operating system (MacOS, Linux and Windows).&lt;/li&gt;
&lt;li&gt;Must have a Huawei phone with HMS 4.0.0.300 or later.&lt;/li&gt;
&lt;li&gt;Must have a laptop or desktop with Android Studio, Jdk 1.8, SDK platform 26 and Gradle 4.6 and above installed.&lt;/li&gt;
&lt;li&gt;Minimum API Level 24 is required.&lt;/li&gt;
&lt;li&gt;Required EMUI 9.0.0 and later version devices.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;How to integrate HMS Dependencies&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;First register as Huawei developer and complete identity verification in Huawei developers website, refer to register a &lt;a href="https://developer.huawei.com/consumer/en/doc/start/registration-and-verification-0000001053628148"&gt;Huawei ID&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;Create a project in android studio, refer &lt;a href="https://developer.huawei.com/consumer/en/codelab/HMSPreparation/index.html#1"&gt;Creating an Android Studio Project&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;Generate a &lt;strong&gt;SHA-256 certificate fingerprint&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;To generate &lt;strong&gt;SHA-256 certificate fingerprint&lt;/strong&gt;. On right-upper corner of android project click &lt;strong&gt;Gradle&lt;/strong&gt;, choose &lt;strong&gt;Project Name &amp;gt; Tasks &amp;gt; android&lt;/strong&gt;, and then click &lt;strong&gt;signingReport&lt;/strong&gt;, as follows.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--rYsXmR4s--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wlthkjyfulhjyiopvh3s.JPG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--rYsXmR4s--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wlthkjyfulhjyiopvh3s.JPG" alt="Image description" width="880" height="516"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Note: Project Name depends on the user created name.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://developer.huawei.com/consumer/en/codelab/HMSPreparation/index.html#0"&gt;Create an App in AppGallery Connect&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;Download the &lt;strong&gt;agconnect-services.json&lt;/strong&gt; file from &lt;strong&gt;App information&lt;/strong&gt;, copy and paste in android **Project **under **app **directory, as follows.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--dETJvpXi--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qr9lonqmkywtplhexuo6.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--dETJvpXi--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qr9lonqmkywtplhexuo6.jpg" alt="Image description" width="464" height="616"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Enter &lt;strong&gt;SHA-256 certificate fingerprint&lt;/strong&gt; and click **Save **button, as follows.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--zj42SD6J--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4a8u31q19frl4v4zzj4f.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--zj42SD6J--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4a8u31q19frl4v4zzj4f.jpg" alt="Image description" width="880" height="298"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Click &lt;strong&gt;Manage APIs&lt;/strong&gt; tab and enable &lt;strong&gt;Push Kit&lt;/strong&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Gw_vLuST--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2aafcs7xlu3iy7066xek.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Gw_vLuST--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2aafcs7xlu3iy7066xek.jpg" alt="Image description" width="880" height="149"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Add the below maven URL in &lt;strong&gt;build.gradle(Project)&lt;/strong&gt; file under the repositories of &lt;strong&gt;buildscript, dependencies&lt;/strong&gt; and &lt;strong&gt;allprojects&lt;/strong&gt;, refer &lt;a href="https://developer.huawei.com/consumer/en/codelab/HMSPreparation/index.html#6"&gt;Add Configuration&lt;/a&gt;.
&lt;code&gt;maven { url 'http://developer.huawei.com/repo/' }
classpath 'com.huawei.agconnect:agcp:1.6.0.300'
&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Add the below plugin and dependencies in &lt;strong&gt;build.gradle(Module)&lt;/strong&gt; file.
&lt;code&gt;apply plugin: id 'com.huawei.agconnect'
// Huawei AGC
implementation 'com.huawei.agconnect:agconnect-core:1.6.0.300'
// Huawei Push Kit
implementation 'com.huawei.hms:push:6.3.0.302'
// PDF Viewer
implementation 'com.github.barteksc:android-pdf-viewer:2.8.2'&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Now Sync the gradle.&lt;/li&gt;
&lt;li&gt;Add the required permission to the &lt;strong&gt;AndroidManifest.xm&lt;/strong&gt;l file.
&lt;code&gt;// Push Kit
&amp;lt;uses-permission android:name="android.permission.INTERNET" /&amp;gt;
&amp;lt;service
android:name=".PushService"
android:exported="false"&amp;gt;
&amp;lt;intent-filter&amp;gt;
    &amp;lt;action android:name="com.huawei.push.action.MESSAGING_EVENT" /&amp;gt;
&amp;lt;/intent-filter&amp;gt;
&amp;lt;/service&amp;gt;&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Let us move to development&lt;/strong&gt;&lt;br&gt;
I have created a project on Android studio with empty activity let us start coding.&lt;br&gt;
In the &lt;strong&gt;WebViewActivity.kt&lt;/strong&gt; to find the web view of pdf document.&lt;br&gt;
`class WebViewActivity : AppCompatActivity() {&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.activity_web_view)

    webView.webViewClient = WebViewClient()
    webView.settings.setSupportZoom(true)
    webView.settings.javaScriptEnabled = true
     val url = getPdfUrl()        webView.loadUrl("https://docs.google.com/gview?embedded=true&amp;amp;url=$url")

}

companion object{
    fun getPdfUrl(): String {
        return "https://mindorks.s3.ap-south-1.amazonaws.com/courses/MindOrks_Android_Online_Professional_Course-Syllabus.pdf"
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;}&lt;code&gt;&lt;br&gt;
Create **PushService.kt** class to send the push notification to device.&lt;br&gt;
&lt;/code&gt;class PushService : HmsMessageService() {&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; // When an app calls the getToken method to apply for a token from the server,
 // if the server does not return the token during current method calling, the server can return the token through this method later.
 // This method callback must be completed in 10 seconds. Otherwise, you need to start a new Job for callback processing.
 // @param token token
override fun onNewToken(token: String?) {
    Log.i(TAG, "received refresh token:$token")
    // send the token to your app server.
    if (!token.isNullOrEmpty()) {
        // This method callback must be completed in 10 seconds. Otherwise, you need to start a new Job for callback processing.
        refreshedTokenToServer(token)
    }
    val intent = Intent()
    intent.action = CODELABS_ACTION
    intent.putExtra("method", "onNewToken")
    intent.putExtra("msg", "onNewToken called, token: $token")
    sendBroadcast(intent)
}

private fun refreshedTokenToServer(token: String) {
    Log.i(TAG, "sending token to server. token:$token")
}

 // This method is used to receive downstream data messages.
 // This method callback must be completed in 10 seconds. Otherwise, you need to start a new Job for callback processing.
 // @param message RemoteMessage
override fun onMessageReceived(message: RemoteMessage?) {
    Log.i(TAG, "onMessageReceived is called")
    if (message == null) {
        Log.e(TAG, "Received message entity is null!")
        return
    }
    // getCollapseKey() Obtains the classification identifier (collapse key) of a message.
    // getData() Obtains valid content data of a message.
    // getMessageId() Obtains the ID of a message.
    // getMessageType() Obtains the type of a message.
    // getNotification() Obtains the notification data instance from a message.
    // getOriginalUrgency() Obtains the original priority of a message.
    // getSentTime() Obtains the time when a message is sent from the server.
    // getTo() Obtains the recipient of a message.
    Log.i(TAG, """getCollapseKey: ${message.collapseKey}
        getData: ${message.data}
        getFrom: ${message.from}
        getTo: ${message.to}
        getMessageId: ${message.messageId}
        getMessageType: ${message.messageType}
        getSendTime: ${message.sentTime}
        getTtl: ${message.ttl}
        getSendMode: ${message.sendMode}
        getReceiptMode: ${message.receiptMode}
        getOriginalUrgency: ${message.originalUrgency}
        getUrgency: ${message.urgency}
        getToken: ${message.token}""".trimIndent())
    // getBody() Obtains the displayed content of a message
    // getTitle() Obtains the title of a message
    // getTitleLocalizationKey() Obtains the key of the displayed title of a notification message
    // getTitleLocalizationArgs() Obtains variable parameters of the displayed title of a message
    // getBodyLocalizationKey() Obtains the key of the displayed content of a message
    // getBodyLocalizationArgs() Obtains variable parameters of the displayed content of a message
    // getIcon() Obtains icons from a message
    // getSound() Obtains the sound from a message
    // getTag() Obtains the tag from a message for message overwriting
    // getColor() Obtains the colors of icons in a message
    // getClickAction() Obtains actions triggered by message tapping
    // getChannelId() Obtains IDs of channels that support the display of messages
    // getImageUrl() Obtains the image URL from a message
    // getLink() Obtains the URL to be accessed from a message
    // getNotifyId() Obtains the unique ID of a message
    val notification = message.notification
    if (notification != null) {
        Log.i(TAG, """
            getTitle: ${notification.title}
            getTitleLocalizationKey: ${notification.titleLocalizationKey}
            getTitleLocalizationArgs: ${Arrays.toString(notification.titleLocalizationArgs)}
            getBody: ${notification.body}
            getBodyLocalizationKey: ${notification.bodyLocalizationKey}
            getBodyLocalizationArgs: ${Arrays.toString(notification.bodyLocalizationArgs)}
            getIcon: ${notification.icon}                
            getImageUrl: ${notification.imageUrl}
            getSound: ${notification.sound}
            getTag: ${notification.tag}
            getColor: ${notification.color}
            getClickAction: ${notification.clickAction}
            getIntentUri: ${notification.intentUri}
            getChannelId: ${notification.channelId}
            getLink: ${notification.link}
            getNotifyId: ${notification.notifyId}
            isDefaultLight: ${notification.isDefaultLight}
            isDefaultSound: ${notification.isDefaultSound}
            isDefaultVibrate: ${notification.isDefaultVibrate}
            getWhen: ${notification.`when`}
            getLightSettings: ${Arrays.toString(notification.lightSettings)}
            isLocalOnly: ${notification.isLocalOnly}
            getBadgeNumber: ${notification.badgeNumber}
            isAutoCancel: ${notification.isAutoCancel}
            getImportance: ${notification.importance}
            getTicker: ${notification.ticker}
            getVibrateConfig: ${notification.vibrateConfig}
            getVisibility: ${notification.visibility}""".trimIndent())
        showNotification(notification.title,notification.body)
    }
    val intent = Intent()
    intent.action = CODELABS_ACTION
    intent.putExtra("method", "onMessageReceived")
    intent.putExtra("msg", "onMessageReceived called, message id:" + message.messageId + ", payload data:" + message.data)
    sendBroadcast(intent)
    val judgeWhetherIn10s = false
    // If the messages are not processed in 10 seconds, the app needs to use WorkManager for processing.
    if (judgeWhetherIn10s) {
        startWorkManagerJob(message)
    } else {
        // Process message within 10s
        processWithin10s(message)
    }
}

private fun showNotification(title: String?, body: String?) {
    val intent = Intent(this, WebViewActivity::class.java)
    intent.putExtra("URL", "Provide link here")
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
    val pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_ONE_SHOT)
    val soundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)
    val notificationBuilder = NotificationCompat.Builder(this)
        .setSmallIcon(R.drawable.sym_def_app_icon)
        .setContentTitle(title)
        .setContentText(body)
        .setAutoCancel(true)
        .setSound(soundUri)
        .setContentIntent(pendingIntent)
    val notificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
    notificationManager.notify(0, notificationBuilder.build())
}

private fun startWorkManagerJob(message: RemoteMessage?) {
    Log.d(TAG, "Start new Job processing.")
}

private fun processWithin10s(message: RemoteMessage?) {
    Log.d(TAG, "Processing now.")
}

override fun onMessageSent(msgId: String?) {
    Log.i(TAG, "onMessageSent called, Message id:$msgId")
    val intent = Intent()
    intent.action = CODELABS_ACTION
    intent.putExtra("method", "onMessageSent")
    intent.putExtra("msg", "onMessageSent called, Message id:$msgId")
    sendBroadcast(intent)
}

override fun onSendError(msgId: String?, exception: Exception?) {
    Log.i(TAG, "onSendError called, message id:$msgId, ErrCode:${(exception as SendException).errorCode}, " +
          "description:${exception.message}")
    val intent = Intent()
    intent.action = CODELABS_ACTION
    intent.putExtra("method", "onSendError")
    intent.putExtra("msg", "onSendError called, message id:$msgId, ErrCode:${exception.errorCode}, " +
                    "description:${exception.message}")
    sendBroadcast(intent)
}

override fun onTokenError(e: Exception) {
    super.onTokenError(e)
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;private fun getToken() {&lt;br&gt;
    showLog("getToken:begin")&lt;br&gt;
    object : Thread() {&lt;br&gt;
        override fun run() {&lt;br&gt;
            try {&lt;br&gt;
                // read from agconnect-services.json&lt;br&gt;
                val appId = "Your app id"&lt;br&gt;
                val token = HmsInstanceId.getInstance(this@MainActivity).getToken(appId, "HCM")&lt;br&gt;
                Log.i(TAG, "get token:$token")&lt;br&gt;
                if (!TextUtils.isEmpty(token)) {&lt;br&gt;
                    sendRegTokenToServer(token)&lt;br&gt;
                }&lt;br&gt;
                showLog("get token:$token")&lt;br&gt;
            } catch (e: ApiException) {&lt;br&gt;
                Log.e(TAG, "get token failed, $e")&lt;br&gt;
                showLog("get token failed, $e")&lt;br&gt;
            }&lt;br&gt;
        }&lt;br&gt;
    }.start()&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;fun showLog(log: String?) {&lt;br&gt;
    runOnUiThread {&lt;br&gt;
        val tvView = findViewById(R.id.tv_log)&lt;br&gt;
        val svView = findViewById(R.id.sv_log)&lt;br&gt;
        if (tvView is TextView) {&lt;br&gt;
            tvView.text = log&lt;br&gt;
        }&lt;br&gt;
        if (svView is ScrollView) {&lt;br&gt;
            svView.fullScroll(View.FOCUS_DOWN)&lt;br&gt;
        }&lt;br&gt;
    }&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;private fun sendRegTokenToServer(token: String?) {&lt;br&gt;
    Log.i(TAG, "sending token to server. token:$token")&lt;br&gt;
}&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;companion object {
    private const val TAG: String = "PushDemoLog"
    private const val CODELABS_ACTION: String = "com.huawei.codelabpush.action"
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;}&lt;code&gt;&lt;br&gt;
In the **activity_web_view.xml** we can create the UI screen.&lt;br&gt;
&lt;/code&gt;&amp;lt;?xml version="1.0" encoding="utf-8"?&amp;gt;&lt;br&gt;

    xmlns:app="http://schemas.android.com/apk/res-auto"&lt;br&gt;
    xmlns:tools="http://schemas.android.com/tools"&lt;br&gt;
    android:layout_width="match_parent"&lt;br&gt;
    android:layout_height="match_parent"&lt;br&gt;
    tools:context=".WebViewActivity"&amp;gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;WebView
    android:id="@+id/webView"
    android:layout_width="match_parent"
    android:layout_height="match_parent" /&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;code&gt;&lt;br&gt;
In the **log_layout.xml** we can create the UI screen.&lt;br&gt;
&lt;/code&gt;&amp;lt;?xml version="1.0" encoding="utf-8"?&amp;gt;&lt;br&gt;

    android:overScrollMode="never"&lt;br&gt;
    android:layout_width="match_parent"&lt;br&gt;
    android:layout_height="match_parent"&lt;br&gt;
    xmlns:android="http://schemas.android.com/apk/res/android"&amp;gt;&lt;br&gt;
    
        android:id="@+id/tv_log"&lt;br&gt;
        android:layout_width="match_parent"&lt;br&gt;
        android:layout_height="wrap_content" /&amp;gt;&lt;br&gt;
`&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Demo&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--tjjmMrDk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yphwuh0x66qu3ydr5t7m.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--tjjmMrDk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yphwuh0x66qu3ydr5t7m.jpg" alt="Image description" width="355" height="716"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--PTItwrtm--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/y6ilyyyxgx1dio3xx00j.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--PTItwrtm--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/y6ilyyyxgx1dio3xx00j.jpg" alt="Image description" width="720" height="1440"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--nbEWi3kg--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7tsm2tz1exiouhqxp1je.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--nbEWi3kg--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7tsm2tz1exiouhqxp1je.jpg" alt="Image description" width="355" height="767"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--13hB9zCu--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5dkjbm6cwli1jgdtxv3i.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--13hB9zCu--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5dkjbm6cwli1jgdtxv3i.jpg" alt="Image description" width="353" height="766"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s---6aDCPQC--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ydg8evbncymavve2m1zy.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s---6aDCPQC--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ydg8evbncymavve2m1zy.jpg" alt="Image description" width="354" height="766"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--dT3ikHel--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/c2dm963grj0a90uzhxog.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--dT3ikHel--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/c2dm963grj0a90uzhxog.jpg" alt="Image description" width="355" height="768"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tips and Tricks&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Make sure you are already registered as Huawei developer.&lt;/li&gt;
&lt;li&gt;Set minSDK version to 24 or later, otherwise you will get AndriodManifest merge issue.&lt;/li&gt;
&lt;li&gt;Make sure you have added the &lt;strong&gt;agconnect-services.json&lt;/strong&gt; file to app folder.&lt;/li&gt;
&lt;li&gt;Make sure you have added SHA-256 fingerprint without fail.&lt;/li&gt;
&lt;li&gt;Make sure all the dependencies are added properly.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;br&gt;
In this article, we have learned how to integrate the Huawei Push Kit in Book Reading app to send the push message notification to users’ phone from the AppGallery Connect. Push notifications offers a great way to increase your application’s user engagement and boost your retention rates by sending meaningful messages or by informing users about your application. These messages can be sent at any time and even if your app is not running at that time.&lt;/p&gt;

&lt;p&gt;I hope you have read this article. If you found it is helpful, please provide likes and comments.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Reference&lt;/strong&gt;&lt;br&gt;
Push Kit – &lt;a href="https://developer.huawei.com/consumer/en/doc/development/HMSCore-Guides/service-introduction-0000001050040060"&gt;Document&lt;/a&gt;&lt;br&gt;
Push Kit – &lt;a href="https://developer.huawei.com/consumer/en/training/course/video/101583005582480166"&gt;Training Video&lt;/a&gt;&lt;/p&gt;

</description>
      <category>kotlin</category>
      <category>huawei</category>
      <category>pushkit</category>
      <category>android</category>
    </item>
    <item>
      <title>Integration of Huawei Analytics Kit and Ads Kit in Book Reading Android app (Kotlin) - Part 2</title>
      <dc:creator>MuraliAkula1</dc:creator>
      <pubDate>Tue, 08 Feb 2022 07:27:39 +0000</pubDate>
      <link>https://dev.to/muraliakula1/integration-of-huawei-analytics-kit-and-ads-kit-in-book-reading-android-app-kotlin-part-2-1d75</link>
      <guid>https://dev.to/muraliakula1/integration-of-huawei-analytics-kit-and-ads-kit-in-book-reading-android-app-kotlin-part-2-1d75</guid>
      <description>&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ay6g0X0I--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nmlzzo5kii1bn8vddxwr.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ay6g0X0I--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nmlzzo5kii1bn8vddxwr.jpg" alt="Image description" width="880" height="426"&gt;&lt;/a&gt;&lt;br&gt;
&lt;strong&gt;Introduction&lt;/strong&gt;&lt;br&gt;
In this article, we can learn how to integrate the Huawei &lt;strong&gt;Analytics Kit&lt;/strong&gt; and &lt;strong&gt;Ads Kit&lt;/strong&gt; in Book Reading app. So, I will provide the series of articles on this Book Reading App, in upcoming articles I will integrate other Huawei Kits.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Analytics Kit&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;HUAWEI Analytics Kit&lt;/strong&gt; provides analysis models to understand user behaviour and gain in-depth insights into &lt;strong&gt;users&lt;/strong&gt;, &lt;strong&gt;products **and **content&lt;/strong&gt;. It helps you to gain insight about user behaviour on different platforms based on the &lt;strong&gt;user behaviour events&lt;/strong&gt; and &lt;strong&gt;user attributes&lt;/strong&gt; reported by through apps.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;AppGallery Connect&lt;/strong&gt;&lt;br&gt;
Find the Analytics using AppGallery connect dashboard.&lt;br&gt;
Choose &lt;strong&gt;My Projects &amp;gt; Huawei Analytics &amp;gt; Overview &amp;gt; Project overview&lt;/strong&gt;.&lt;br&gt;
Project overview displays the core indicators of current project, such as the number of &lt;strong&gt;new users, User activity, User acquisition, User revisit, New user retention, Active user retention, User characteristics&lt;/strong&gt; and &lt;strong&gt;Popular pages&lt;/strong&gt; etc. providing a quick overview of the users and how they are using your app.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--EwVPiTzV--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jud3i89qh5onpvo6igig.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--EwVPiTzV--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jud3i89qh5onpvo6igig.jpg" alt="Image description" width="880" height="413"&gt;&lt;/a&gt;&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Ik2IZPFi--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hyk6rm4orx9arns6apbm.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Ik2IZPFi--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hyk6rm4orx9arns6apbm.jpg" alt="Image description" width="880" height="401"&gt;&lt;/a&gt;&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--h5L1XqMs--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/joewnalbwt339r2x0yvl.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--h5L1XqMs--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/joewnalbwt339r2x0yvl.jpg" alt="Image description" width="880" height="321"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Ads Kit&lt;/strong&gt;&lt;br&gt;
Huawei Ads provides to developers a wide-ranging capabilities to deliver good quality ads content to users. This is the best way to reach target audience easily and can measure user productivity. It is very useful when we publish a free app and want to earn some money from it.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;HMS Ads Kit&lt;/strong&gt; has &lt;strong&gt;7&lt;/strong&gt; types of Ads kits. Now we can implement &lt;strong&gt;Interstitial Ads&lt;/strong&gt; in this application.&lt;/p&gt;

&lt;p&gt;Interstitial ads are full-screen ads that cover the interface of an app. Such an ad is displayed when a user &lt;strong&gt;starts&lt;/strong&gt;, &lt;strong&gt;pauses **or **exits&lt;/strong&gt; an app, without disrupting the user's experience.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Requirements&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Any operating system (MacOS, Linux and Windows).&lt;/li&gt;
&lt;li&gt;Must have a Huawei phone with HMS 4.0.0.300 or later.&lt;/li&gt;
&lt;li&gt;Must have a laptop or desktop with Android Studio, Jdk 1.8, SDK platform 26 and Gradle 4.6 and above installed.&lt;/li&gt;
&lt;li&gt;Minimum API Level 24 is required.&lt;/li&gt;
&lt;li&gt;Required EMUI 9.0.0 and later version devices.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;How to integrate HMS Dependencies&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;First register as Huawei developer and complete identity verification in Huawei developers website, refer to register a &lt;a href="https://developer.huawei.com/consumer/en/doc/start/registration-and-verification-0000001053628148"&gt;Huawei ID&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;Create a project in android studio, refer &lt;a href="https://developer.huawei.com/consumer/en/codelab/HMSPreparation/index.html#1"&gt;Creating an Android Studio Project&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;Generate a &lt;strong&gt;SHA-256 certificate fingerprint&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;To generate &lt;strong&gt;SHA-256 certificate fingerprint&lt;/strong&gt;. On right-upper corner of android project click &lt;strong&gt;Gradle&lt;/strong&gt;, choose &lt;strong&gt;Project Name &amp;gt; Tasks &amp;gt; android&lt;/strong&gt;, and then click &lt;strong&gt;signing
Report&lt;/strong&gt;, as follows.
&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Ll3i2XR9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pyddaarsxwcywnejrbh3.png" alt="Image description" width="880" height="516"&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://developer.huawei.com/consumer/en/codelab/HMSPreparation/index.html#0"&gt;Create an App in AppGallery Connect&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;Download the &lt;strong&gt;agconnect-services.json&lt;/strong&gt; file from &lt;strong&gt;App information&lt;/strong&gt;, copy and paste in android **Project **under **app **directory, as follows.
&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--MUeuDweR--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cjjemtvdw089q5xdob2k.png" alt="Image description" width="464" height="616"&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Enter &lt;strong&gt;SHA-256 certificate fingerprint&lt;/strong&gt; and click **Save **button, as follows.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--dhrr_rDS--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vnmbjp3fl4fholi6ylfc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--dhrr_rDS--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vnmbjp3fl4fholi6ylfc.png" alt="Image description" width="880" height="298"&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Click &lt;strong&gt;Manage APIs&lt;/strong&gt; tab and enable &lt;strong&gt;HUAWEI Analytics&lt;/strong&gt;.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--zdR0xIam--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pu9wf8cdx2aeszh47kkb.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--zdR0xIam--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pu9wf8cdx2aeszh47kkb.jpg" alt="Image description" width="880" height="150"&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Add the below maven URL in &lt;strong&gt;build.gradle(Project)&lt;/strong&gt; file under the repositories of &lt;strong&gt;buildscript&lt;/strong&gt;, &lt;strong&gt;dependencies **and **allprojects&lt;/strong&gt;, refer &lt;a href="https://developer.huawei.com/consumer/en/codelab/HMSPreparation/index.html#6"&gt;Add Configuration&lt;/a&gt;.&lt;br&gt;
&lt;code&gt;maven { url 'http://developer.huawei.com/repo/' }&lt;br&gt;
classpath 'com.huawei.agconnect:agcp:1.6.0.300'&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Add the below plugin and dependencies in &lt;strong&gt;build.gradle(Module)&lt;/strong&gt; file.&lt;br&gt;
&lt;code&gt;apply plugin: id 'com.huawei.agconnect'&lt;br&gt;
// Huawei AGC&lt;br&gt;
implementation 'com.huawei.agconnect:agconnect-core:1.6.0.300'&lt;br&gt;
// Huawei Analytics Kit&lt;br&gt;
implementation 'com.huawei.hms:hianalytics:6.4.0.300'&lt;br&gt;
// Huawei Ads Kit&lt;br&gt;
implementation 'com.huawei.hms:ads-lite:13.4.51.300'&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Now Sync the gradle.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Add the required permission to the AndroidManifest.xml file&lt;br&gt;
.&lt;code&gt;// Analytics Kit&lt;br&gt;
&amp;lt;uses-permission android:name="android.permission.INTERNET" /&amp;gt;&lt;br&gt;
&amp;lt;uses-permission android:name="com.huawei.appmarket.service.commondata.permission.GET_COMMON_DATA" /&amp;gt;&lt;br&gt;
&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Let us move to development&lt;/strong&gt;&lt;br&gt;
I have created a project on Android studio with empty activity let us start coding.&lt;/p&gt;

&lt;p&gt;In the &lt;strong&gt;MainActivity.kt&lt;/strong&gt; we can find the business logic for Analytics.&lt;br&gt;
`class MainActivity : AppCompatActivity() {&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Initialize the Analytics
var  mInstance: HiAnalyticsInstance? = null

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.activity_main)

    sign_btn.setOnClickListener(mOnClickListener)
    // Initialize the Analytics function
    initAna()

}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;private fun initAna() {&lt;br&gt;
    // Enable Analytics Kit Log&lt;br&gt;
    HiAnalyticsTools.enableLog()&lt;br&gt;
    // Generate the Analytics Instance&lt;br&gt;
    mInstance = HiAnalytics.getInstance(this)&lt;br&gt;
    // Enable collection capability&lt;br&gt;
    mInstance?.setAnalyticsEnabled(true)&lt;br&gt;
}&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
    super.onActivityResult(requestCode, resultCode, data)
    if (requestCode == 1002 ) {
        val authAccountTask = AccountAuthManager.parseAuthResultFromIntent(data)
        if (authAccountTask.isSuccessful) {

            // Analytics data to send custom events
            val bundle = Bundle()
            bundle.putString("email", data!!.extras!!.getString("email" ))
            bundle.putString("name", data.extras!!.getString("name"))
            bundle.putString("phone", data!!.extras!!.getInt("phone").toString())
            bundle.putString("marks", data!!.extras!!.getFloat("86.5").toString())
            mInstance!!.onEvent(HAEventType.SIGNIN, bundle)

            Toast.makeText(this, "SigIn success", Toast.LENGTH_LONG).show()
        } else {
            Toast.makeText(this, "SignIn failed: " + (authAccountTask.exception as ApiException).statusCode, Toast.LENGTH_LONG).show()
        }
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;}`&lt;/p&gt;

&lt;p&gt;In the &lt;strong&gt;ListActivity.kt&lt;/strong&gt; we can find the business logic for Ads.&lt;br&gt;
`class ListActivity : AppCompatActivity() {&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Initialize the Interstitial Ads Kit
private var interstitialAd: InterstitialAd? = null

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.activity_list)

   title = getString(R.string.interstitial_ad)
    btn_alltypes.setOnClickListener {
        loadInterstitialAd()
    }

    showInterstitialAd()
    val actionBar = supportActionBar
    actionBar!!.setDisplayHomeAsUpEnabled(true)
}

private val adListener: AdListener = object : AdListener() {
    override fun onAdLoaded() {
        super.onAdLoaded()
        showToast("Ad loaded")
        // Display an interstitial ad.
        showInterstitialAd()
        val intent = Intent(this@ListActivity, Home::class.java)
        startActivity(intent)
    }
    override fun onAdFailed(errorCode: Int) {
        showToast("Ad load failed with error code: $errorCode")
        Log.d(TAG, "Ad load failed with error code: $errorCode")
        val intent = Intent(this@ListActivity, Home::class.java)
        startActivity(intent)
    }
    override fun onAdClosed() {
        super.onAdClosed()
        showToast("Ad closed")
        Log.d(TAG, "onAdClosed")
        val intent = Intent(this@ListActivity, Home::class.java)
        startActivity(intent)
    }
    override fun onAdClicked() {
        Log.d(TAG, "onAdClicked")
        super.onAdClicked()
    }
    override fun onAdOpened() {
        Log.d(TAG, "onAdOpened")
        super.onAdOpened()
    }
    override fun onAdLeave() {
        Log.d(TAG, "onAdLeaves")
        super.onAdLeave()
    }
}

private fun loadInterstitialAd() {
    // Load an interstitial ad.
    interstitialAd = InterstitialAd(this)
    val adParam = AdParam.Builder().build()
    interstitialAd!!.adId = getString(R.string.video_ad_id)
    interstitialAd!!.loadAd(adParam)
    interstitialAd!!.adListener = adListener
}

private val adId: String
    get() = if (btn_alltypes.isClickable) {
        getString(R.string.image_ad_id)
    } else {
        getString(R.string.video_ad_id)
    }

private fun showInterstitialAd() {
    // Display the ad
    if (interstitialAd != null &amp;amp;&amp;amp; interstitialAd!!.isLoaded) {
        interstitialAd!!.show(this)
    } else {
        Toast.makeText(this, "Ad did not load", Toast.LENGTH_LONG).show()
    }
}

private fun showToast(text: String) {
    runOnUiThread {
        Toast.makeText(this@ListActivity, text, Toast.LENGTH_LONG).show()
    }
}

companion object {
    private val TAG = ListActivity::class.java.simpleName
}

override fun onSupportNavigateUp(): Boolean {
    finish()
    return super.onSupportNavigateUp()
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;}`&lt;/p&gt;

&lt;p&gt;In the &lt;strong&gt;activity_main.xml&lt;/strong&gt; we can create the UI screen.&lt;br&gt;
`&amp;lt;?xml version="1.0" encoding="utf-8"?&amp;gt;&lt;br&gt;

    xmlns:app="http://schemas.android.com/apk/res-auto"&lt;br&gt;
    xmlns:tools="http://schemas.android.com/tools"&lt;br&gt;
    android:layout_width="match_parent"&lt;br&gt;
    android:layout_height="match_parent"&lt;br&gt;
    android:orientation="vertical"&lt;br&gt;
    android:background="@drawable/book_fly"&lt;br&gt;
    tools:context=".MainActivity"&amp;gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;ImageButton
    android:id="@+id/sign_btn"
    android:layout_width="290dp"
    android:layout_height="60dp"
    android:layout_alignParentBottom="true"
    android:layout_centerInParent="true"
    android:layout_margin="15dp"
    android:paddingTop="10dp"
    app:srcCompat="@drawable/huawei_id_buttons" /&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;`&lt;/p&gt;

&lt;p&gt;In the &lt;strong&gt;activity_list.xml&lt;/strong&gt; we can create the UI screen.&lt;br&gt;
`&amp;lt;?xml version="1.0" encoding="utf-8"?&amp;gt;&lt;br&gt;

    xmlns:app="http://schemas.android.com/apk/res-auto"&lt;br&gt;
    xmlns:tools="http://schemas.android.com/tools"&lt;br&gt;
    android:layout_width="match_parent"&lt;br&gt;
    android:layout_height="match_parent"&lt;br&gt;
    android:orientation="vertical"&lt;br&gt;
    android:paddingTop="10dp"&lt;br&gt;
    android:paddingBottom="10dp"&lt;br&gt;
    tools:context=".ListActivity"&amp;gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;Button
    android:id="@+id/btn_alltypes"
    android:layout_width="310dp"
    android:layout_height="wrap_content"
    android:layout_marginTop="70dp"
    android:textAlignment="center"
    android:layout_gravity="center_horizontal"
    android:textSize="20sp"
    android:textColor="@color/black"
    android:padding="10dp"
    android:textAllCaps="false"
    android:text="Types of Books" /&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;`&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Demo&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--1a3RiERb--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/28qyvx2uhun321y9jozj.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--1a3RiERb--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/28qyvx2uhun321y9jozj.jpg" alt="Image description" width="355" height="716"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--MlBTweRQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ynuupx9ykcn7ptgtxgmu.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--MlBTweRQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ynuupx9ykcn7ptgtxgmu.jpg" alt="Image description" width="355" height="769"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--7F1zUJnz--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bt9ud7umfnue7rvv35t5.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--7F1zUJnz--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bt9ud7umfnue7rvv35t5.jpg" alt="Image description" width="299" height="618"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--keponG9F--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/x5ycdmn9x2gvsg39u4do.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--keponG9F--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/x5ycdmn9x2gvsg39u4do.jpg" alt="Image description" width="300" height="630"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--a2NEmPno--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zls7cs6aj6dgacjlqya6.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--a2NEmPno--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zls7cs6aj6dgacjlqya6.jpg" alt="Image description" width="298" height="626"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tips and Tricks&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Make sure you are already registered as Huawei developer.&lt;/li&gt;
&lt;li&gt;Set minSDK version to 24 or later, otherwise you will get AndriodManifest merge issue.&lt;/li&gt;
&lt;li&gt;Make sure you have added the &lt;strong&gt;agconnect-services.json&lt;/strong&gt; file to app folder.&lt;/li&gt;
&lt;li&gt;Make sure you have added SHA-256 fingerprint without fail.&lt;/li&gt;
&lt;li&gt;Make sure all the dependencies are added properly.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;br&gt;
In this article, we have learned how to integrate the Huawei Analytics Kit and Ads Kit in Book Reading app. So, I will provide the series of articles on this Book Reading App, in upcoming articles will integrate other Huawei Kits.&lt;/p&gt;

&lt;p&gt;I hope you have read this article. If you found it is helpful, please provide likes and comments.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Reference&lt;/strong&gt;&lt;br&gt;
&lt;a href="https://developer.huawei.com/consumer/en/doc/development/HMSCore-Guides/android-dev-process-0000001050163813"&gt;Analytics Kit&lt;/a&gt;&lt;br&gt;
Ads Kit - &lt;a href="https://developer.huawei.com/consumer/en/doc/development/HMSCore-Guides/publisher-service-interstitial-0000001050064970"&gt;Interstitial Ads&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Integration of Huawei Account Kit in Book Reading Android app (Kotlin) - Part 1</title>
      <dc:creator>MuraliAkula1</dc:creator>
      <pubDate>Fri, 04 Feb 2022 04:53:09 +0000</pubDate>
      <link>https://dev.to/muraliakula1/integration-of-huawei-account-kit-in-book-reading-android-app-kotlin-part-1-1nge</link>
      <guid>https://dev.to/muraliakula1/integration-of-huawei-account-kit-in-book-reading-android-app-kotlin-part-1-1nge</guid>
      <description>&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--NUkJZ7cV--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rr6hgwzqccrbnfhhtv1z.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--NUkJZ7cV--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rr6hgwzqccrbnfhhtv1z.jpg" alt="Image description" width="499" height="346"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Introduction&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;In this article, we can learn how to integrate the &lt;strong&gt;Huawei Account Kit&lt;/strong&gt; in Book Reading app. So, I will provide the series of articles on this Book Reading App, in upcoming articles I will integrate other Huawei Kits.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Account Kit&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Huawei Account Kit provides for developers with &lt;strong&gt;simple&lt;/strong&gt;, &lt;strong&gt;secure&lt;/strong&gt;, and &lt;strong&gt;quick sign-in&lt;/strong&gt; and authorization functions. User is not required to enter accounts, passwords and waiting for authorization. User can click on &lt;strong&gt;Sign In with HUAWEI ID&lt;/strong&gt; button to quickly and securely sign in to the app.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Requirements&lt;/strong&gt;
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Any operating system (MacOS, Linux and Windows).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Must have a Huawei phone with HMS 4.0.0.300 or later.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Must have a laptop or desktop with Android Studio, Jdk 1.8, SDK platform 26 and Gradle 4.6 and above installed.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Minimum API Level 24 is required.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Required EMUI 9.0.0 and later version devices.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;How to integrate HMS Dependencies&lt;/strong&gt;
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;First register as Huawei developer and complete identity verification in Huawei developers website, refer to register a &lt;a href="https://developer.huawei.com/consumer/en/doc/start/registration-and-verification-0000001053628148"&gt;Huawei ID&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;Create a project in android studio, refer &lt;a href="https://developer.huawei.com/consumer/en/codelab/HMSPreparation/index.html#1"&gt;Creating an Android Studio Project&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;Generate a &lt;strong&gt;SHA-256 certificate fingerprint&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;To generate &lt;strong&gt;SHA-256 certificate fingerprint&lt;/strong&gt;. On right-upper corner of android project click &lt;strong&gt;Gradle&lt;/strong&gt;, choose &lt;strong&gt;Project Name &amp;gt; Tasks &amp;gt; android&lt;/strong&gt;, and then click &lt;strong&gt;signingReport&lt;/strong&gt;, as follows.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--n3jTmoYc--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rlsp69x3eohuilb3jaso.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--n3jTmoYc--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rlsp69x3eohuilb3jaso.png" alt="Image description" width="880" height="516"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://developer.huawei.com/consumer/en/codelab/HMSPreparation/index.html#0"&gt;Create an App in AppGallery Connect&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;Download the &lt;strong&gt;agconnect-services.json&lt;/strong&gt; file from &lt;strong&gt;App information&lt;/strong&gt;, copy and paste in android **Project **under **app **directory, as follows.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Hpt-52XO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/row6epkn1g959j0z3uos.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Hpt-52XO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/row6epkn1g959j0z3uos.png" alt="Image description" width="464" height="616"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Enter &lt;strong&gt;SHA-256 certificate fingerprint&lt;/strong&gt; and click **Save **button, as follows.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--nknuN8kN--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/abirkw50zgoeivhuspez.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--nknuN8kN--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/abirkw50zgoeivhuspez.png" alt="Image description" width="880" height="298"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Click &lt;strong&gt;Manage APIs&lt;/strong&gt; tab and enable &lt;strong&gt;Account Kit&lt;/strong&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--o3KIya3p--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0dz2wugp8pgk6ao1hc10.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--o3KIya3p--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0dz2wugp8pgk6ao1hc10.jpg" alt="Image description" width="880" height="150"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Add the below maven URL in &lt;strong&gt;build.gradle(Project)&lt;/strong&gt; file under the repositories of &lt;strong&gt;buildscript&lt;/strong&gt;, &lt;strong&gt;dependencies and allprojects&lt;/strong&gt;, refer &lt;a href="https://developer.huawei.com/consumer/en/codelab/HMSPreparation/index.html#6"&gt;Add Configuration&lt;/a&gt;.
&lt;code&gt;maven { url 'http://developer.huawei.com/repo/' }
classpath 'com.huawei.agconnect:agcp:1.6.0.300'&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Add the below plugin and dependencies in &lt;strong&gt;build.gradle(Module)&lt;/strong&gt; file.
&lt;code&gt;apply plugin: id 'com.huawei.agconnect'
// Huawei AGC
implementation 'com.huawei.agconnect:agconnect-core:1.6.0.300'
// Huawei Account Kit
implementation 'com.huawei.hms:hwid:6.3.0.301'
implementation 'androidx.recyclerview:recyclerview:1.2.1'&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Now Sync the gradle.&lt;/li&gt;
&lt;li&gt;Add the required permission to the &lt;strong&gt;AndroidManifest.xml&lt;/strong&gt; file.
&lt;code&gt;&amp;lt;uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /&amp;gt;
&amp;lt;uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /&amp;gt;&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Let us move to development&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;I have created a project on Android studio with empty activity let us start coding.&lt;/p&gt;

&lt;p&gt;In the &lt;strong&gt;MainActivity.kt&lt;/strong&gt; we can find the business logic.&lt;/p&gt;

&lt;p&gt;`class MainActivity : AppCompatActivity() {&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;private var mAuthManager: AccountAuthService? = null
private var mAuthParam: AccountAuthParams? = null

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.activity_main)

    sign_btn.setOnClickListener(mOnClickListener)

}

private fun signIn() {
    mAuthParam = AccountAuthParamsHelper(AccountAuthParams.DEFAULT_AUTH_REQUEST_PARAM)
        .setIdToken()
        .setAccessToken()
        .setProfile()
        .createParams()
    mAuthManager = AccountAuthManager.getService(this@MainActivity, mAuthParam)
    startActivityForResult(mAuthManager?.signInIntent, 1002)
}

private val mOnClickListener: View.OnClickListener = object : View.OnClickListener {
    override fun onClick(v: View?) {
        when (v?.id) {
            R.id.sign_btn -&amp;gt; signIn()
        }
    }
}

override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
    super.onActivityResult(requestCode, resultCode, data)
    if (requestCode == 1002 ) {
        val authAccountTask = AccountAuthManager.parseAuthResultFromIntent(data)
        if (authAccountTask.isSuccessful) {
            Toast.makeText(this, "SigIn success", Toast.LENGTH_LONG).show()
            val intent = Intent(this@MainActivity, Home::class.java)
            startActivity(intent)
        } else {
            Toast.makeText(this, "SignIn failed: " + (authAccountTask.exception as ApiException).statusCode, Toast.LENGTH_LONG).show()
        }
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;}`&lt;br&gt;
In the &lt;strong&gt;Home.kt&lt;/strong&gt; we can find the business logic.&lt;/p&gt;

&lt;p&gt;`class Home : AppCompatActivity() {&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;lateinit var recyclerView: RecyclerView
var mBookAdapter: BookAdapter? = null

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.activity_home)

    recyclerView = findViewById(R.id.recycler_view)
    mBookAdapter = BookAdapter()
    recyclerView.adapter = mBookAdapter

}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;}`&lt;/p&gt;

&lt;p&gt;Create &lt;strong&gt;BookAdapter.kt&lt;/strong&gt; class for holding the list.&lt;/p&gt;

&lt;p&gt;`class BookAdapter(): RecyclerView.Adapter() {&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;private var titles = arrayOf("Life", "Young Adult", "Comedy", "Women", "Tragedy", "Science Fiction",
                             "Horror Stories", "Drama", "Society", "Biography")
private var images = intArrayOf(R.drawable.life, R.drawable.youth, R.drawable.comedy, R.drawable.women,
                                R.drawable.tragedy, R.drawable.science, R.drawable.horror, R.drawable.drama,
                                R.drawable.society, R.drawable.biography)

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): BookAdapter.ViewHolder {
    val view = LayoutInflater.from(parent.context)
        .inflate(R.layout.list_item, parent, false)
    return BookAdapter.ViewHolder(view)
}

override fun onBindViewHolder(holder: BookAdapter.ViewHolder, position: Int) {
    holder.itemTitle.text = titles[position]
    holder.itemImage.setImageResource(images[position])
}

override fun getItemCount(): Int {
    return titles.size
}

class ViewHolder(ItemView: View) : RecyclerView.ViewHolder(ItemView) {
    var itemTitle: TextView = itemView.findViewById(R.id.titles)
    var itemImage: ImageView = itemView.findViewById(R.id.images)
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;}`&lt;/p&gt;

&lt;p&gt;In the &lt;strong&gt;activity_main.xml&lt;/strong&gt; we can create the UI screen.&lt;/p&gt;

&lt;p&gt;`&amp;lt;?xml version="1.0" encoding="utf-8"?&amp;gt;&lt;br&gt;

    xmlns:app="http://schemas.android.com/apk/res-auto"&lt;br&gt;
    xmlns:tools="http://schemas.android.com/tools"&lt;br&gt;
    android:layout_width="match_parent"&lt;br&gt;
    android:layout_height="match_parent"&lt;br&gt;
    android:orientation="vertical"&lt;br&gt;
    android:background="@drawable/book_fly"&lt;br&gt;
    tools:context=".MainActivity"&amp;gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;TextView
    android:id="@+id/act_main_title"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="left"
    android:layout_marginLeft="20dp"
    android:layout_marginTop="30dp"
    android:text="Huawei E-Book Store"
    android:textSize="32sp"
    android:textColor="@color/hwid_auth_button_color_red"
    android:textStyle="bold" /&amp;gt;

&amp;lt;ImageButton
    android:id="@+id/sign_btn"
    android:layout_width="290dp"
    android:layout_height="60dp"
    android:layout_alignParentBottom="true"
    android:layout_centerInParent="true"
    android:layout_margin="15dp"
    android:paddingTop="10dp"
    app:srcCompat="@drawable/huawei_id_buttons" /&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;`&lt;/p&gt;

&lt;p&gt;In the &lt;strong&gt;activity_home.xml&lt;/strong&gt; we can create the UI screen.&lt;/p&gt;

&lt;p&gt;`&amp;lt;?xml version="1.0" encoding="utf-8"?&amp;gt;&lt;br&gt;

    xmlns:app="http://schemas.android.com/apk/res-auto"&lt;br&gt;
    xmlns:tools="http://schemas.android.com/tools"&lt;br&gt;
    android:layout_width="match_parent"&lt;br&gt;
    android:layout_height="match_parent"&lt;br&gt;
    android:gravity="center_vertical"&lt;br&gt;
    android:orientation="vertical"&lt;br&gt;
    android:paddingLeft="8dp"&lt;br&gt;
    android:paddingRight="8dp"&lt;br&gt;
    tools:context=".Home"&amp;gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;androidx.recyclerview.widget.RecyclerView
    android:id="@+id/recycler_view"
    android:layout_width="match_parent"
    app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
    android:layout_height="match_parent" /&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;`&lt;/p&gt;

&lt;p&gt;In the &lt;strong&gt;list_item.xml&lt;/strong&gt; we can create the list of items.&lt;/p&gt;

&lt;p&gt;`&amp;lt;?xml version="1.0" encoding="utf-8"?&amp;gt;&lt;br&gt;

    xmlns:app="http://schemas.android.com/apk/res-auto"&lt;br&gt;
    android:layout_width="match_parent"&lt;br&gt;
    android:layout_height="wrap_content"&lt;br&gt;
    android:id="@+id/list_view"&lt;br&gt;
    android:layout_marginLeft="-3dp"&lt;br&gt;
    android:layout_marginRight="0dp"&lt;br&gt;
    android:layout_marginBottom="5dp"&lt;br&gt;
    app:cardBackgroundColor="@color/hwid_auth_button_color_border"&lt;br&gt;
    app:cardCornerRadius="8dp"&lt;br&gt;
    app:cardElevation="3dp"&lt;br&gt;
    app:contentPadding="5dp"&amp;gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:padding="5dp"&amp;gt;
    &amp;lt;TextView
        android:id="@+id/titles"
        android:layout_width="160dp"
        android:layout_height="50dp"
        android:layout_marginStart="10dp"
        android:layout_marginLeft="15dp"
        android:text="Item"
        android:textSize="20sp"
        android:textAlignment="viewStart"
        android:textColor="@color/black"
        android:textStyle="bold" /&amp;gt;
    &amp;lt;ImageView
        android:id="@+id/images"
        android:layout_width="150dp"
        android:layout_height="60dp"
        android:layout_gravity="right"
        android:layout_marginLeft="55dp" /&amp;gt;
&amp;lt;/LinearLayout&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;`&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Demo&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--P-BiqMfU--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3ahgz4hbe4ioegnre6lz.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--P-BiqMfU--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3ahgz4hbe4ioegnre6lz.jpg" alt="Image description" width="357" height="760"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--29pt_mBY--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/47rwpgkfdea3km8dfonk.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--29pt_mBY--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/47rwpgkfdea3km8dfonk.jpg" alt="Image description" width="352" height="759"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--HFHPHW7Z--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pa9ubqm8z8s2ltkfijl4.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--HFHPHW7Z--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pa9ubqm8z8s2ltkfijl4.jpg" alt="Image description" width="356" height="759"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--1EKJm-bb--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/r48xc2l3glmivut7x0ei.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--1EKJm-bb--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/r48xc2l3glmivut7x0ei.jpg" alt="Image description" width="355" height="757"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Tips and Tricks&lt;/strong&gt;
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Make sure you are already registered as Huawei developer.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Set minSDK version to &lt;strong&gt;24&lt;/strong&gt; or later, otherwise you will get **AndriodManifest **merge issue.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Make sure you have added the &lt;strong&gt;agconnect-services.json&lt;/strong&gt; file to app folder.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Make sure you have added &lt;strong&gt;SHA-256 fingerprint&lt;/strong&gt; without fail.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Make sure all the dependencies are added properly.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Conclusion&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;In this article, we have learned how to integrate the &lt;strong&gt;Huawei Account Kit&lt;/strong&gt; in Book Reading app. So, I will provide the series of articles on this Book Reading App, in upcoming articles will integrate other Huawei Kits.&lt;/p&gt;

&lt;p&gt;I hope you have read this article. If you found it is helpful, please provide likes and comments.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Reference&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://developer.huawei.com/consumer/en/doc/development/HMSCore-Guides/introduction-0000001050048870"&gt;Account Kit&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
