<?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 Rishikesh Pathak on Medium]]></title>
        <description><![CDATA[Stories by Rishikesh Pathak on Medium]]></description>
        <link>https://medium.com/@sauge16?source=rss-49083635e554------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*g6GXSRcUz2SUsHfB-M1HBA.jpeg</url>
            <title>Stories by Rishikesh Pathak on Medium</title>
            <link>https://medium.com/@sauge16?source=rss-49083635e554------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 20:42:45 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@sauge16/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[Exploring Android APK in Android 10( API level 29)]]></title>
            <link>https://medium.com/android-aosp-geeks/exploring-android-apk-in-android-10-api-level-29-c9e175f971e?source=rss-49083635e554------2</link>
            <guid isPermaLink="false">https://medium.com/p/c9e175f971e</guid>
            <category><![CDATA[apk]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[androidmanifest]]></category>
            <category><![CDATA[android-apps]]></category>
            <category><![CDATA[android-app-development]]></category>
            <dc:creator><![CDATA[Rishikesh Pathak]]></dc:creator>
            <pubDate>Sat, 14 Dec 2019 18:46:39 GMT</pubDate>
            <atom:updated>2019-12-14T18:46:39.137Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/932/1*T5dCQwQNb2WpyEW_E5NIXA.png" /></figure><p>If you are using an Android phone you will likely have heard of an APK file at some point.<br>So basically Android Package Kit (APK) is the package file format used by the Android operating system for distribution and installation of mobile apps. Every application installed in your Android Phone is being downloaded in .apk format.</p><blockquote>What an Android APK Contains?</blockquote><p>Let&#39;s take an example, I have made a Sample Application using <a href="https://developer.android.com/studio/">Android Studio</a> and got an APK with compile and taget SDK version 29, named as “<strong>app-debug.apk” </strong>having package name<strong> “com.aospgeeks.sample”. <br></strong>We will extract that APK as we <a href="https://support.microsoft.com/en-in/help/14200/windows-compress-uncompress-zip-files">extract</a> any other .zip/.rar file. To Extract an APK lets rename the extension as .rar and than we can extract it. Below is file structure we got after extraction:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/828/1*8OqRpuNP3ts0AW2gQ_Lr8Q.png" /></figure><p>Your APK may contain more items like assets,lib etc. It depends on what you have included in your project. Above one is small project example. We will elaborate all one by one from downward directions,</p><p><strong>resources.arsc:</strong> <br>This <em>resources.arsc</em> file contains all the meta-information about the resources and the xml nodes(e.g. LinearLayout, FrameLayout, etc) and their attributes(e.g. <em>android:layout_height</em>) including their ids. These ids reference into the actual resources in the apk-file. These are resolved to a value at runtime.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/878/1*7WrGfqvhnUAPk8vyVzsdOA.png" /><figcaption><strong>the resource items available in resource.arsc file</strong></figcaption></figure><p><strong>classes.dex and classes2.dex: <br></strong> Android programs are compiled into .dex (Dalvik Executable) files,<br>The DEX byte code format is translated to native machine code via either ART or the Dalvik runtimes. Here DEX bytecode is independent of device architecture. So, basically <strong>classes.dex </strong>file contains all the java classes in .dex format if you observe below two photos, <strong>classes.dex </strong>containing all library/sdk classes and <strong>classes2.dex</strong> containing your application classes along with some support library classes.</p><blockquote>Note: An APK can contain Multiple dex files</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/885/1*-Fg3G-kVVnchBv8e1_-erQ.png" /><figcaption><strong>classes.dex</strong></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/889/1*9Nu5UDnAURszRSlUSEzY4w.png" /><figcaption><strong>classes2.dex</strong></figcaption></figure><p><strong>AndroidManifest.xml:<br></strong>AndroidManifest contains all your application configuration, components and permission requirements that you provided while creating your application. It is same that you written for your application.</p><p><strong>res:<br></strong>If you will open <strong>res </strong>folder you will find all <em>drawable, layout, anim, color, mipmap, etc </em>folder inside as given in below image.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/539/1*vver2aqItnl4rGd0lt0KKw.png" /></figure><p>Basically, it contains all .xml and .png files that you provided in your project while writing your application.</p><p><strong>META-INF:<br></strong>META_INF folder contains application signature details which look like below when you open it:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/951/1*n5gaGoLV_JDDUZxdYtFfSQ.png" /></figure><p>We will mainly discuss about MANIFEST.MF, CERT.SF and CERT.RSA.</p><ul><li><strong>MANIFEST.MF:</strong> <br> It stores the message digests of all source files in the apk to prevent their integrity from tampering. Enumerate all the files, calculate their message digest, and finally convert all digests to base64-encoded binary value.<br> The default digest used is <a href="http://en.wikipedia.org/wiki/SHA-1">SHA-1</a>.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/674/1*cdWrMlrX6JRq6KtPQjbSIw.png" /><figcaption><strong>MANIFEST.MF</strong></figcaption></figure><ul><li><strong>CERT.SF:</strong> <br>This is similar to MANIFEST.MF but it stores the base64-encoded codes of MANIFEST.MF’s message digest, and the message digests of all the digests stored in MANIFEST.MF.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/878/1*nw9pgsQV-zYj_JihJom4ig.png" /><figcaption><strong>CERT.SF</strong></figcaption></figure><blockquote>In a simple terms, CERT.SF is similar to the MANIFEST.MF file, except that instead of the SHA1 hash of the contents for a file, it lists a SHA1 hash of the lines for the file from the MANIFEST.MF file.</blockquote><p>The “TTYx9NO2OS5ScAuB+LNG2A/b/qOXlBalU5dDggHMXPA=” you see in CERT.SF for Name AndroidManifest.xml is the SHA1 hash of this string from MANIFEST.MF <br>“Name: AndroidManifest.xml<br>SHA-256-Digest: hOQuzwEFzVI1wPTsLkTULBwOa15M5p2Jdpor9G6fVc0=”</p><ul><li><strong>CERT.RSA:</strong> <br>It stores the digital signature of CERT.SF, as well as the certificate used for signing.<br>It can be viewed by below command:<br>“<em>keytool -printcert -file CERT.RSA”<br></em>It contains<em> </em>Owner details such as (Email, Company details), Issuer details, Serial number, Valid from, Valid Until, Certificate fingerprints, Signature algorithm name, Subject Public Key Algorithm, Extensions.</li></ul><p><em>If you liked my story please click on clap icon and if you want to read future stories by me related to Android Development please follow me </em>and publication. :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c9e175f971e" width="1" height="1" alt=""><hr><p><a href="https://medium.com/android-aosp-geeks/exploring-android-apk-in-android-10-api-level-29-c9e175f971e">Exploring Android APK in Android 10( API level 29)</a> was originally published in <a href="https://medium.com/android-aosp-geeks">Android(AOSP) Geeks</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Android Instant Apps,All you need to know about..]]></title>
            <link>https://medium.com/hackernoon/android-instant-apps-all-you-need-to-know-about-d392a6e10584?source=rss-49083635e554------2</link>
            <guid isPermaLink="false">https://medium.com/p/d392a6e10584</guid>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[android-instant-apps]]></category>
            <category><![CDATA[androiddev]]></category>
            <category><![CDATA[google]]></category>
            <dc:creator><![CDATA[Rishikesh Pathak]]></dc:creator>
            <pubDate>Sat, 02 Sep 2017 06:48:49 GMT</pubDate>
            <atom:updated>2019-05-17T10:06:38.123Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*Cdb4uoqwa1T2Fn9ClGi9lQ.jpeg" /><figcaption>Google I/O 2017</figcaption></figure><blockquote>Native Android apps, without the installation.</blockquote><p><strong>1. What is Android Instant Apps?</strong></p><p>As a Developer ever thought to bring users into your apps more quickly and easily.</p><p>Android Instant Apps allows Android users to run your apps instantly, without installation. Android users experience what they love about apps — fast and beautiful user interfaces, high performance, and great capabilities — with just a tap.</p><p><strong>2. Why you need to make Android Instant Apps?</strong></p><p>You can let user try few feature of your native app without installing and they can download installable version when they want.So this brings more customers to your app.</p><p><strong>3. How to make Android Instant Apps?</strong></p><blockquote><strong>Note</strong>:Android Instant Apps only work on Android devices running on Android 6.0 (API level 23) or higher</blockquote><p>Android Instant Apps enables native Android applications to run in response to launching a URL, without installing the app. Instant apps can use many Android APIs and you use Android Studio to build them.</p><h4>Development environment for Android Instant Apps</h4><ul><li>JDK 1.8</li><li><a href="https://developer.android.com/studio/preview/index.html">Android Studio version <strong>3.0 or later</strong></a></li><li>Android SDK 6.0+</li><li>Android SDK Build Tools 26.x or later</li><li>Android SDK Tools 25.x or later</li><li>Android SDK Platform Tools 25.x or later</li></ul><p><strong>Instant Apps Development SDK</strong>.</p><ol><li>Open the Android SDK Manager by clicking <strong>Tools &gt; Android &gt; SDK Manager</strong>.</li><li>Click the <strong>SDK Tools</strong> tab.</li><li>From the list, select <strong>Instant Apps Development SDK</strong>.</li><li>Click <strong>Apply</strong>.</li><li>Click <strong>Finish</strong>.</li></ol><p>opt-in to Android Instant apps in the Settings app of your device by going to <strong>Google &gt; Instant Apps</strong>. Note that if you do not opt-in, developer mode does not work on the device. The first time you navigate to a instant app, the system automatically asks you to opt-in.</p><p>With Android Instant Apps, users can use a single feature of an app without having to install the app with all its other features. Each feature within the instant app should have at least one Activity that acts as the <em>entry-point</em> for that feature. you need to break up your app into smaller modules and refactor them into <em>feature modules</em>.</p><p>Every instant app must have one (and only one) <em>base feature APK</em>. You can have feature APKs in addition to your <em>base feature</em> APK ,If your Instant app has more features.</p><p>When users request a feature from an instant app, they get two feature APKs: the corresponding feature APK and the base feature APK. If the same user requests another feature from the same instant app, they might receive just the feature APK because they have already downloaded the base feature APK. Of course, if the instant app only has one feature — and thus only a base feature APK — users only receive the base feature APK.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-yWWiJhzFl-V4N5x2FQP4g.png" /><figcaption>source: developer.android.com</figcaption></figure><p>To download a feature of an instant app from <a href="https://hackernoon.com/tagged/google">Google</a> Play, users need only to click a link. After Google Play finds an instant app that matches the link requested by the user, Google Play sends the corresponding feature APKs for that feature to the user’s device and the Android system then launches the feature. If Google Play cannot find a match, it alerts the Android system. The system then broadcasts an intent to the system to handle the URL.</p><p>For this reason, each entry-point activity in an instant app needs to be <em>addressable</em>: it needs to correspond to a unique URL address. To provide a unique URL address for each feature, the instant app specifies a different path underneath the domain for each feature.</p><p><em>Ex: <br>Feature “News” : </em><a href="http://example.com/news"><em>http://example.com/new</em></a><em>s<br> Feature “Horoscope” : </em><a href="http://example.com/news"><em>http://example.com/</em></a><em>horoscope</em></p><p>Suppose your app show news by particular city in this case your URL matches</p><p><em>Ex:<br></em>All news : <a href="http://example.com/news">http://example.com/news</a><br>Bangalore News : <a href="http://example.com/news/bangalore.">http://example.com/news/bangalore.</a></p><p>The URL address for the CityNews activity is similar to the AllNews activity except that the CityNews activity has a city appended to the URL.</p><p>The manifest for the feature needs to specify both a path for each activity and a priority order for the activities, in case of multiple matches.</p><p>1.Activity Name :AllNewsActivity , url address : <a href="http://example.com/news">http://example.com/news</a> ,priority:1<br>2. Activity Name :CityNewsActivity , url address : <a href="http://example.com/news">http://example.com/news</a>/bangalore , priority:100</p><p>If Google Play received a request for the URL ‘http://example.com/<a href="http://example.com/news">news</a>/abab&#39;, it matches both the AllNews and the CityNews activity. Google Play needs to pick one of the two activities as the starting point for the feature. Because the instant app specifies that the CityNews activity has a higher priority than the AllNews activity, Google Play specifies to the system to start the feature from the CityNews activity</p><p>So your manifest will be like</p><pre>&lt;application&gt;<br>    &lt;activity android:name=&quot;.AllNewsActivity&quot;&gt;<br>        &lt;intent-filter android:order=&quot;1&quot;&gt;<br>            &lt;action android:name=&quot;android.intent.action.VIEW&quot; /&gt;<br>            &lt;category android:name=&quot;android.intent.category.BROWSABLE&quot; /&gt;<br>            &lt;category android:name=&quot;android.intent.category.DEFAULT&quot; /&gt;<br>            &lt;data android:host=&quot;<a href="http://example.com/news"><em>example.com/new</em></a><em>s</em>&quot;<br>                android:path=&quot;/&quot;<br>                android:scheme=&quot;https&quot; /&gt;<br>        &lt;/intent-filter&gt;<br>        &lt;intent-filter&gt;<br>            &lt;action android:name=&quot;android.intent.action.MAIN&quot; /&gt;<br>            &lt;category android:name=&quot;android.intent.category.LAUNCHER&quot; /&gt;<br>        &lt;/intent-filter&gt;<br>    &lt;/activity&gt;<br>&lt;/application&gt;</pre><p>Here, “android:order” is priority.<br>For creating Instant app in Android studio,</p><ol><li>Start a new project</li></ol><p>2. In the <strong>Minimum SDK</strong> list, select <strong>API 23: Android 6.0 (Marshmallow)</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PtNPSTMH1vDYzntiRlZvOQ.png" /><figcaption>source: developer.android.com</figcaption></figure><p>3. Under the <strong>Minimum SDK</strong> list, check <strong>Include Android Instant app support</strong>.</p><p>4. Select an Activity.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RfYFQfR6IOTcq2W3qXmlHA.png" /><figcaption>source: developer.android.com</figcaption></figure><p>5. In the <strong>Configure Activity</strong> window, do the following:</p><ul><li>In the <strong>Instant App URL Host</strong> box, enter ‘myfirstinstantapp.example.com’.</li><li>In the <strong>Instant App URL</strong> route box, enter ‘/hello’.</li></ul><p>6.Finish and Run.</p><p>For more details about creating feature module you can see <a href="https://codelabs.developers.google.com/codelabs/android-instant-apps/#0">Google codelabs</a>.</p><blockquote><strong>Note:</strong> When you run your app locally on a device or emulator, the Android system displays the default placeholder icon for your app. Once you have deployed your Instant App APK to the Google Play Console, the appropriate icon shows up when the instant app launches.</blockquote><p>Android Instant Apps uses the runtime permission model introduced in Android 6.0 (API level 23).Instant apps can use the Android permissions shown in the list that follows. Any permission not shown in the list is not available to instant apps.</p><ul><li>BILLING</li><li>ACCESS_COARSE_LOCATION</li><li>ACCESS_FINE_LOCATION</li><li>ACCESS_NETWORK_STATE</li><li>CAMERA</li><li>INSTANT_APP_FOREGROUND_SERVICE only in Android O.</li><li>INTERNET</li><li>READ_PHONE_NUMBERS only in Android O.</li><li>RECORD_AUDIO</li><li>VIBRATE</li></ul><blockquote><strong>Note 1</strong>: All <a href="https://hackernoon.com/tagged/network">network</a> traffic from inside the instant app must use HTTPS. Instant Apps does not support HTTP.</blockquote><blockquote><strong>Note 2</strong>: The sum of the base feature and the feature APK must be under 4MB.</blockquote><blockquote><strong>Note 3</strong>: Since App Links are regular URLs, apps can force them to be opened inside an in-app browser. Consider using <a href="https://firebase.google.com/docs/dynamic-links/">Firebase Dynamic Links</a> to wrap your URLs and guarantee that clicks on your links always take users to your instant app.</blockquote><h4>You can follow sample code provided by google</h4><ol><li><em>Hello World sample app</em><br>This sample app demonstrates how to build an installed app and an instant app with the same behaviors. <a href="https://github.com/googlesamples/android-instant-apps/tree/master/hello">Get it on GitHub</a></li><li><em>Hello multi feature module sample app</em><br>This sample app builds upon the Hello World sample app by moving its code into two feature modules. These modules can be run independently. <a href="https://github.com/googlesamples/android-instant-apps/tree/master/hello-feature-module">Get it on GitHub</a></li><li><em>Multi feature module sample app<br></em>This sample app demonstrates how to build an installed app and an instant app with the same behaviors. The functionality of the instant app is split in two features that you can launch individually on a device. <a href="https://github.com/googlesamples/android-instant-apps/tree/master/multi-feature-module">Get it on GitHub</a></li><li><em>Build flavors sample app<br></em>This sample app demonstrates how to build an installed app and an instant app with the same behaviors. The functionality of the instant app is split in two features that you can launch individually on a device.This sample also uses the concept of build flavors, providing both a “paid” and “free” version of the app. <a href="https://github.com/googlesamples/android-instant-apps/tree/master/flavors">Get it on GitHub</a></li><li><em>Google Analytics for Firebase sample app<br></em>This sample app demonstrates how to build an installed app and an instant app with the same behaviors. The app integrates Google Analytics for Firebase event logging into both the installed and instant app, demonstrating how to differentiate events raised in the two versions of the app. <a href="https://github.com/googlesamples/android-instant-apps/tree/master/analytics">Get it on GitHub</a></li></ol><p>If you liked my story please click on clap icon and if you want to read future stories by me related to Android Development please follow me.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fupscri.be%2Fdde502%3Fas_embed%3Dtrue&amp;dntp=1&amp;url=https%3A%2F%2Fupscri.be%2Fhackernoon%2F&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=upscri" width="800" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/3c851dac986ab6dbb2d1aaa91205a8eb/href">https://medium.com/media/3c851dac986ab6dbb2d1aaa91205a8eb/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d392a6e10584" width="1" height="1" alt=""><hr><p><a href="https://medium.com/hackernoon/android-instant-apps-all-you-need-to-know-about-d392a6e10584">Android Instant Apps,All you need to know about..</a> was originally published in <a href="https://medium.com/hackernoon">HackerNoon.com</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[FileUriExposed Exception?]]></title>
            <link>https://medium.com/@sauge16/targetting-sdkversion-24-android-nougat-and-above-and-sharing-file-through-intent-3f0f0128fa7e?source=rss-49083635e554------2</link>
            <guid isPermaLink="false">https://medium.com/p/3f0f0128fa7e</guid>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[android-apps]]></category>
            <dc:creator><![CDATA[Rishikesh Pathak]]></dc:creator>
            <pubDate>Mon, 08 May 2017 09:20:45 GMT</pubDate>
            <atom:updated>2017-09-11T14:49:45.977Z</atom:updated>
            <content:encoded><![CDATA[<blockquote>Android may throw “ FileUriExposedException” in Android 7.0 (API level 24) and above,this exception will come when you will expose a file:// URIs outside your package domain through intent .</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/442/1*UEvjdKh4ln3u11dENKgDkA.png" /></figure><p>For apps targeting Android 7.0, the Android framework enforces the strict mode API policy that prohibits exposing file:// URIs outside your app. If an intent containing a file URI leaves your app, the app fails with a <strong>FileUriExposedException</strong>.</p><p>Your Exception will be like this:</p><pre>08-05 17:30:00.476 22265-22265/ com.example.file</pre><pre>E/AndroidRuntime: FATAL EXCEPTION: main<br>                                                                  Process: com.example.file, PID: 22265<br>                                                                               android.os.FileUriExposedException: file:///storage/emulated/0/example/ profilePic.jpg exposed beyond app through ClipData.Item.getUri()<br>......</pre><p>So wondering how to avoid this exception then follow below steps:</p><blockquote>Note:Considering you already given Runtime Permission for Camera and Storage.</blockquote><p><strong>Step 1:</strong></p><p>You have to define a FileProvider for your app for that you have to give &lt;provider&gt; element in your manifest see example.</p><pre>&lt;manifest xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;<br>    package=&quot;com.example.file&quot;&gt;<br>    &lt;application<br>        ...&gt;<br>        &lt;provider<br>           android:name=&quot;android.support.v4.content.FileProvider&quot;<br>           android:authorities=&quot;com.example.file.provider&quot;<br>           android:exported=&quot;false&quot;<br>           android:grantUriPermissions=&quot;true&quot;&gt;<br>       &lt;meta-data<br>           android:name=&quot;android.support.FILE_PROVIDER_PATHS&quot;<br>           android:resource=&quot;@xml/file_provider_path&quot;/&gt;<br>       &lt;/provider&gt;<br>        ...<br>    &lt;/application&gt;<br>&lt;/manifest&gt;</pre><p>Here authorities name should be unique thats why i used package name +.provider.</p><p>And the &lt;meta-data&gt; child element of the &lt;provider&gt; points to an XML file that specifies the directories you want to share.</p><p><strong>Step 2:</strong></p><p>Create file_provider_path.xml in the res/xml/ subdirectory of your project.</p><pre><em>&lt;?</em><strong>xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;</strong><em>?&gt;<br></em>&lt;<strong>paths xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;</strong>&gt;<br>    &lt;<strong>external-path name=&quot;image_capture&quot; path=&quot;example/&quot; </strong>/&gt;<br>&lt;/<strong>paths</strong>&gt;</pre><p>Here i am giving file name “example” of external storage.if your file path is in internal storage then you can give &lt;files-path&gt; element in place of &lt;external-path&gt;</p><p><strong>Step 3:</strong></p><p>Now for sending file:// uri to other app i will take example to open Camera App ,</p><p>For getting URI earlier we used to do like this</p><pre>Uri photoURI = Uri.fromFile(file);</pre><p>So we have to do like this now</p><pre>Uri photoUri =     FileProvider.<em>getUriForFile</em>(Context,<strong>&quot;</strong>com.example.file.provider<strong>&quot;</strong>, file);</pre><p>check below example:</p><pre>String <strong>fileName </strong>= &quot;profilePic&quot;;<br><br><strong>String path = </strong>Environment.<em>getExternalStorageDirectory</em>().getAbsolutePath()+ <strong>&quot;/example&quot;</strong>;<br><br>File file = <strong>new </strong>File(<strong>path</strong>,<strong>fileName</strong>+<strong>&quot;.jpg&quot;</strong>);<br><br>Intent intent = <strong>new </strong>Intent(MediaStore.<strong><em>ACTION_IMAGE_CAPTURE</em></strong>);</pre><pre>//We have to check if it&#39;s nougat or not.</pre><pre><strong>if </strong>(Build.VERSION.<strong><em>SDK_INT </em></strong>&gt; Build.VERSION_CODES.M)<br>{</pre><pre>Uri photoUri =     FileProvider.<em>getUriForFile</em>(Context,<strong>&quot;</strong>com.example.file.provider<strong>&quot;</strong>, file);<br><br>  intent.putExtra(MediaStore.<strong><em>EXTRA_OUTPUT</em></strong>, photoUri);<br>}<br><strong>else<br></strong>{</pre><pre>intent.putExtra(MediaStore.<strong><em>EXTRA_OUTPUT</em></strong>, Uri.<em>fromFile</em>(file));<br><br>}<br><br><br><br>intent.addFlags(Intent.<strong><em>FLAG_GRANT_READ_URI_PERMISSION</em></strong>);<br><br><br><br><strong>if </strong>(intent.resolveActivity(getApplicationContext().getPackageManager()) != <strong>null</strong>) {<br><br>    startActivityForResult(intent, <strong>REQUEST_CODE_CAMERA</strong>);<br><br>}</pre><p>Ya that’s it,So FileProvider will return following URI</p><p><em>content://com.example.file.provider/image_capture/profilePic.jpg</em></p><p>that is nothing but combination of these:</p><p><em>content://”android:authorities you give to provider in manifest”/”&lt;external-path name&gt;, you given in file_provider_path.xml”/”your fileName”</em></p><p>Welldone ! Your application should now work perfectly fine on any Android version including Android Nougat.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3f0f0128fa7e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Android DOZE mode, how to deal with it..]]></title>
            <link>https://medium.com/@sauge16/how-to-handle-alarm-in-all-android-version-e7aca16ae885?source=rss-49083635e554------2</link>
            <guid isPermaLink="false">https://medium.com/p/e7aca16ae885</guid>
            <category><![CDATA[android-apps]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[androiddev]]></category>
            <dc:creator><![CDATA[Rishikesh Pathak]]></dc:creator>
            <pubDate>Sat, 06 May 2017 06:00:10 GMT</pubDate>
            <atom:updated>2017-09-11T14:53:42.794Z</atom:updated>
            <content:encoded><![CDATA[<p>Android is launching new versions with cool features and many changes that Android developer should be updated with.</p><blockquote>If you are updated with new versions you must have heared about DOZE mode.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/653/1*6T__REHvyrCNCZZZ0gaScg.png" /></figure><p>Android 6.0 introduced Doze, a system mode that saves battery by deferring apps’ CPU and network activities when the device is idle.</p><p>Now in Android 7.0, Doze takes a step further and saves battery while on the go. Any time the screen is off for a period of time and the device is unplugged, Doze applies a subset of the familiar CPU and network restrictions to apps. This means users can save battery even when carrying their devices in their pockets.</p><p>Doze applies the full CPU and network restrictions on AlarmManager alarms.</p><p>So how to deal with this situation?Dont worry just follw below steps.</p><p><strong>Step 1:</strong></p><p>Extend Your Alarm Broadcast Receiver class with WakefulBroadcastReceiver.</p><pre>public class AlarmBroadCastReceiver extends WakefulBroadcastReceiver</pre><p><strong>Step 2:</strong></p><blockquote>Note:If you have to start a <strong>IntentService </strong>from receiver then follow E<strong>xample B</strong> else follow E<strong>xample A</strong></blockquote><p><strong>Example A :</strong>Acquire wakelock — do your work such as create notification ,etc-release wakelock</p><pre>public class AlarmBroadCastReceiver extends WakefulBroadcastReceiver</pre><pre>{</pre><pre>private PowerManager.WakeLock screenWakeLock;</pre><pre>@Override</pre><pre>public void onReceive(Context context, Intent intent)</pre><pre>{</pre><pre>if (screenWakeLock == null)</pre><pre>{</pre><pre>PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);</pre><pre>screenWakeLock = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, “ScreenLock tag from AlarmListener”);</pre><pre>screenWakeLock.acquire();</pre><pre>}</pre><pre>//TODO:Do your code here related to alarm receiver.</pre><pre>if (screenWakeLock != null)</pre><pre>screenWakeLock.release();</pre><pre>}</pre><pre>}</pre><p><strong>Example B:</strong></p><p>If you have to start a intent service then you dont need to use <em>PowerManager.Wakelock</em> used in above example.</p><p>So you have to start your service by using <em>startWakefulService(context, service) </em>And from service you have to inform by <em>AlarmBroadCastReceiver.completeWakefulIntent(intent)</em> to <em>AlarmBroadCastReceiver </em>that your service task is done.For detail follow example:</p><pre>public class AlarmBroadCastReceiver extends WakefulBroadcastReceiver {<br>    @Override<br>    public void onReceive(Context context, Intent intent) {<br>        // This is the Intent to deliver to your service.<br>       <br> Intent service = new Intent(context, WakefulService.class);<br><br>        // Start the service, keeping the device awake while it is launching.<br>        <br>        startWakefulService(context, service);<br>    }<br>}</pre><blockquote>The service does some work. When it is finished, it releases the wake lock by calling <em>completeWakefulIntent(intent)</em>.</blockquote><pre>public class WakefulService extends IntentService {<br> public WakefulService() {<br> super(“WakefulService”);<br> }<br> <br> @Override<br> protected void onHandleIntent(Intent intent) <br>  {</pre><pre>    //TODO:Service code</pre><pre>    AlarmBroadCastReceiver.completeWakefulIntent(intent)</pre><pre>  }</pre><pre>}</pre><p>Well receiver is done but how to set alarm,so for setting alarm you have to check android OS version first and set your alarm, check it out.</p><p><strong>Step 3:</strong></p><pre>AlarmManager alarmManager = (AlarmManager)context.getSystemService(Context.ALARM_SERVICE);</pre><pre>Intent intent = new Intent(context, AlarmBroadCastReceiver.class);</pre><pre>PendingIntent pendingIntent = PendingIntent.getBroadcast(context, reminderiId, intent, PendingIntent.FLAG_UPDATE_CURRENT);</pre><pre>if (Build.VERSION.SDK_INT &gt;= 23)</pre><pre>{</pre><pre>alarmManager.setExactAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, alarmPeriodicTime, pendingIntent);</pre><pre>}</pre><pre>else if (Build.VERSION.SDK_INT &gt;= 19)</pre><pre>{</pre><pre>alarmManager.setExact(AlarmManager.RTC_WAKEUP, alarmPeriodicTime, pendingIntent);</pre><pre>}</pre><pre>else</pre><pre>{</pre><pre>alarmManager.set(AlarmManager.RTC_WAKEUP, alarmPeriodicTime, pendingIntent);</pre><pre>}</pre><p><strong>Step 4:</strong></p><p>Last step but very important step,give wake lock permission in manifest.</p><pre><strong>&lt;uses-permission android:name=”android.permission.WAKE_LOCK” /&gt;</strong></pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e7aca16ae885" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>