<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by tolunaykatirci on Medium]]></title>
        <description><![CDATA[Stories by tolunaykatirci on Medium]]></description>
        <link>https://medium.com/@tolunaykatirci?source=rss-5dd1b7feb64e------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*I5blRoE6y_6djrznciJswQ.jpeg</url>
            <title>Stories by tolunaykatirci on Medium</title>
            <link>https://medium.com/@tolunaykatirci?source=rss-5dd1b7feb64e------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 03:19:45 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@tolunaykatirci/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Database Relationships In Spring Data JPA]]></title>
            <link>https://medium.com/huawei-developers/database-relationships-in-spring-data-jpa-8d7181f50f60?source=rss-5dd1b7feb64e------2</link>
            <guid isPermaLink="false">https://medium.com/p/8d7181f50f60</guid>
            <category><![CDATA[database]]></category>
            <category><![CDATA[spring-boot]]></category>
            <category><![CDATA[one-to-many]]></category>
            <category><![CDATA[spring-jpa]]></category>
            <category><![CDATA[one-to-one]]></category>
            <dc:creator><![CDATA[tolunaykatirci]]></dc:creator>
            <pubDate>Mon, 05 Jul 2021 18:28:20 GMT</pubDate>
            <atom:updated>2021-07-06T13:46:48.196Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ogDh6QwIStNatDyH3VCRGQ.png" /></figure><p>Hello everyone, in this story, I will try to show Database relationships (One-to-Many, Many-to-Many, One-to-One) with examples in Spring Data JPA.</p><p>Let’s start 💪</p><h3>Introduction</h3><p>I created an example ER diagram for book database. I will try to explain the relations by including the scenario in this diagram in the project.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/681/1*wAT6A6Cka5vKpTrm_rFzIw.png" /></figure><p>In this diagram, there is a <strong>Many-to-Many</strong> relationship between books and categories. A book can have more than one category, and a category can have more than one book. The same is true for the relationship between the book and the author.</p><p>Categories can have subcategories. These subcategories must be linked to a parent category. In this case, the <strong>One-to-Many</strong> relationship emerges.</p><p>There is also a photo table attached to the books. This table keeps the cover photos of the related book in different sizes. The relationship here will be <strong>One-to-One</strong>.</p><p>First we will create a Spring project using Spring Initializr. Then we will establish the database connection. I will use PostgreSQL database in this project.</p><p>Next, we will look at these relationships in more detail by applying the diagram through the code.</p><p>I used the following versions while developing this project.</p><ul><li>Java 11.0.11</li><li>Spring 2.5.2</li><li>PostgreSQL 13.3–2</li><li>Intellij IDEA Community 2021.1.2</li></ul><h3>Installation</h3><p>Let’s start with creating a new Spring application with <a href="https://start.spring.io/">Spring Initializr</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JsNYqKvcEKaFE32FNF4U-w.png" /></figure><p>We should specify project metadata and select some required dependencies. After providing required data, we can download our demo project by clicking generate button.</p><p>Open the project in Intellij IDEA and connect to database by adding required information to <strong>application.properties </strong>file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/716/1*GGKTdORsdpgsYkAzUtR-Rw.png" /></figure><h3>Implementation</h3><p>In this section, we will implement the previously specified ER diagram.</p><p>Let’s start with entities without creating relations. For the construction and Getter &amp; Setter methods, we will use <a href="https://projectlombok.org/">Lombok</a> library. <strong>Data </strong>annotation contains <em>ToString, Getter, Setter, EqualsAndHashCode</em> and <em>RequiredArgsConstructor.</em></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7a8bb13ba7abedb3fad2ae2f4a1aec2e/href">https://medium.com/media/7a8bb13ba7abedb3fad2ae2f4a1aec2e/href</a></iframe><p>This is an example to <strong>Book </strong>entity. Other entities will be similar. After we created all entities and run the program, we should find these tables on our database.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/251/1*Ad26n5KONtASaLcuHLpHpw.png" /></figure><p>We can check the restrictions from the <strong>Column </strong>section of any table properties. For example, for the Book table, title cannot be null.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/696/1*FbSRUopedWMsYSBXapUPxg.png" /></figure><p>If all OK, we can start to implement relations.</p><h4>OneToOne Relation</h4><p>Relationship between Book and Photo is an example to <strong>OneToOne </strong>relation.</p><p>For that relation, we need to create a foreign key for <strong>photo_id </strong>parameter in Book table. <strong>OneToOne</strong> annotation will create this relation for us. We should add this annotation to both entity classes that’s because this is a bidirectional relationship.</p><p>We want to create a column in Book table. So, we will use <strong>JoinColumn </strong>annotation in Book class. On the Photo class, simply put <strong>OneToOne</strong> annotation and fill<strong> mappedBy </strong>field by variable name on the owning side. In this example, this value will be ‘photo’.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a0372277385b21e14fe31ee2c3169849/href">https://medium.com/media/a0372277385b21e14fe31ee2c3169849/href</a></iframe><p>Rerun the program and you will see the <strong>photo_id</strong> in columns and the <strong>foreign key</strong> in the properties of the Book table.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/692/1*w9R3uJv-KLoU-qhECpWFiQ.png" /></figure><h4>OneToMany Relation</h4><p>Relationship between parent category and children categories in Category table is an example to <strong>OneToMany </strong>relation.</p><p>In this case, both parent and children tables are same, we will add both <strong>OneToMany</strong> and <strong>ManyToOne</strong> annotations to same class. We should join a column for <strong>parent_id</strong>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5117fdb5c48e35075e69489d5f467c35/href">https://medium.com/media/5117fdb5c48e35075e69489d5f467c35/href</a></iframe><p>After rerunning the program, we will see a foreign key for <strong>parent_id </strong>in properties of Category table.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/695/1*vmi6pP_sD2-cxp_JoZYOFA.png" /></figure><h4>ManyToMany Relation</h4><p>Relationship between book and category is an example to <strong>ManyToMany</strong> relation.</p><p>In this relation, we need to create a new table to handle <strong>ManyToMany</strong> relationship. This new table will hold foreign keys for both <strong>book_id</strong> and <strong>category_id</strong> fields. We will follow the relationship between books and categories by this table.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8f174ac09e66048561c8ba27960b6834/href">https://medium.com/media/8f174ac09e66048561c8ba27960b6834/href</a></iframe><p>After running the code, a new table called <strong>books_categories </strong>will be exist and specified foreign keys will be shown in properties of this new table.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/694/1*SetP4K33SkB6JZCjE-ABvQ.png" /></figure><p>We need same relation for book and author. After adding that, we can test our database.</p><h4>Testing</h4><p>In pgAdmin, we can find a <strong>Generate ERD (Beta) </strong>option by right click to the our database.</p><p>The result is quite similar to our ER diagram.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/881/1*CmRgtP5qJ-9X9jx8MmEWOA.png" /></figure><h3>Conclusion</h3><p>In this story, i tried to explain database relations in Spring Data JPA. I hope, it was helpful.</p><p>You can ask any questions or text me if there is a mistake in story.</p><p>You can find final codes on my GitHub profile. And I would be very happy if you want contribute 🙃</p><p>Thanks for reading…</p><h3>References</h3><p><a href="https://www.baeldung.com/spring-data-rest-relationships">https://www.baeldung.com/spring-data-rest-relationships</a></p><p><a href="https://github.com/tolunaykatirci/spring-data-jpa-relationships">tolunaykatirci/spring-data-jpa-relationships</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8d7181f50f60" width="1" height="1" alt=""><hr><p><a href="https://medium.com/huawei-developers/database-relationships-in-spring-data-jpa-8d7181f50f60">Database Relationships In Spring Data JPA</a> was originally published in <a href="https://medium.com/huawei-developers">Huawei Developers</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[HUAWEI Cordova Map Plugin in Ionic]]></title>
            <link>https://medium.com/huawei-developers/huawei-cordova-map-plugin-in-ionic-e0ab93f3dfe?source=rss-5dd1b7feb64e------2</link>
            <guid isPermaLink="false">https://medium.com/p/e0ab93f3dfe</guid>
            <category><![CDATA[hms-core]]></category>
            <category><![CDATA[cordova]]></category>
            <category><![CDATA[huawei]]></category>
            <category><![CDATA[ionic]]></category>
            <category><![CDATA[maps]]></category>
            <dc:creator><![CDATA[tolunaykatirci]]></dc:creator>
            <pubDate>Tue, 16 Mar 2021 10:42:35 GMT</pubDate>
            <atom:updated>2021-03-16T11:21:01.888Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*pXdQnxeKZ4okrOOL.jpg" /></figure><h3>Introduction</h3><p>Hello everyone, in this article, I will show how to integrate Huawei Cordova Map Plugin to an Ionic project and how to use features of this plugin.</p><h3>Pre-Installation</h3><h4>Configuring App Information in AppGallery Connect</h4><blockquote>Before you get started, you must register as a HUAWEI developer and complete identity verification on <a href="https://developer.huawei.com/consumer/en">HUAWEI Developers</a>.</blockquote><p>Firstly, lets create an AppGallery Connect Project.</p><ol><li>Sign in to <a href="https://developer.huawei.com/consumer/en/service/josp/agc/index.html">AppGallery Connect</a> and select <strong>My projects</strong>.</li><li>Click <strong>Add project</strong>.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*BD7q91zpzgOeAFMP.png" /></figure><p>3. Enter a project name and click <strong>OK.</strong></p><p>After the project is created, the <strong>Project settings</strong> page is displayed. Before you use development capabilities provided by <strong>AppGallery Connect</strong>, you need to add an app to your project first.</p><ol><li>In section <strong>Project settings </strong>&gt; <strong>General information</strong>, click <strong>Add app</strong>.</li><li>On the <strong>Add app</strong> page, enter app information.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/777/0*Nmj4kCrLwwKbBrNy.png" /><figcaption>Enter App Information</figcaption></figure><p>3. On the <strong>Project settings</strong> page, enter SHA-256 certificate fingerprint and then download the configuration file <strong>agconnect-services.json </strong>for Android platform.</p><p>We will use this file later.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*tnY0WqAIyJjY9V34.png" /></figure><blockquote>A signing certificate fingerprint is used to verify the authenticity of an app when it attempts to access an HMS Core (APK) through the HMS SDK. Before using the HMS Core (APK), you must locally generate a signing certificate fingerprint and configure it in the <strong>AppGallery Connect</strong>. You can refer to 3rd and 4th steps of <a href="https://developer.huawei.com/consumer/en/codelab/HMSPreparation/index.html#2">Generating a Signing Certificate</a> Codelab tutorial for the certificate generation. Perform the following steps after you have generated the certificate.</blockquote><h4>Enabling Service</h4><p>To use HUAWEI Map Plugin on your app, you need to enable the service if not enabled before.</p><ol><li>Sign in to <a href="https://developer.huawei.com/consumer/en/">HUAWEI Developers</a> and click <a href="https://developer.huawei.com/consumer/en/console">Console</a> in the upper right corner. Go to <strong>HMS API Services</strong> &gt; <strong>My APIs</strong>, select the project for which you want to enable HUAWEI Map Kit, and click <strong>Add API from library</strong>. The <strong>API Library</strong> page is displayed.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/625/0*_dd5ivS0v7pTOcWs" /></figure><p>2. Click <strong>Map Kit</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*N8LSQwNFCwVtI_Zz" /></figure><p>3. On the <strong>Map Kit</strong> page, click <strong>Enable</strong> to enable HUAWEI Map Kit.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GIEtEHXYJERKyIlsrdva7w.png" /></figure><h3>Installation</h3><p>Before integrate Huawei Map plugin, make sure you have installed Node.js, npm, Cordova CLI and Ionic CLI on your computer.</p><ol><li>Create a new Ionic project. I used the Cordova Backend to develop the sample project but you can use also Capacitor Backend if you want.</li></ol><pre>ionic start HuaweiMapDemo blank --type=angular --cordova</pre><blockquote>To create a new Ionic project, you can use <strong><em>ionic start &lt;name&gt; &lt;template&gt; [options]</em></strong> command. For more details you can follow <a href="https://ionicframework.com/docs/cli/commands/start">ionic start - Ionic Documentation</a>.</blockquote><p>2. Update the widget <strong>id</strong> property which is specified in the <strong>config.xml</strong> file. It must be same with <strong>client &gt; package_name</strong> value of the <strong>agconnect-services.json</strong> file.</p><p>3. Go into project directory and add the android platform to the project.</p><pre>cd HuaweiMapDemo<br>ionic cordova platform add android</pre><p>4. Install HMS Map plugin to the project.</p><pre>ionic cordova plugin add @hmscore/cordova-plugin-hms-map</pre><p>5. Install Ionic Native support for HMS Map plugin.</p><pre>npm install @ionic-native/core @hmscore/ionic-native-hms-map</pre><p>6. Copy <strong>agconnect-services.json</strong> file to <strong>&lt;project_root&gt;/platforms/android/app</strong> directory.</p><p>7. Add <strong>keystore(.jks) </strong>to your project’s root directory.</p><blockquote>You can refer to 3rd and 4th steps of <a href="https://developer.huawei.com/consumer/en/codelab/HMSPreparation/index.html#2">Generating a Signing Certificate</a> Codelab tutorial page for generating keystore file.</blockquote><p>8. Create a file named as <strong>build.json </strong>in project’s root directory and fill the file according to your keystore information as in example below.</p><pre>{<br>    &quot;android&quot;: {<br>        &quot;debug&quot;: {<br>            &quot;keystore&quot;: &quot;&lt;keystore_file&gt;&quot;,<br>            &quot;storePassword&quot;: &quot;&lt;keystore_password&gt;&quot;,<br>            &quot;alias&quot;: &quot;&lt;key_alias&gt;&quot;,<br>            &quot;password&quot;: &quot;&lt;key_password&gt;&quot;<br>        },<br>        &quot;release&quot;: {<br>            &quot;keystore&quot;: &quot;&lt;keystore_file&gt;&quot;,<br>            &quot;storePassword&quot;: &quot;&lt;keystore_password&gt;&quot;,<br>            &quot;alias&quot;: &quot;&lt;key_alias&gt;&quot;,<br>            &quot;password&quot;: &quot;&lt;key_password&gt;&quot;<br>        }<br>    }<br>}</pre><p>9. Build Ionic app to generate resource files.</p><pre>ionic build</pre><p>10. Run the application.</p><pre>ionic cordova run android --device</pre><p>Project should be compile without an error and a blank Ionic project should be opened on the device.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/447/1*thJM10UOeGvcW3HCig0HIQ.png" /></figure><p>We successfully configured our project. We can use all functionalities of Huawei Cordova Map Plugin in our project.</p><h3>Using Huawei Cordova Map Plugin</h3><h4><strong>Adding Plugin to AppModule</strong></h4><p>In order to use Map Plugin in Ionic, we need to import wrapper files to <strong>app.module.ts</strong> file as a provider.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b2c9ad5d59db88efa22d878078266563/href">https://medium.com/media/b2c9ad5d59db88efa22d878078266563/href</a></iframe><p>After this step, we can use plugin functions in all pages. Inject like a service and call functions.</p><h4>Creating Map</h4><p>In Huawei Map Plugin, map instances are linked to specific div tags. Plugin creates an android map View and it shows this view below Ionic View.</p><p>We should add a div tag with id attribute to html file of the page where we want to use the map.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5817b1b140787b125b697f1102403fcd/href">https://medium.com/media/5817b1b140787b125b697f1102403fcd/href</a></iframe><p>Then, we should add some CSS properties. We should give width and height to map div and make ion-content’s background color transparent.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2405bf39b529305754b5340563ef15fd/href">https://medium.com/media/2405bf39b529305754b5340563ef15fd/href</a></iframe><p>As last step, we should initialize the map.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/10b5d42f66906c83c3846d15fca09317/href">https://medium.com/media/10b5d42f66906c83c3846d15fca09317/href</a></iframe><p>Map should be successfully shown on the page after initialized.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/448/1*SSBPlraS5_jDL7u5-LPoAw.png" /></figure><h4>Adding Marker</h4><p>We can add markers to a map to identify locations and provide extra information with information windows.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ec1bc2250f37bf80602538d3e6ec707c/href">https://medium.com/media/ec1bc2250f37bf80602538d3e6ec707c/href</a></iframe><p>After map initialized, we called <strong>addMarker </strong>function to add marker. You can configure marker options according to your case. In the sample above, we added a custom icon to marker. If you want to use default marker icon, you can delete <strong>icon</strong> property.</p><p>In addition, after marker added to map, we called <strong>setTag</strong> method of marker. We can push extra information to markers separately.</p><p>The page should look like the following.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/445/1*WjDs4nM92eioc19QrH9vGw.png" /></figure><h4>Adding InfoWindow</h4><p>Initially, infowindows of markers are empty. We can update infowindows with</p><ul><li>static values,</li><li>dynamic values using marker tags.</li></ul><p>In order to customize infowindows, we should create an html file. We can design this page as an html (add scripts, styles etc. ). <strong>getMarkerInfo</strong> function gives information of current marker. We can get our additional info with <strong>markerInfo.tag</strong> key.</p><p>I created a file named <strong>marker-info.html</strong> and saved it to <strong>assets</strong> folder.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ef8a7cb2fbc69830b6bf17f218a5478d/href">https://medium.com/media/ef8a7cb2fbc69830b6bf17f218a5478d/href</a></iframe><p>In order to use this custom html file, We should set this file as info window adapter.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/40aa197213f7e6516dab5d5192099885/href">https://medium.com/media/40aa197213f7e6516dab5d5192099885/href</a></iframe><blockquote>If you are using Capacitor Backend, you should pass file path with <strong>“public” </strong>instead of <strong>“www”</strong>.</blockquote><p>The result should look like following.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/445/1*lu-IvJ36kRt_xDP3bii9hQ.png" /></figure><h4>Drawing on Map</h4><p>Adding polygons, polylines, circles etc. is similar to marker. Just set the options and call related “add” method.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/884bfe7cf7182711e1fca0e2642d45c5/href">https://medium.com/media/884bfe7cf7182711e1fca0e2642d45c5/href</a></iframe><p>And the result is:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/446/1*tJ80vx7UyakWdxRx9YxAvg.png" /></figure><h4>Event Listening</h4><p>We can use <strong>on </strong>function to listen for map events. It has two parameters: event name and handler. When an event occurs, the handler is called.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/50485a9b0de03a82862f11a69bdcdf13/href">https://medium.com/media/50485a9b0de03a82862f11a69bdcdf13/href</a></iframe><p>You can reach all events from <a href="https://developer.huawei.com/consumer/en/doc/development/HMS-Plugin-References/map-event-0000001053115659">this</a> address.</p><h4>Page Navigation</h4><p>We need to change map visibility manually on page navigations. We can use Ionic lifecycle events to handle this problem. Map visibility should be updated like:</p><ul><li>Create HMS map on page creation,</li><li>Hide HMS map on map page leaving,</li><li>Show HMS map on map page enter,</li><li>Destroy HMS map on map page destroy.</li></ul><p>Before creating map, HTML elements should be rendered. So, we need to use <strong>ionViewDidEnter </strong>to handle map create and show cases.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d725bc264704d00b4b920c737936b13a/href">https://medium.com/media/d725bc264704d00b4b920c737936b13a/href</a></iframe><h4>Scrolling with Map</h4><p>In Ionic, we should add scroll function manually for HMS Map plugin. The <strong>content </strong>component in Ionic provides scroll events. We will use these events to handle map scrolling.</p><p>Firstly, we should activate scroll events. For each scroll event, <strong>scrollMap </strong>function will be triggered.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/da60160a6698b54cd8c8fdefb7d0196a/href">https://medium.com/media/da60160a6698b54cd8c8fdefb7d0196a/href</a></iframe><p>Then, we define the <strong>scrollMap </strong>function. Basically, calling <strong>map.scroll() </strong>function will be sufficient.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ce8b122a3d7532e74efc2c48a4357976/href">https://medium.com/media/ce8b122a3d7532e74efc2c48a4357976/href</a></iframe><h3>Conclusion</h3><p>In this story, I have tried to clarify HMS Map Plugin with detailed examples. I hope it was easy to understand. Please state your opinions and questions in the comments section.</p><p>I have collected all examples in a project and uploaded it to GitHub. You can find it by clicking <a href="https://github.com/tolunaykatirci/ionic-hms-cordova-map-sample">this</a> link.</p><p>In this story, I used HMS Map version <strong>5.1.0–300</strong>.</p><h3>References</h3><ul><li><a href="https://github.com/HMS-Core/hms-cordova-plugin/tree/master/cordova-plugin-hms-map">HMS-Core/hms-cordova-plugin</a></li><li><a href="https://developer.huawei.com/consumer/en/doc/development/HMS-Plugin-Guides/introduction-0000001050329204">Document</a></li><li><a href="https://github.com/tolunaykatirci/ionic-hms-cordova-map-sample">tolunaykatirci/ionic-hms-cordova-map-sample</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e0ab93f3dfe" width="1" height="1" alt=""><hr><p><a href="https://medium.com/huawei-developers/huawei-cordova-map-plugin-in-ionic-e0ab93f3dfe">HUAWEI Cordova Map Plugin in Ionic</a> was originally published in <a href="https://medium.com/huawei-developers">Huawei Developers</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Integrate HUAWEI Nearby Plugin to Cordova Project]]></title>
            <link>https://medium.com/huawei-developers/how-to-integrate-huawei-nearby-plugin-to-cordova-project-f863dca43e94?source=rss-5dd1b7feb64e------2</link>
            <guid isPermaLink="false">https://medium.com/p/f863dca43e94</guid>
            <category><![CDATA[huawei-mobile-service]]></category>
            <category><![CDATA[cordova]]></category>
            <category><![CDATA[huawei]]></category>
            <category><![CDATA[nearby]]></category>
            <dc:creator><![CDATA[tolunaykatirci]]></dc:creator>
            <pubDate>Mon, 11 Jan 2021 06:14:29 GMT</pubDate>
            <atom:updated>2021-01-11T08:01:50.263Z</atom:updated>
            <content:encoded><![CDATA[<h3>Introduction</h3><p>Hello everyone, in this article, I will show how to integrate Huawei Nearby Plugin to a Cordova project.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/801/1*2UQap-YNaUHwULaRQnOFng.png" /></figure><h3>Prerequisites</h3><p>You should install npm, Node.js and Cordova CLI on your PC.</p><h3>Pre-Installation</h3><h4>Configuring App Information in AppGallery Connect</h4><blockquote>Before you get started, you must register as a HUAWEI developer and complete identity verification on <a href="https://developer.huawei.com/consumer/en">HUAWEI Developers</a>.</blockquote><p>Firstly, lets create an AppGallery Connect Project.</p><ol><li>Sign in to <a href="https://developer.huawei.com/consumer/en/service/josp/agc/index.html">AppGallery Connect</a> and select <strong>My projects</strong>.</li><li>Click <strong>Add project</strong>.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*BD7q91zpzgOeAFMP.png" /></figure><p>3. Enter a project name and click <strong>OK.</strong></p><p>After the project is created, the <strong>Project settings</strong> page is displayed. Before you use development capabilities provided by <strong>AppGallery Connect</strong>, you need to add an app to your project first.</p><ol><li>In section <strong>Project settings </strong>&gt; <strong>General information</strong>, click <strong>Add app</strong>.</li><li>On the <strong>Add app</strong> page, enter app information.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/777/0*Nmj4kCrLwwKbBrNy.png" /><figcaption>Enter App Information</figcaption></figure><p>3. On the <strong>Project settings</strong> page, enter SHA-256 certificate fingerprint and then download the configuration file <strong>agconnect-services.json </strong>for Android platform.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*tnY0WqAIyJjY9V34.png" /></figure><blockquote>A signing certificate fingerprint is used to verify the authenticity of an app when it attempts to access an HMS Core (APK) through the HMS SDK. Before using the HMS Core (APK), you must locally generate a signing certificate fingerprint and configure it in the <strong>AppGallery Connect</strong>. You can refer to 3rd and 4th steps of <a href="https://developer.huawei.com/consumer/en/codelab/HMSPreparation/index.html#2">Generating a Signing Certificate</a> Codelab tutorial for the certificate generation. Perform the following steps after you have generated the certificate.</blockquote><h4>Enabling Service</h4><p>To use HUAWEI Nearby Service on your app, you first need to enable the service.</p><ol><li>Sign in to <a href="https://developer.huawei.com/consumer/en/">HUAWEI Developers</a> and click <a href="https://developer.huawei.com/consumer/en/console">Console</a> in the upper right corner. Go to <strong>HMS API Services</strong> &gt; <strong>My APIs</strong>, select the project for which you want to enable HUAWEI Nearby Service, and click <strong>Add API from library</strong>. The <strong>API Library</strong> page is displayed.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/625/0*_dd5ivS0v7pTOcWs" /></figure><p>2. Click <strong>Nearby Service</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*N8LSQwNFCwVtI_Zz" /></figure><p>3. On the <strong>Nearby Service</strong> page, click <strong>Enable</strong> to enable HUAWEI Nearby Service.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*x_x-l761hrvh9ieD" /></figure><p>4. Sign the <em>HUAWEI Nearby Service Agreement</em>.</p><blockquote>When you click <strong>My projects</strong> on the home page of AppGallery Connect to create a project for the first time, a dialog box will be displayed to prompt you to sign the <em>HUAWEI Nearby Service Agreement</em> (for details, please refer to <a href="https://developer.huawei.com/consumer/en/doc/app/10125">AppGallery Connect Service and Agreement</a>). If you have agreed to the <em>HUAWEI Nearby Service Agreement</em>, no such a dialog box will be displayed after you click <strong>Enable</strong>. For details, please refer to <a href="https://developer.huawei.com/consumer/en/doc/distribution/app/signing-guide">AppGallery Connect Agreement Signing Guide</a>.</blockquote><p>5. Go to <strong>HMS API Services</strong> &gt; <strong>My APIs</strong>. The Nearby Service API is displayed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/601/0*q-pUwQg9S-DWSZFP" /></figure><p>Pre-installation steps end here. Basically, we created an AppGallery Connect project and enabled the Nearby Service. We also saved the SHA-256 certificate fingerprint to the project.</p><h3>Installation</h3><p>Firstly, open a command line and create a new Cordova project.</p><pre>cordova create HMSNearbyDemo com.huawei.medium.nearbydemo HMSNearby</pre><p>This command will create a new directory named as <strong>HMSNearbyDemo </strong>and a new project named as <strong>HMSNearby</strong> inside it. You can change names as you wish.</p><blockquote>The widget <strong>id </strong>property in <strong>config.xml </strong>file must be same with <strong>client &gt; package_name </strong>value in <strong>agconnect-services.json </strong>file.</blockquote><ol><li>Go to project directory and add the android platform to the project.</li></ol><pre>cd HMSNearbyDemo<br>cordova platform add android</pre><p>2. Now, you need to add Huawei Nearby Plugin to the project. Run the following command in the root directory of your project to install it through <strong>npm</strong>.</p><pre>cordova plugin add <a href="http://twitter.com/hmscore/cordova-plugin-hms-nearby">@hmscore/cordova-plugin-hms-nearby</a></pre><p>3. Copy <strong>agconnect-services.json </strong>file to <strong>&lt;project_root&gt;/platforms/android/app </strong>directory. In our case, <strong>project_root </strong>is <strong>HMSNearbyDemo </strong>folder.</p><p>4. Add <strong>keystore(.jks) </strong>to your project’s root directory.</p><blockquote>You can refer to 3rd and 4th steps of <a href="https://developer.huawei.com/consumer/en/codelab/HMSPreparation/index.html#2">Generating a Signing Certificate</a> Codelab tutorial page for generating keystore file.</blockquote><p>5. Create a file named as <strong>build.json </strong>in project’s root directory and fill the file according to your keystore information as in example below.</p><pre>{<br>    &quot;android&quot;: {<br>        &quot;debug&quot;: {<br>            &quot;keystore&quot;: &quot;&lt;keystore_file&gt;.jks&quot;,<br>            &quot;storePassword&quot;: &quot;&lt;keystore_password&gt;&quot;,<br>            &quot;alias&quot;: &quot;&lt;key_alias&gt;&quot;,<br>            &quot;password&quot;: &quot;&lt;key_password&gt;&quot;<br>        },<br>        &quot;release&quot;: {<br>            &quot;keystore&quot;: &quot;&lt;keystore_file&gt;.jks&quot;,<br>            &quot;storePassword&quot;: &quot;&lt;keystore_password&gt;&quot;,<br>            &quot;alias&quot;: &quot;&lt;key_alias&gt;&quot;,<br>            &quot;password&quot;: &quot;&lt;key_password&gt;&quot;<br>        }<br>    }<br>}</pre><p>6. Huawei Nearby Plugin requires minimum sdk version 21. If your minimum sdk version is lower than 21, set it as 21 in <strong>config.xml </strong>file. Otherwise, you can skip this step.</p><pre>...<br>&lt;platform name=&quot;android&quot;&gt;<br>    ...<br>    &lt;preference name=&quot;android-minSdkVersion&quot; value=&quot;21&quot; /&gt;<br>&lt;/platform&gt;</pre><p>7. Finally, build the project.</p><pre>cordova build android</pre><p>We successfully configured our project. We can use all functionalities of Huawei Cordova Nearby Plugin in our project.</p><h3>Using Huawei Cordova Nearby Plugin</h3><p>Initially, we should request missing permissions from the user.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f03738c09bc839273ca4a0613635f0c0/href">https://medium.com/media/f03738c09bc839273ca4a0613635f0c0/href</a></iframe><p>Now, all functionalities are ready to use. The Nearby Connection basic structure is shown in the image below. I will show you sample code parts for each step.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/582/1*W1zdhl9Gbc3ccYNA0RwUdw.png" /></figure><h4>Starting Broadcasting</h4><p>The sample code for starting broadcasting is as follows:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/57ebe865a03f2c6dbcc3dc546163d57f/href">https://medium.com/media/57ebe865a03f2c6dbcc3dc546163d57f/href</a></iframe><p>You can customize the <strong>name </strong>parameter.</p><blockquote>The ‘serviceId’ parameter uniquely identifies your app. You can use the package name of your app as the value of <strong>serviceId</strong>, for example, <strong>com.huawei.example.myapp</strong>.</blockquote><h4>Starting Scanning</h4><p>The sample code for starting scanning is as follows:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5b91ff30bc96ae4fb2a66af22bb5d3ed/href">https://medium.com/media/5b91ff30bc96ae4fb2a66af22bb5d3ed/href</a></iframe><p>We need to register scan events. When a remote device is found or an already found device is lost, scan events will be triggered.</p><h4>Registering Scan Events and Requesting Connection</h4><p>Code part below sends a connection request to the remote device without asking the user when any device is found.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6da1c56bcb83923be6d022fe92e84149/href">https://medium.com/media/6da1c56bcb83923be6d022fe92e84149/href</a></iframe><h4>Registering Connection Events and Accepting Connection</h4><p>When a connection established, both peers must accept the connection. Then, event EVENT_CONNECTION_ON_RESULT will be triggered with the success state.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b4027b6d8daa5807a0ad3f4be651a2f5/href">https://medium.com/media/b4027b6d8daa5807a0ad3f4be651a2f5/href</a></iframe><h4>Registering Data Events and Sending Data</h4><p>We connected to remote peer successfully. Now, we can send any data to peer.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/92240594d29d669792adf618aaab3ddc/href">https://medium.com/media/92240594d29d669792adf618aaab3ddc/href</a></iframe><h4>Disconnection</h4><p>After all operations are done, we should simply call disconnect method. When a peer calls disconnect, event EVENT_CONNECTION_ON_DISCONNECT will be triggered on the other peer’s device.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/98ee77b5161126061646b8af75664468/href">https://medium.com/media/98ee77b5161126061646b8af75664468/href</a></iframe><h3>Conclusion</h3><p>In this article, I integrated HMS Nearby Plugin to a Cordova project and showed the basic functionalities of Nearby Connection. I tried to explain connecting to peer, transferring data and disconnection functionalities with examples.</p><p>Thank you for reading, I hope it was helpful.</p><h3>References</h3><ul><li><a href="https://www.npmjs.com/package/@hmscore/cordova-plugin-hms-nearby">@hmscore/cordova-plugin-hms-nearby</a></li><li><a href="https://developer.huawei.com/consumer/en/doc/development/HMS-Plugin-Guides/introduction-0000001062870688">Document</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f863dca43e94" width="1" height="1" alt=""><hr><p><a href="https://medium.com/huawei-developers/how-to-integrate-huawei-nearby-plugin-to-cordova-project-f863dca43e94">How to Integrate HUAWEI Nearby Plugin to Cordova Project</a> was originally published in <a href="https://medium.com/huawei-developers">Huawei Developers</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>