<?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 Bansi khokhani on Medium]]></title>
        <description><![CDATA[Stories by Bansi khokhani on Medium]]></description>
        <link>https://medium.com/@bansikhokhani27?source=rss-d76ad13ca572------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*8o9wPBYcMEHFfkU25fO2bw.jpeg</url>
            <title>Stories by Bansi khokhani on Medium</title>
            <link>https://medium.com/@bansikhokhani27?source=rss-d76ad13ca572------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 29 Nov 2026 09:44:30 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@bansikhokhani27/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[How to Add Google Ads in React-Native]]></title>
            <link>https://medium.com/@bansikhokhani27/how-to-add-google-ads-in-react-native-9a8d3a66fe43?source=rss-d76ad13ca572------2</link>
            <guid isPermaLink="false">https://medium.com/p/9a8d3a66fe43</guid>
            <category><![CDATA[reactjs]]></category>
            <category><![CDATA[admob]]></category>
            <category><![CDATA[react-native-development]]></category>
            <category><![CDATA[google-ads]]></category>
            <category><![CDATA[react-native]]></category>
            <dc:creator><![CDATA[Bansi khokhani]]></dc:creator>
            <pubDate>Sat, 09 Mar 2024 17:51:16 GMT</pubDate>
            <atom:updated>2024-03-10T13:36:00.245Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LjucR0n2pJwfkvmr5ckfVA.png" /></figure><h3><strong>Steps</strong></h3><ol><li>Setup Google AdMob Account</li><li>Add react-native-google-mobile-ads module</li><li>Add Banner, Interstitial and Rewarded Ads into mobile application</li><li>Run and Output</li></ol><h3>Step 1: Setup Google AdMob Account</h3><p>#1. First signup the <a href="https://admob.google.com/home/get-started/?subid=gb-en-ha-z-g-a-de!o3&amp;17285255462&amp;137543326275&amp;google%20admob&amp;e&amp;utm_source=sem&amp;utm_medium=text&amp;utm_campaign=2024admob_emea_gb&amp;utm_content=rsa&amp;gad_source=1&amp;gclid=Cj0KCQiArrCvBhCNARIsAOkAGcWGANfAwF8Ps8sHcTxuetu6OLNr_BrtuB-iFeeY8Yxubk3mpyXRMWoaAgqgEALw_wcB&amp;gclsrc=aw.ds"><strong>Google admob account</strong></a>, if you don’t have google admob account otherwise you can go on step 2 directly.</p><p>#2. Create new app: Apps -&gt; Add app.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9jupa793IdKJSiTAqWjcTQ.png" /><figcaption>Setup new app</figcaption></figure><p>#3. Google Ads will generate two ids: <strong>application id</strong> and <strong>app unit id.</strong></p><p>#4. Add Banner, Interstitial and Rewarded Ads: Apps -&gt; Select current -&gt; ad units.</p><h3>step 2: Add react-native-google-mobile-ads module</h3><p>#1. Install react-native-google-mobile-ads module:</p><pre>yarn add react-native-google-mobile-ads</pre><p>#2. Update app.json file:</p><pre><br>// &lt;project-root&gt;/app.json<br>{<br>  &quot;react-native-google-mobile-ads&quot;: {<br>    &quot;android_app_id&quot;: &quot;ca-app-pub-xxxxxxxx~xxxxxxxx&quot;,<br>    &quot;ios_app_id&quot;: &quot;ca-app-pub-xxxxxxxx~xxxxxxxx&quot;<br>  }<br>}</pre><p>In Google Ad Mob account, Under the “App settings” menu item, you can find the “App ID”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AeJpdz3KmrX0EJmVwFLXWQ.png" /></figure><p>Now, you can paste <strong>App Id</strong> inside the “<strong>android_app_id</strong>” and “<strong>ios_app_id</strong>” in <strong>app.json</strong> file.</p><h3>Step 3: Add Banner, Interstitial and Rewarded Ads into mobile application</h3><p><strong>#1. Banner Ads:-</strong></p><pre>import React from &#39;react&#39;;<br>import { BannerAd, BannerAdSize, TestIds } from &#39;react-native-google-mobile-ads&#39;;<br><br>const adUnitId = __DEV__ ? TestIds.BANNER : &#39;ca-app-pub-xxxxxxxxxxxxx/yyyyyyyyyyyyyy&#39;;<br><br>function App() {<br>  return (<br>    &lt;BannerAd<br>      unitId={adUnitId}<br>      size={BannerAdSize.ANCHORED_ADAPTIVE_BANNER}<br>    /&gt;<br>  );<br>}<br>export default App;</pre><p><strong>#2. Interstitial Ads:-</strong></p><pre>import React, { useEffect, useState } from &#39;react&#39;;<br>import { Button } from &#39;react-native&#39;;<br>import { InterstitialAd, AdEventType, TestIds } from &#39;react-native-google-mobile-ads&#39;;<br><br>const adUnitId = __DEV__ ? TestIds.INTERSTITIAL : &#39;ca-app-pub-xxxxxxxxxxxxx/yyyyyyyyyyyyyy&#39;;<br><br>const interstitial = InterstitialAd.createForAdRequest(adUnitId, {<br>  keywords: [&#39;fashion&#39;],<br>});<br><br>function FinalApp() {<br>  const [loaded, setLoaded] = useState(false);<br><br>  useEffect(() =&gt; {<br>    const unsubscribe = interstitial.addAdEventListener(AdEventType.LOADED, () =&gt; {<br>      setLoaded(true);<br>    });<br><br>    // Start loading the interstitial straight away<br>    interstitial.load();<br><br>    // Unsubscribe from events on unmount<br>    return unsubscribe;<br>  }, []);<br><br>  // No advert ready to show yet<br>  if (!loaded) {<br>    return null;<br>  }<br><br>  return (<br>    &lt;Button<br>      title=&quot;Show Interstitial&quot;<br>      onPress={() =&gt; {<br>        interstitial.show();<br>      }}<br>    /&gt;<br>  );<br>}<br>export default FinalApp;</pre><p><strong>#3. Rewarded Ads:-</strong></p><pre>import React, { useEffect, useState } from &#39;react&#39;;<br>import { Button } from &#39;react-native&#39;;<br>import { RewardedAd, RewardedAdEventType, TestIds } from &#39;react-native-google-mobile-ads&#39;;<br><br>const adUnitId = __DEV__ ? TestIds.REWARDED : &#39;ca-app-pub-xxxxxxxxxxxxx/yyyyyyyyyyyyyy&#39;;<br><br>const rewarded = RewardedAd.createForAdRequest(adUnitId, {<br>  keywords: [&#39;fashion&#39;, &#39;clothing&#39;],<br>});<br><br>function FinalApp() {<br>  const [loaded, setLoaded] = useState(false);<br><br>  useEffect(() =&gt; {<br>    const unsubscribeLoaded = rewarded.addAdEventListener(RewardedAdEventType.LOADED, () =&gt; {<br>      setLoaded(true);<br>    });<br>    const unsubscribeEarned = rewarded.addAdEventListener(<br>      RewardedAdEventType.EARNED_REWARD,<br>      reward =&gt; {<br>        console.log(&#39;User earned reward of &#39;, reward);<br>      },<br>    );<br><br>    // Start loading the rewarded ad straight away<br>    rewarded.load();<br><br>    // Unsubscribe from events on unmount<br>    return () =&gt; {<br>      unsubscribeLoaded();<br>      unsubscribeEarned();<br>    };<br>  }, []);<br><br>  // No advert ready to show yet<br>  if (!loaded) {<br>    return null;<br>  }<br><br>  return (<br>    &lt;Button<br>      title=&quot;Show Rewarded Ad&quot;<br>      onPress={() =&gt; {<br>        rewarded.show();<br>      }}<br>    /&gt;<br>  );<br>}<br>export default FinalApp;</pre><h3>Step 4:Run and Output</h3><p>First uninstall the app from mobile and again install the application in mobile using following command:</p><pre>yarn android</pre><p>Thank you 😊</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9a8d3a66fe43" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[To Write Data to an Excel File and Download it into the Local Directory in React-Native]]></title>
            <link>https://medium.com/@bansikhokhani27/to-write-data-to-an-excel-file-and-download-it-into-the-local-directory-in-react-native-e9827abe1124?source=rss-d76ad13ca572------2</link>
            <guid isPermaLink="false">https://medium.com/p/e9827abe1124</guid>
            <category><![CDATA[export-json-data-to-excel]]></category>
            <category><![CDATA[react-native-development]]></category>
            <category><![CDATA[excel]]></category>
            <category><![CDATA[react-native]]></category>
            <category><![CDATA[android]]></category>
            <dc:creator><![CDATA[Bansi khokhani]]></dc:creator>
            <pubDate>Wed, 06 Mar 2024 13:06:18 GMT</pubDate>
            <atom:updated>2024-03-15T22:56:33.677Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fpc3_vYMRzS4BchnqxFXbg.png" /></figure><h3><strong>Steps</strong></h3><ol><li>Create a new react-native Project</li><li>Install Dependencies ( <a href="https://www.npmjs.com/package/react-native-fs"><strong><em>react-native-fs</em></strong></a> and <a href="https://www.npmjs.com/package/xlsx"><strong><em>xlsx</em></strong></a><em> )</em></li><li>Add Storage Permission</li><li>Implement main Functionality</li><li>Final run</li></ol><h3><strong>Step 1: Create a new react-native Project</strong></h3><p>Run the following Commands:</p><pre> npx react-native init MyProjectName</pre><p>Replace MyProjectName with the desired name of your project. This command will create a new react-native project with the specified project name.</p><h3><strong>Step 2: </strong>Install Dependencies ( <a href="https://www.npmjs.com/package/react-native-fs"><strong><em>react-native-fs</em></strong></a> and <a href="https://www.npmjs.com/package/xlsx"><strong><em>xlsx</em></strong></a><em> )</em></h3><p><strong>I.</strong> Install and Link <em>`react-native-fs`</em></p><pre>npm install react-native-fs   <br>react-native link react-native-fs</pre><p>OR</p><pre>yarn add react-native-fs<br>react-native link react-native-fs</pre><p>For React Native versions 0.60 and above, automatic linking is handled by React Native’s autolinking feature, so you don’t need to run the link command.</p><p><strong>II.</strong> Install `<a href="https://www.npmjs.com/package/xlsx">xlsx</a>`</p><pre>npm install xlsx</pre><p>OR</p><pre>yarn add xlsx</pre><h3><strong>Step 3: </strong>Add Storage Permission (WRITE_EXTERNAL_STORAGE)</h3><p>Add the following line in <strong>android/app/src/main/AndroidMainfest.xml.</strong></p><pre>&lt;uses-permission android:name=&quot;android.permission.WRITE_EXTERNAL_STORAGE&quot; /&gt;</pre><h3>Step 4: Implement main functionality</h3><p><strong>I. </strong>Import <em>react-native-fs</em> and <em>xlsx</em></p><pre>let RNFS = require(‘react-native-fs’);<br>import XLSX from ‘xlsx’</pre><p><strong>II. </strong>Implement final code</p><pre>import React from &#39;react&#39;<br>import { View, StyleSheet, TouchableOpacity, Text, PermissionsAndroid } from &#39;react-native&#39;<br>var RNFS = require(&#39;react-native-fs&#39;);<br>import XLSX from &#39;xlsx&#39;;<br><br>const DownloadExcelFile = () =&gt; {<br>    // function to handle writing and downloading excel file<br>    const  writeDataAndDownloadExcelFile= () =&gt; {<br><br>        // Created Sample data<br>        let sample_data_to_export = [{ id: &#39;1&#39;, name: &#39;first&#39; }, { id: &#39;2&#39;, name: &#39;second&#39; }];<br><br>        let wb = XLSX.utils.book_new();<br>        let ws = XLSX.utils.json_to_sheet(sample_data_to_export)<br>        XLSX.utils.book_append_sheet(wb, ws, &quot;Users&quot;)<br>        const wbout = XLSX.write(wb, { type: &#39;binary&#39;, bookType: &quot;xlsx&quot; });<br><br>        // Write generated excel to Storage<br><br>        RNFS.writeFile(RNFS.DownloadDirectoryPath + &#39;/ExpenseIncomeDataFile.xlsx&#39;, wbout, &#39;ascii&#39;).then((r) =&gt; {<br>           console.log(&#39;success&#39;)<br><br>        }).catch((e) =&gt; {<br>            console.log(&#39;Error&#39;, e);<br>        });<br><br>    }<br>    const handleButtonClick = async () =&gt; {<br><br>        try {<br>            // Check for Permission (check if permission is already given or not)<br>            let isPermitedExternalStorage = await PermissionsAndroid.check(PermissionsAndroid.PERMISSIONS.WRITE_EXTERNAL_STORAGE);<br><br>            if (!isPermitedExternalStorage) {<br><br>                // Ask for permission<br>                const granted = await PermissionsAndroid.request(<br>                    PermissionsAndroid.PERMISSIONS.WRITE_EXTERNAL_STORAGE,<br>                    {<br>                        title: &quot;Storage permission needed&quot;,<br>                        buttonNeutral: &quot;Ask Me Later&quot;,<br>                        buttonNegative: &quot;Cancel&quot;,<br>                        buttonPositive: &quot;OK&quot;<br>                    }<br>                );<br><br>                if (granted === PermissionsAndroid.RESULTS.GRANTED) {<br>                    // Permission Granted (calling our writeDataAndDownloadExcelFile function)<br>                    writeDataAndDownloadExcelFile();<br>                    console.log(&quot;Permission granted&quot;);<br>                } else {<br>                    // Permission denied<br>                    console.log(&quot;Permission denied&quot;);<br>                }<br>            } else {<br>                // Already have Permission (calling our writeDataAndDownloadExcelFile function)<br>                writeDataAndDownloadExcelFile();<br>            }<br>        } catch (e) {<br>            console.log(&#39;Error while checking permission&#39;);<br>            console.log(e);<br>            return<br>        }<br>    }<br>    return (<br>        <br>            &lt;View<br>                style={styles.mainView}&gt;<br>                &lt;TouchableOpacity<br>                    onPress={() =&gt; handleButtonClick()}<br>                    style={styles.button}&gt;<br>                    &lt;Text style={{ textAlign: &#39;center&#39;, color:&#39;#ffff&#39;, fontWeight: &#39;bold&#39; }}&gt;<br>                        Export Excel<br>                    &lt;/Text&gt;<br>                &lt;/TouchableOpacity&gt; <br>            &lt;/View&gt;<br>    );<br>}<br>const styles = StyleSheet.create({<br>    mainView:<br>    {<br>        display: &#39;flex&#39;,<br>        justifyContent: &#39;center&#39;,<br>        alignItems: &#39;center&#39;,<br>        flex: 1,<br>        backgroundColor:&#39;#155638&#39;<br>    },<br>    button:{<br>        width: &#39;50%&#39;,<br>        paddingVertical: 10,<br>        paddingHorizontal: 10,<br>        backgroundColor: &#39;#155638&#39;,<br>        marginVertical: 20,<br>        borderRadius: 5,<br>        borderColor: &#39;#ffff&#39;,<br>        borderWidth: 3<br><br>    }<br>})<br>export default DownloadExcelFile;</pre><p>( If anyone encounters an issue like the following:<br>Error [Error: ENOENT: open failed: EACCES (Permission denied), open ‘/storage/emulated/0/Download/XYZ.xlsx’]</p><p>I suggest deleting the existing Excel file named “XYZ.xlsx” from your mobile device. This should resolve the permission denied error.)</p><h3>Step 5: Final run</h3><pre><br>npx react-native run-android</pre><p>Thank you 😊</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e9827abe1124" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>