<?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 Tushar Rohilla on Medium]]></title>
        <description><![CDATA[Stories by Tushar Rohilla on Medium]]></description>
        <link>https://medium.com/@trohila10?source=rss-25549a17944------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*VfLN57UrJCSRqxCTG5-lMA.jpeg</url>
            <title>Stories by Tushar Rohilla on Medium</title>
            <link>https://medium.com/@trohila10?source=rss-25549a17944------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 17 Nov 2026 01:40:37 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@trohila10/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[Fixing error:EACCES in Android Q]]></title>
            <link>https://trohila10.medium.com/fixing-error-eacces-in-android-q-870c638c0c7f?source=rss-25549a17944------2</link>
            <guid isPermaLink="false">https://medium.com/p/870c638c0c7f</guid>
            <category><![CDATA[android]]></category>
            <category><![CDATA[error-handling]]></category>
            <category><![CDATA[android-app-development]]></category>
            <dc:creator><![CDATA[Tushar Rohilla]]></dc:creator>
            <pubDate>Tue, 16 Jun 2020 23:02:11 GMT</pubDate>
            <atom:updated>2021-02-19T19:27:52.511Z</atom:updated>
            <content:encoded><![CDATA[<h3>Fixing error: EACCES in Android Q</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2nFeTldp333kyu6MO0ZDAA.jpeg" /></figure><p>This blog explains how to tackle EACCES error in Android Q and above.</p><h3>Introduction</h3><p>Developing for Android is an amazing experience for every mobile developer because of the ultra-active developer community improving it day by day and bringing new features. Almost every year we see a new android version released by Google through their event Google I/O. The most recently released stable version of android is the <strong>Android 10(Q) </strong>or<strong> API Level 29</strong> as many devs call it.</p><p>While switching code to make it suited for the Android 10 running devices, one common error developers come across is <strong>Permission denied (EACCES)</strong>. This most commonly happens when the user needs permission to do some task (For example: Storage Access, Media/Image Access) which wasn’t the case in previous Android versions.</p><h3>When it happened</h3><p>It happened with me when I was contributing to a project in Android which could be able to determine if a plant has any disease or not, known as <a href="https://github.com/CapTen101/Crop-Analyzer-AI"><strong>CropAI</strong></a>. An Image upload was required and I stumbled on this issue. I tried to tackle it as a bug fix in the <a href="https://github.com/CropAi/Android-Application/pull/68">pull request</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/488/1*DmnUg7Bo8yc10r9Rzj-FuA.png" /></figure><p>According to the Official <a href="https://developer.android.com/training/data-storage#scoped-storage">Android Documentation</a>:</p><blockquote>On earlier versions of Android, apps needed to declare these permissions to access any file outside the <a href="https://developer.android.com/training/data-storage/app-specific#external">app-specific directories</a> on external storage. More recent versions of Android rely more on a file’s purpose than its location for determining an app’s ability to access that file. This purpose-based storage model improves user privacy because apps are given access only to the areas of the device’s file system that they actually use.</blockquote><p>Taking <strong>my use-case of uploading an image</strong> from the media gallery, we shall figure out how to solve the above problem. There are two ways to figure out a solution:</p><ul><li>Using “<a href="https://developer.android.com/preview/privacy/storage">requestLegacyExternalStorage</a>” as a temporary solution.</li><li>Using “<a href="https://developer.android.com/reference/android/os/ParcelFileDescriptor">ParcelFileDescriptor</a>” (a better, robust solution)</li></ul><h4>Using requestLegacyExternalStorage</h4><p>Switch the flag<strong> requestLegacyExternalStorage </strong>to<strong> true</strong> in the manifest file of your android project.</p><p>Here’s a word from the <a href="https://developer.android.com/preview/privacy/storage">Official Documentation</a>:</p><blockquote>To give developers additional time for testing, apps that target Android 10 (API level 29) can still request the <a href="https://developer.android.com/reference/android/R.attr#requestLegacyExternalStorage">requestLegacyExternalStorage</a> attribute. This flag allows apps to temporarily opt out of the changes associated with scoped storage, such as granting access to different directories and different types of media files. After you update your app to target Android 11, the system ignores the requestLegacyExternalStorage flag.</blockquote><pre>&lt;?xml ver ...&gt;<br>&lt;manifest xmlns:andro ...&gt;<br>    &lt;application <br>        android:requestLegacyExternalStorage = &quot;true&quot;&gt;<br>    ...<br>    &lt;/application&gt;<br>&lt;/manifest&gt;</pre><h4>Using ParcelFileDescriptor</h4><p>The idea behind this way is to make a copy of the file that the user picks in the media gallery and add it to your application cache directory, and then further use/process it as we would have in normal scenario.</p><ul><li>So, the first step is to open the file using a ParcelFileDescriptor object and create an InputStream from the choosen original file.</li><li>Now, give a name to your copied file and create an empty copy of the original file.</li><li>Create an OutputStream for the newly created file and then finally transfer the data from the original file to the newly created empty file.</li><li>Don’t forget to close the input and output streams. Get the file accessible in the form of a Uri.</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/77ff0d526b21f02db6550fe5e72ba8f0/href">https://medium.com/media/77ff0d526b21f02db6550fe5e72ba8f0/href</a></iframe><p>To get the path of the copied file, simply use the getPath method of the Uri class:</p><pre>image_path = copyImage.getPath();</pre><p>That’s it, we are done! Hope you liked it.</p><p>Peace out! 🙌</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=870c638c0c7f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Lookout — Air Quality Index app]]></title>
            <link>https://medium.com/mobile-development-group/lookout-air-quality-index-app-a59885eec085?source=rss-25549a17944------2</link>
            <guid isPermaLink="false">https://medium.com/p/a59885eec085</guid>
            <category><![CDATA[android]]></category>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[soc]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[air-pollution]]></category>
            <dc:creator><![CDATA[Tushar Rohilla]]></dc:creator>
            <pubDate>Wed, 10 Jun 2020 12:25:18 GMT</pubDate>
            <atom:updated>2020-06-12T17:08:24.670Z</atom:updated>
            <content:encoded><![CDATA[<h3>Lookout — Air Quality Index app</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vlsEeazQS6paJpPgekNT3Q.jpeg" /><figcaption>Increasing Pollution — Digital Art on <a href="https://wallup.net/pollution-digital-art-lungs/">Wallup</a></figcaption></figure><p>This blog encircles my entire (initially enticing 😛) journey of starting off with android development and then moving on to develop my very first android application using Java.</p><p>I participated in Season of Code ‘2019 (SOC) which is an annual competition organized by our institute’s <a href="https://medium.com/u/cb7bba2eb1b0">Mobile Development Group</a> every year to recruit students from freshmen and sophomore year. Though I couldn’t make for unfortunate reasons but it was a fantastic journey overall and I learnt a lot.</p><p>Link to the final application in my GitHub repository: <a href="https://github.com/CapTen101/Lookout-AQI-app">Lookout</a></p><h3>Inspiration</h3><p>The first task for us participants was to draft a proposal with an idea for an app and an essential point to include was to <strong>why </strong>we want to go forward with this idea.</p><p>It was pretty easy for me figuring out an idea since I always wanted to make such an application through which (in some way) I could help my parents. A <strong>little heads up</strong>, I live in Delhi-NCR in India and air pollution has long been an issue with the country’s capital region. I still remember suggesting my dad to shift to some other place and settling there. This was, of course, not possible given the professional constraints.</p><p>Building an app which constantly monitors and shows the user the latest info about air pollution and could also suggest suitable precautions? <strong>Boom </strong><a href="https://hotemoji.com/boom-emoji.html"><strong>💥</strong></a><strong> idea is ready!</strong></p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FCjmvTCZf2U3p09Cn0h%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2FCjmvTCZf2U3p09Cn0h%2Fgiphy.gif&amp;image=https%3A%2F%2Fi.giphy.com%2Fmedia%2FCjmvTCZf2U3p09Cn0h%2Fgiphy.gif&amp;key=d04bfffea46d4aeda930ec88cc64b87c&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="409" frameborder="0" scrolling="no"><a href="https://medium.com/media/299d92410c85baea4abbb6ad6d7f7285/href">https://medium.com/media/299d92410c85baea4abbb6ad6d7f7285/href</a></iframe><p>Link to my proposal: <a href="https://drive.google.com/file/d/1oBOvZYt0FXkTyIR1OGZMgX-tzRMFf5BZ/view?usp=sharing">SOC: Lookout proposal</a></p><h3>Design — UI/UX and Layout</h3><p>I used <a href="https://medium.com/u/bf1152b11387"><strong>Figma</strong></a> for designing my application prototype. Honestly, Figma is awesome and is my go-to tool for any kind of UI/UX task which I need to accomplish. Being my first ever project involving designing work, I studied the basics.</p><p>Link to my Figma board: <a href="https://www.figma.com/file/Z0FV3aVkKY2NUrLvSg4j3s/MDG-SoC?node-id=0%3A1">design board</a>. The <a href="https://medium.com/@hichristineyeh/a-primer-on-ux-design-for-people-who-are-completely-new-to-ux-a5f0db3b71fe"><strong>UI-UX Primer</strong></a> is an amazing blog written by <a href="https://medium.com/u/e795fea396a4"><strong>Christine Yeh</strong></a> and is a good resource for someone who is just getting started.</p><h3>Starting with the basics</h3><p>I started off the <strong>Udacity Android-Basics NanoDegree</strong> courses for learning android and they are amazing for anyone who wants to start off with android. I’ll mention them in their further coming respective sentences. They develop your concepts right from the basics like: l<a href="https://classroom.udacity.com/courses/ud834">ayouts, views and<strong> </strong>basic<strong> android UI components</strong></a> to the advanced stuff like <a href="https://classroom.udacity.com/courses/ud845"><strong>Data Storage</strong></a> and <a href="https://classroom.udacity.com/courses/ud843"><strong>Networking</strong></a>.</p><p>Then comes basic programming tasks revolving around OOPS(Object Oriented Programming Language) in Java, Gradle, adding logic to your app and <a href="https://classroom.udacity.com/courses/ud836"><strong>taking input from the user</strong></a>. I used <strong>Android Studio</strong> as my primary IDE for developing the app. It’s a feature-packed IDE by JetBrains having tons of features to develop a nice and robust android application.</p><p>I also formulated a <strong>layout</strong> for the working of my project before entering the development phase:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HPVwbr8ulPLxGBpB372GoQ.jpeg" /><figcaption>The layout for my app</figcaption></figure><h3>Development Phase</h3><p>Then came the development phase when I finished all the tutorials and started off with the coding of the application.</p><p>The frontend of the app is created through XML (Extensible Markup Language) in the form of XML layout files. Check official guide from Google on XML user interfaces for android <a href="https://developer.android.com/guide/topics/ui/declaring-layout">here</a>.</p><p>I used the <strong>BottomNavigationView</strong> Activity style as I had three independent type of screens to show to the user including the home page, AQI page for searching cities(where the user will spend the most time) and finally the screen for showing a world map wherein all cities are marked by different colours (according to their AQI).</p><h4>API</h4><p>One major component the application requires for functioning is an API (Application Programming Interface). According to <a href="https://simple.wikipedia.org/wiki/Application_programming_interface">Wikipedia</a> :</p><blockquote>An <strong>Application Programming Interface</strong> <strong>(API)</strong> is a set of functions, procedures, methods or classes used by computer programs to request services from the operating system, software libraries or any other service providers running on the computer. A computer programmer uses the API to make application programs.</blockquote><p>Here I’ve used <a href="https://www.iqair.com/air-pollution-data-api">Airvisual</a> and <a href="https://aqicn.org/api/">AQICN</a> API. Both these organisations have hardware components in various cities across the world feeding live data into the server which the Api fetches for us. Consuming data from an API requires an <strong>HTTP operation</strong>. The primary and most-commonly-used HTTP operations (or methods, as they are properly called) are <strong>POST</strong>, <strong>GET</strong>, <strong>PUT</strong>, <strong>PATCH</strong>, and <strong>DELETE</strong>. You can get to know more about these <a href="https://www.restapitutorial.com/lessons/httpmethods.html">here</a>.</p><p>To use the API, our application requires Networking implementation. We have many libraries available in Android for making networking calls over the internet. The most famous ones are <a href="https://square.github.io/retrofit/"><strong>Retrofit</strong></a>, <a href="https://docs.oracle.com/javase/8/docs/api/java/net/HttpURLConnection.html"><strong>HttpURLConnection</strong></a> and <a href="https://square.github.io/okhttp/"><strong>OkHTTP</strong></a>. HttpURLConnection is the one more basic and old among them. I used HttpURLConnection for my work. Code follows:</p><pre>urlConnection = (HttpURLConnection) url.openConnection();                                   urlConnection.setRequestMethod(&quot;GET&quot;);                                   urlConnection.setRequestProperty(&quot;Authorization&quot;, &quot;Token xxxxxxxx&quot;);                                   urlConnection.setRequestProperty(&quot;Content-Type&quot;, &quot;application/json&quot;);                                   urlConnection.connect();</pre><p>According to the <a href="https://developer.android.com/training/basics/network-ops/connecting">official Android documentation</a> networking calls cannot be made directly through the <strong>UI thread </strong>instead it required asynchronous calls:</p><blockquote>To avoid creating an unresponsive UI, don’t perform network operations on the UI thread. By default, Android 3.0 (API level 11) and higher requires you to perform network operations on a thread other than the main UI thread; if you don’t, a NetworkOnMainThreadException is thrown.</blockquote><h4>Asynchronous Operations</h4><p>Here, at this point, I was introduced to the concept of threads and asynchronous (short for ASync) operation. This is something with which every developer is familiar since it’s an essential part of many background operations of applications and software.</p><p>Asynchronous ops is essential in a way because you don’t want to block your UI if (let’s say) an image is not downloaded? or maybe some data is not fetched from the database yet? Async operations use a simultaneous yet entirely separate thread for communicating with an external service (most commonly Database and networking calls). Hence they don’t interfere with the main(UI) thread and update it whenever the data is ready.</p><p>There are many ways to implement Asynchronous operations in Android and one of them is <a href="https://developer.android.com/reference/android/os/AsyncTask"><strong>AsyncTask</strong></a><strong> </strong>(though it’s deprecated now).</p><pre>class DownloadFilesTask extends AsyncTask &lt;URL, Integer, Long&gt; {</pre><pre>protected Long doInBackground(URL... urls) {</pre><pre>//   this function executes the desired Async operation which cannot    //   be performed on UI thread.</pre><pre>}</pre><pre>     protected void onProgressUpdate(Integer... progress) {</pre><pre>//   executed if any any operation has to be done on the data       //   obtained from the ASync call.</pre><pre>}</pre><pre>     protected void onPostExecute(Long result) {</pre><pre>//   this function returns the final data obtained after the ASync //   call.</pre><pre>}<br> }</pre><p>This above Asynchronous operation can be triggered through:</p><pre>new DownloadFilesTask().execute(url1, url2, url3);</pre><h4>Search functionality using ArrayAdapter</h4><p>In this app, user can search the name of the city he/she wants to see the AQI. The order goes like this as seen in the flowchart shown: Country name then it’s states followed by the chosen state’s cities.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VSY3tP_Bins5f5rqewY7rg.jpeg" /><figcaption>Flowchart made on <a href="http://miro.com/">Miro</a></figcaption></figure><p><strong>ArrayAdapter</strong> is used to transfer the <strong>Arraylist</strong> data to a dropdown.:</p><pre>ArrayAdapter&lt;String&gt; Country = new ArrayAdapter&lt;&gt;(getActivity(), android.R.layout.simple_dropdown_item_1line, countryList);<br>countrySearch.setAdapter(adapterCountry);</pre><h4>World Map page</h4><p>To display maps in android apps, the best way is to use the <a href="https://developers.google.com/maps/documentation/android-sdk/intro">Maps API</a> of the Google Maps Android SDK. It provides a ton of features and is pretty easy to use given the methods. <strong>SupportMapFragment</strong> class enables us to implement the maps:</p><pre>SupportMapFragment mapFragment = getSupportFragmentManager()<br>                                .findFragmentById(R.id.map);        mapFragment.getMapAsync(this);</pre><p><strong>OnMapReady</strong> method needs to be overridden in order to control various features of the maps. For example: using custom markers, zoom to a particular coordinate at the start etc.</p><p>This is what the app looked at the end:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/540/1*vYy4IfJR0FpvnxdpZHkiBw.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/540/1*NIgn_Vf1Y4tssMG3zx1MMA.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*W8ntFRgbxHKaFKKDmdvWwg.jpeg" /></figure><p>So, that’s pretty much it! Thanks for staying till the end and share if you like it 😄</p><p>Peace out 🙌</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a59885eec085" width="1" height="1" alt=""><hr><p><a href="https://medium.com/mobile-development-group/lookout-air-quality-index-app-a59885eec085">Lookout — Air Quality Index app</a> was originally published in <a href="https://medium.com/mobile-development-group">MDG Space</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Cerr — Error Stream Object in C++]]></title>
            <link>https://medium.com/swlh/cerr-error-stream-object-in-c-9d62d564e72c?source=rss-25549a17944------2</link>
            <guid isPermaLink="false">https://medium.com/p/9d62d564e72c</guid>
            <category><![CDATA[error-handling]]></category>
            <category><![CDATA[programming-languages]]></category>
            <category><![CDATA[cplusplus]]></category>
            <dc:creator><![CDATA[Tushar Rohilla]]></dc:creator>
            <pubDate>Sun, 07 Jun 2020 14:02:55 GMT</pubDate>
            <atom:updated>2020-06-08T13:51:06.155Z</atom:updated>
            <content:encoded><![CDATA[<h3>Cerr — Error Stream Object in C++</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*R0XzdzpssugFhLonM0_c-g.png" /><figcaption><a href="https://www.atlassian.com/blog/statuspage/error-pages">Error Page</a></figcaption></figure><h3>Introduction</h3><p>This article tries to throw some light on (often ignored) cerr Object in C++. The ‘c’ in cerr means “character” and ‘err’ means “error”, hence cerr means “character error”.</p><p>It is defined in iostream header file and it corresponds to the C stream stderr. It has a very similar usage to the cout object (i.e. printing characters on the console during runtime) under the stream stdout.</p><h3>The Difference</h3><p>Even though the result of both cout and cerr is same, there is a very subtle difference between the two which we can find in the use-case of the above both streams.</p><p>Here a sample code to show the difference between the two:</p><pre>#include&lt;bits/stdc++&gt;<br>using namespace std;<br>int main()<br>{</pre><pre>cout &lt;&lt; &quot;Hey there, Geek! :: cout&quot; &lt;&lt; endl;</pre><pre>cerr &lt;&lt; &quot;Hey there, Geek! :: cerr&quot; &lt;&lt; endl;</pre><pre>return 0;</pre><pre>}</pre><p>Both the statements above will print characters but under different consoles/context. Have a look at the output.</p><p><strong>Output:</strong></p><pre>Hey there, Geek! :: cout</pre><p><strong>Runtime Error:</strong></p><pre>Hey there, Geek! :: cerr</pre><h3>So, what can be derived from their usage?</h3><p>Generally, stdout::cout<strong> </strong>should be used for<strong> actual program output</strong>, while all information and <strong>error messages </strong>should be printed to<strong> </strong>stderr::cerr.</p><p>For example: Let’s say the user wants to open a file and redirect output to that external file. Assume that during the program execution (due to some problem) file opening throws an error. To keep a check of such errors the developer has to <strong>log </strong>the error somewhere to check it later. He can use cerr since that error is still printed while not being an ouput to the console or the output file.</p><p>Let’s see an example program for that:</p><pre>#include &lt;iostream&gt;<br>#include&lt;fstream&gt;<br>using namespace std;<br>int main()</pre><pre>{</pre><pre>char fileName[] = &quot;data.txt&quot;;</pre><pre>// Opening a file using the infile object of ifstream class in fstream header file<br>ifstream infile(fileName);</pre><pre>// If the file exists, start reading from the file</pre><pre>if(infile)<br>cout &lt;&lt; infile.rdbuf();</pre><pre>// If any problem occurs, this message is shown as a error.<br>// This way, user can clearly diffrenciate between legit output and //errors in their code.</pre><pre>else<br>cerr &lt;&lt; &quot;Error while opening the file &quot; &lt;&lt; fileName &lt;&lt;endl;</pre><pre>return 0;</pre><pre>}</pre><p>Thanks!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9d62d564e72c" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swlh/cerr-error-stream-object-in-c-9d62d564e72c">Cerr — Error Stream Object in C++</a> was originally published in <a href="https://medium.com/swlh">The Startup</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>