<?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 Samat Gayazov on Medium]]></title>
        <description><![CDATA[Stories by Samat Gayazov on Medium]]></description>
        <link>https://medium.com/@diesersamat?source=rss-91192517f569------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*8oG8eDLBYqSaRFQMGTObGw.jpeg</url>
            <title>Stories by Samat Gayazov on Medium</title>
            <link>https://medium.com/@diesersamat?source=rss-91192517f569------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 29 Nov 2026 01:20:36 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@diesersamat/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[Getting inside APK files]]></title>
            <link>https://medium.com/android-news/getting-inside-apk-files-21dbd01529d4?source=rss-91192517f569------2</link>
            <guid isPermaLink="false">https://medium.com/p/21dbd01529d4</guid>
            <category><![CDATA[androiddev]]></category>
            <category><![CDATA[reverse-engineering]]></category>
            <category><![CDATA[android]]></category>
            <dc:creator><![CDATA[Samat Gayazov]]></dc:creator>
            <pubDate>Fri, 09 Nov 2018 08:01:01 GMT</pubDate>
            <atom:updated>2018-11-09T08:01:01.825Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>Disclaimer</strong>: <strong>Never try to reverse engineer apps, which are not developed by you. I’m not responsible for any damage you may cause to third-party developers using this tutorial, I insist that you should use this knowledge only to audit your own apps!</strong></p><p>So, your Android app was pirated? You have Google in-app purchases, but someone published a full paid version for free on pirating websites? How is it even possible?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/900/1*8wY0YUHwfEbQS4DAHI4hHA.jpeg" /></figure><p>Let’s try to understand and try to decompile APK file. Here is the guide. Not for pirates or hackers, but for developers — so you will know better your app’s security weak sides.</p><p>In this tutorial, I will be using Mac OS X, but the tools I’m using are multi-platform — and you can install them also on Linux and even maybe Windows.</p><p>To start with, you will obviously need the APK file of the app you want to reverse engineer. As it is your own project, you can get it from app\build\outputs\apk folder of your project, alternatively get it using <a href="https://apkpure.com/">ApkPure</a> on your PC or from your device (you can back up any of your installed apps without root, for example, with ES File Explorer).</p><h3>Installing the required tools</h3><p>Next, let’s start with installing the required tools. You will need:</p><ol><li><a href="https://ibotpeaches.github.io/Apktool/"><em>apktool</em></a> to unpack APK file to a <em>smali</em> project and pack it back.</li><li><a href="https://shatter-box.com/knowledgebase/android-apk-signing-tool-apk-signer/"><em>apk-signer</em></a> to sign your final APK file</li><li><a href="https://www.jetbrains.com/idea/download/#section=mac">IntelliJ IDEA</a> and<em> </em><a href="https://github.com/JesusFreke/smali"><em>Smali Support Plugin</em></a> (I haven’t tried to install it on Android Studio, but I think it should work)</li></ol><p>Let’s start with <em>apktool</em>. Go to <a href="https://ibotpeaches.github.io/Apktool/install/">this</a> webpage and follow the instructions. After that, you should be able to run apktool command from your Terminal:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*c1Q-l1UKTqJllXQCG6bHfg.png" /></figure><p>Next, let’s download apk-signer. Go to <a href="https://shatter-box.com/knowledgebase/android-apk-signing-tool-apk-signer/">this</a> page, click “Download” button near <em>APK-Signer</em>. It’s just a simple <em>.jar</em> file with GUI, so you can open it as any usual app with double-click to run it in Mac OS X. You should see the following window:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-EyZ0hddENad7viIbCK2xA.png" /></figure><p>For Mac OS X users you don’t have to specify JDK path.</p><p>And the last piece of our tools installation journey is <em>smalidea</em> <em>plugin</em>. Download it from <a href="https://bitbucket.org/JesusFreke/smali/downloads/">here</a>, just search on the page for smalidea-*.*.zip and choose the latest version. To install it, open IntelliJ IDEA, go to <em>Preferences-&gt;Plugins-&gt;Install plugin from disk…</em> After that, you will have to restart IntelliJ IDEA.</p><p>Now we’re ready to begin.</p><h3>Decompiling APK file</h3><p>To decompile APK file, open Terminal and run following command:</p><p>apktool d path/to/your/app.apk</p><p>By default, after running that command, you should see a folder with the decompiled app in your Home folder.</p><p>If you open the decompiled app folder, you should see the structure similar to this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/352/1*7X9BRqPq8TXQFSkRu55xHA.png" /></figure><p>I suggest you open IntelliJ IDEA, click <em>File-&gt;Open…</em> and choose the decompiled app folder in the following window. Now it’s easier to edit files there.</p><h3>Let’s make changes</h3><p>To start with, let’s try to understand the files structure. You can see <em>AndroidManifest.xml</em> file in the root folder and also you can edit it as is — because it is default Android manifest file.</p><p>In the res folder you can find app’s resources — strings, values, drawables.</p><p>The most interesting folder for us is smali. In <em>multidex</em> app cases, you may see the smali_classes2 folder — this is the location for classes from the second <em>.dex</em> file.</p><p>Let’s open smali folder. Here you will see the basic structure of all packages included in the app. For example:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/270/1*L9oChsKrHuoTtwWXGk7Y2g.png" /></figure><p>Of course, if you go down the tree, you will finally see files with class names. But they are not .java or .kt — they are all <em>.smali</em>. And it is kind of a way to interpret code inside <em>.dex</em> files in readable and editable format.</p><blockquote>The syntax is loosely based on Jasmin’s/dedexer’s syntax, and supports the full functionality of the dex format (annotations, debug info, line info, etc.)</blockquote><p>Sometimes you will see one file with source file name and a lot of files with almost similar names:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/538/1*5fKPX97F2wD3cw3QjBg46w.png" /></figure><p>These are internal classes. For example, each lambda has its own <em>.smali</em> file, as well as each internal class.</p><p>So, finally, let’s try to open any of these <em>.smali</em> files!</p><p>The folder structure should be similar to your source code structure (of course, if the app you decompiled is not <em>obfuscated</em>), so you can easily find any classes you may be looking for. Also, you can search in IntelliJ IDEA, using <em>double-shift</em>.</p><p>You can notice that <em>.smali</em> files inside are really different from usual source code files. For example, here is a class declaration:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/956/1*_qK2ntX2x3hL0YouPJ6RVw.png" /></figure><p>But don’t worry — it’s easy to read and understand <em>.smali</em> files. In this case, we have an <em>interface</em> file, with name <em>Event</em>. It implements <em>parcelable</em>, and its parent class is <em>Object</em>.</p><p>Also, you can see declared static fields, and of course, edit them:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/858/1*6FCcydN3JMLttJA9xnch2g.png" /></figure><blockquote>As mentioned previously, long and double primitives (J and D respectively) are 64 bit values, and require 2 registers.</blockquote><p>So, basically, J means that it is a 64-bit value, and we can edit it, but keep in mind, that this is a 16-bit literal.</p><p>And here is one of method/function declarations:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/928/1*4IfGn3LG4dykJ7K-SyuaHA.png" /></figure><p>In this case, the method name is isUserSubscribed, it has parameter with name p2 with Java type <em>List</em>, and it is a list of Purchases, which is, by the way, annotated as <em>Nullable</em>.</p><p>Let’s imagine, that the method has serious and reliable logic inside, a lot of conditions and iterations, method calls to check if the end-user really bought the premium subscription, but finally it ends with this return code:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/352/1*KeebUFeVkCue8tW1cAK6gQ.png" /></figure><p>As you can see, in one if-branch (<em>cond_0</em>), using line const/4 p1, 0x1 we set “<em>true</em>” value to <strong>p1</strong>, and in other if-branch (<em>cond_1</em>), using line const/4 p1, 0x0 we set “<em>false</em>” to <strong>p1</strong> and in both cases return <strong>p1</strong>. Basically, changing <strong>0x0</strong> in the last line — and they can change it using IntelliJ IDEA or any other text editor, — hackers can make this method always to return “<em>true</em>” and <em>break all premium subscription logic</em>.</p><p>Of course, this is the most obvious case — to try to pirate the app, to disable some purchase checks — most primitive and simple one. But using the same tools, detractors can do a lot of even worse things with your app, so <em>be careful</em>.</p><h3>Build APK from smali</h3><p>So, we’ve changed some code here, let’s try to build and run our modified APK. It is simple — just run:</p><p>apktool b path/to/your/decompiled/folder</p><p>After a few seconds, there will be new APK file inside dist folder which is inside your decompiled app folder.</p><p>But if you will try to install it on your device, you will get an error saying “<em>Application not installed</em>”. It’s because your APK file is <em>not signed</em> at all. Of course, a hacker wouldn’t be able to sign it using the original <em>keystore</em> — of course, if you keep your <em>keystore</em> and passwords in a safe place. So in order to run it, we will have to sign it with a <em>new</em> <em>keystore</em>, or we can use an existing one. To create one, open apk-signer.jar, go to “<em>Key Generator</em>” tab, fill in all required info and click “<em>Generate Keyfile</em>”. Now you can use this <em>keystore</em> to sign APK files.</p><p>In Apk Signer tool, go to “<em>Signer</em>” tab.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FY9-BTKIcV5p4cEob9sKdA.png" /></figure><p>Select the <em>keystore</em> you generated in the previous step, fill in passwords and alias names, choose the APK file you want to sign, and click the “<em>Sign!</em>” button.</p><p>You will find final installable APK file in the same place where unsigned one was located — in the dist folder. Try to run it and if you’ve done everything correctly, you should see the changes in the app.</p><h3>What if I use React Native? Am I safe?</h3><p>Not really. If your app is written on React Native, using the same apktool you can find index.android.bundle file inside assets folder of decompiled APK folder.</p><p>To open it using IntelliJ IDEA, right click on the file, <em>Associate with File Type…</em> and choose <em>JavaScript</em>. And it is usual minified .js file. Of course, you can edit it and rebuild the app, but it may be difficult to do that as is:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/980/1*fvsF48EFAjLNcs3hTx5Lkw.png" /></figure><p>Just use <a href="https://github.com/beautify-web/js-beautify">js-beautify</a> — to install it use:</p><pre>pip install jsbeautifier</pre><p>and run it using:</p><pre>js-beautify -o out.js in.js</pre><p>Now you can find everything that you want inside this <em>beautified .js file</em>. With <em>beautified .js file</em> it’s much easier to read JavaScript code. But don’t replace index.android.bundle file with beautified one, because we have it only to understand source code — that’s why after finding required lines in <em>the beautified file</em>, replace what you want inside the minified source index.android.bundle file, and rebuild APK.</p><h3>How to be safe</h3><p>If you’re suffering from piracy and don’t know how intruders modified your APK, you can try to think as they do and reproduce these steps with your APK, and later use that knowledge.</p><p>How to be safe? One of the possible solutions is to make all checks on the back-end side, but in some cases, it is not possible. But for really sensitive operations, somehow linked to your or your users’ money you should do back-end side checks anyway. Because front-end is almost always reverse engineerable. Use front-end <em>only to validate</em> data, obtained from the back-end.</p><p>Also, remember to use <em>ProGuard</em> and don’t forget to turn it on for release builds — it can help in some cases.</p><p>By the way, if you need more info on <em>smali</em> language, always visit their <a href="https://github.com/JesusFreke/smali">GitHub page</a>. More about <em>apktool</em> you can read <a href="https://ibotpeaches.github.io/Apktool/documentation/">here</a>.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fupscri.be%2F3e491f%3Fas_embed%3Dtrue&amp;dntp=1&amp;url=https%3A%2F%2Fupscri.be%2F3e491f%2F&amp;image=http%3A%2F%2Fapi.screenshotlayer.com%2Fapi%2Fcapture%3Faccess_key%3Dfe59908dad3baab69ffab249a2224b03%26viewport%3D1024x612%26width%3D1000%26url%3Dhttps%253A%252F%252Fupscri.be%252F3e491f%253Fscreenshot&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=upscri" width="800" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/fedb9f91e907af2468a937c944ed32ab/href">https://medium.com/media/fedb9f91e907af2468a937c944ed32ab/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=21dbd01529d4" width="1" height="1" alt=""><hr><p><a href="https://medium.com/android-news/getting-inside-apk-files-21dbd01529d4">Getting inside APK files</a> was originally published in <a href="https://medium.com/android-news">AndroidPub</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Let’s start Daydreaming…]]></title>
            <link>https://medium.com/virtual-reality-pop/lets-start-daydreaming-4730aa1c270?source=rss-91192517f569------2</link>
            <guid isPermaLink="false">https://medium.com/p/4730aa1c270</guid>
            <category><![CDATA[daydream]]></category>
            <category><![CDATA[virtual-reality]]></category>
            <category><![CDATA[google-daydream]]></category>
            <category><![CDATA[android]]></category>
            <dc:creator><![CDATA[Samat Gayazov]]></dc:creator>
            <pubDate>Tue, 31 Jan 2017 07:48:23 GMT</pubDate>
            <atom:updated>2017-02-02T03:12:16.988Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AXLxOotnjO1ynpAYB_QChQ.jpeg" /></figure><p>To start with, I’m Android, not Unity or 3D developer. I’m always working with fragments and adapters and so on in Android Studio. So, it’s very simple tutorial for beginners.</p><p>Some time ago I bought Chinese VR-glasses from AliExpress just to try out mobile VR. And recently Google released tools for developing own Unity Android VR game/application. To be exact, Google released Cardboard kit even earlier, more than a year ago, but Daydream has released not really long ago. So, first, you should know differences between Cardboard and Daydream. I think you know the difference, if not, just Google it.</p><p>SDK’s are also different. In this article I’m not going to describe Cardboard apps development, I’m going to start just from Daydream.</p><p>In this article, I’m going to cover all problems I’ve met trying to start VR-development for Daydream and running Daydream apps on non-Google-certified hardware.</p><h3>I. We’re starting. Installing SDK</h3><p>Preparations, preparations… Here is just one step: <a href="https://unity3d.com/ru/partners/google/daydream">https://unity3d.com/ru/partners/google/daydream</a></p><p>Download SDK from here <a href="https://github.com/googlevr/gvr-unity-sdk">https://github.com/googlevr/gvr-unity-sdk</a> and install special Unity version from the link and run it.</p><p>Let’s start with the empty project. Create it and in empty project window select <strong>Assets — Import Package — Custom Package</strong>. Find your <strong>gvr-unity-sdk</strong> folder and choose <strong>GoogleVRForUnity.unitypackage</strong>. You can unselect <strong>iOS</strong> and <strong>x86</strong> from <strong>Plugins</strong> if you don’t need iPhone support. Click <strong>Import</strong>.</p><p>Click <strong>File — Build Settings </strong>and in opened window select Android platform and click <strong>Switch Platform</strong>. Click <strong>Player Settings</strong> on the same screen after platform switching process is finished. Enable <strong>Virtual Reality Supported</strong>. Add Daydream to <strong>Virtual Reality SDK</strong> list.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2HqJeoJvZYN3AzRqtppzqw.jpeg" /></figure><p>You can also edit package name (it’s that you <strong>must</strong> do before building and running your app on a device), icon here. Close <strong>Build Settings</strong> screen when you finished.</p><p>Let’s open a Sample. In Project window on the bottom go to <strong>Google VR — Demos — Scenes</strong> and double click on any of scenes.</p><p>You can click <strong>Play</strong> button on the top of Unity window to run it on your computer. You can run the app on your headset phone by clicking <strong>File — Build and Run</strong>.</p><p>Also, there are lot more samples, which are located in the downloaded <strong>gvr-unity-sdk</strong> folder named <strong>Samples</strong>. Some of them are simple real games, so I recommend trying them out.</p><h3>II. Setting up your not-really-daydream-compatible phone</h3><p>Basically, to launch and experience VR by Google we need these 3 things (as Google says):</p><ol><li>Daydream compatible phone (Pixel (XL), Moto Z and some upcoming phones)</li><li>Daydream VR-headset</li><li>Daydream Controller, which comes with the VR-headset</li></ol><p>As I stated in the first paragraph, I have Chinese VR-headset, which is, obviously, not compatible with the “Daydream technology”. But, there is technically almost no difference between Google Daydream VR-headset and no-name VR-headset from AliExpress (I’m not saying a word about quality, convenience and so on). So, everything isn’t going to be as easy as it should be.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VDoeI0EA1o9-AkHQVUNVJg.jpeg" /></figure><p>So, I don’t have a Pixel phone also, so I’m using Nexus 6P, which isn’t on the list of Daydream compatible phones, but still, a very powerful device. You can use any phone running 7.0 and above, but even my powerful 6P sometimes freezes in VR-mode, and its aluminium body becomes very hot, and battery discharges really fast.</p><p>Also, we can use another phone (Nexus 6 in my case) as a controller. I think, there are no restrictions on controller phone, you can use any phone running KitKat or above. So, my set up, against to recommended by Google is:</p><ol><li>Any VR-headset or even Cardboard</li><li>Any of latest high-end phones running <strong>Android 7.0 and above</strong> (in my case Nexus 6P) (<strong>headset phone</strong>)</li><li>Another phone with at least Android KitKat as a controller (<strong>controller phone</strong>)</li></ol><p>Cheaper, isn’t it? Let’s start setting up. VR-headset works as is, and you don’t have to do anything with it.</p><p>To set up your VR-phone, you will have to download this app (you cannot install it from Google Play, until you have Daydream compatible phone):</p><p><a href="https://www.apkmirror.com/apk/google-inc/daydream/daydream-1-0-161019143-release/daydream-1-0-161019143-android-apk-download/">Daydream 1.0.161019143 APK Download by Google Inc. - APKMirror</a></p><p>It’s the main Daydream APK. Install it to VR-phone and run it, click “I have headset”, confirm that you’re at least 13 years old. App will download additional components and it should start after that. If Daydream app will crash with VR Keyboard not found!” or something like that, just also Google for this APK and install it too.</p><p>On controller-phone install <a href="https://github.com/googlevr/gvr-android-sdk/blob/master/apks/controller_emulator.apk?raw=true">controller APK</a> and also run it.</p><ol><li>Pair your headset phone to your controller phone via Bluetooth.</li></ol><ul><li>On both phones, go to <strong>Settings &gt; Bluetooth</strong>.</li><li>Optionally, rename your controller phone in order to make it easier to identify. To do this, press more_vert, then <strong>Rename this device</strong>. Change its name to, for example, <strong>(Your Name)’s Controller Phone</strong>.</li><li>On the headset phone, tap the controller phone’s name on the list of devices. This will show a dialog box on both devices to confirm the pairing.</li><li>Confirm the pairing, then return to the home screen on both devices.</li></ul><p>2. Configure the Controller Emulator device.</p><ul><li>On the headset phone, launch the app for Daydream you installed earlier.</li><li>Press the settings button at the bottom of the screen, then press <strong>Setup</strong>.</li><li>You should now be in the Google VR Services settings screen. Tap the <strong>Version</strong> item 7 times to show the <strong>Developer Options</strong>.</li><li>Select <strong>Controller emulator device</strong>.</li><li>Select the controller phone from the list.</li><li>Close the app by pressing the square <strong>Recents</strong> button in the bottom-right and swiping the app away.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fSjfZ1CLPofeYUU4E52r6Q.png" /><figcaption>That’s how the controller app looks like</figcaption></figure><h3>III. The third part or “What about running it with Controller Emulator in Unity”?</h3><p>Now you just have to connect your VR-phone to your computer and click “Build &amp; Run” in Unity, put the phone inside of your VR-headset and try to use controller emulator on the second phone.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/1*Xwvm_Quv7bYe7tP1EalnDw.jpeg" /></figure><p>To save time on building and running your app on the phone and to make it easier to debug your apps, I recommend you to run the app on the computer using Unity by just clicking “Play” button.</p><p>But what about the controller? We’re going to make our controller phone work with Unity.</p><p>First, make sure your controller phone connected to the same WiFI as your computer. In your Unity project find GvrControllerMain and change Emulator Connection Mode to Wi-Fi. Also find Assets/GoogleVR/Scripts/Controller/Internal/Emulator/EmulatorConfig.cs and change line to IP address displayed on daydream controller emulator app on the phone.</p><pre>// IP address of the phone, when connected to the PC via WiFi.<br>public static readonly string WIFI_SERVER_IP = &quot;192.168.0.78&quot;;</pre><p>Click “Play” in Unity. It should work now.</p><h3>IV. What’s next?</h3><p>That’s it. I’m open to any questions, but keep in mind, that I’m Android developer, not 3D artist or Unity master.</p><p>I understand why Google do not certificate Nexus 6P or similar devices — because of lags and low frame rate. It’s OK that end-users will not run Daydream on their “old” and “laggy” phones, and it’s also a marketing thing, to support Pixel, which is an excellent phone, as for me, after all. But, to make Daydream more popular they should’ve made it easier for developers, I think.</p><p>So, I wrote this article to make it easier to start for you, developer. I found Unity and VR-development as very interesting and promising area of mobile development. It’s absolutely different to usual native mobile apps development. It’s C# scripting and level designing, and 3D modelling and so on.</p><p>For now, I have to leave scenes and return to my old favourite activities and fragments.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4730aa1c270" width="1" height="1" alt=""><hr><p><a href="https://medium.com/virtual-reality-pop/lets-start-daydreaming-4730aa1c270">Let’s start Daydreaming…</a> was originally published in <a href="https://medium.com/virtual-reality-pop">Virtual Reality Pop</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Deep Linking in Android]]></title>
            <link>https://medium.com/android-news/deep-linking-in-android-46bc61bd9750?source=rss-91192517f569------2</link>
            <guid isPermaLink="false">https://medium.com/p/46bc61bd9750</guid>
            <category><![CDATA[android]]></category>
            <category><![CDATA[deep-linking]]></category>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[androiddev]]></category>
            <dc:creator><![CDATA[Samat Gayazov]]></dc:creator>
            <pubDate>Mon, 12 Sep 2016 11:34:07 GMT</pubDate>
            <atom:updated>2016-09-13T14:46:24.483Z</atom:updated>
            <content:encoded><![CDATA[<p>If you often use Android phone, you’ve seen “Open with…” menus. That’s the topic of this post.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/1*XN6hUGMg_MbXhlMvejPITA.png" /><figcaption>“Open with…” menu</figcaption></figure><p>“Open with…” menus appear then you trying to open some link, which is deep linked to one of installed apps. If you choose to open it with app, app will be opened instead of browser.</p><p>How to implement deep linking in your app?</p><p>You can start learning about deep linking from <a href="https://developer.android.com/training/app-indexing/deep-linking.html">Google documentation</a>, but there are some tricks in my tutorial which can save your time.</p><p>First, you should find in our AndroidManifest file activity, which will open link and add there <strong>intent-filter</strong> with <strong>action.VIEW, category.DEFAULT </strong>and<strong> category.BROWSABLE </strong>children:</p><pre>&lt;activity<br>    android:name=&quot;.view.activity.SomeActivity&quot;<br>    android:screenOrientation=&quot;portrait&quot;&gt;<br>    &lt;intent-filter android:autoVerify=&quot;true&quot;&gt;<br>        &lt;action android:name=&quot;android.intent.action.VIEW&quot;/&gt;<br>        &lt;category android:name=&quot;android.intent.category.DEFAULT&quot;/&gt;<br>        &lt;category android:name=&quot;android.intent.category.BROWSABLE&quot;/&gt;<br>        &lt;data android:host=&quot;www.host.com&quot; android:scheme=&quot;http&quot;/&gt;<br>    &lt;/intent-filter&gt;<br>&lt;/activity&gt;</pre><p>This is the simplest example. What should you do, if you want to open not all links in app, but only links matching some custom pattern? Of course, it’s simple:</p><pre>&lt;data android:host=&quot;www.host.com&quot; android:pathPattern=&quot;/movie/0.*/&quot; android:scheme=&quot;http&quot;/&gt;</pre><p>You should add <strong>pathPattern </strong>parameter.</p><p>Here is the main problem of Android SDK deep linking. <strong>pathPattern</strong> looks like regular expression, but it is very simplified regular expression. As you can see <a href="https://developer.android.com/guide/topics/manifest/data-element.html">in documentation</a>, there are only two wildcards:</p><ul><li>An asterisk (‘*’) matches a sequence of 0 to many occurrences of the immediately preceding character.</li><li>A period followed by an asterisk (“.*”) matches any sequence of 0 to many characters.</li></ul><p>And that’s all. But wait, what if you want to open in app links which start from digits? Like these: <strong>www.link.com/page2323232</strong>, <strong>www.link.com/page04393</strong>, but not these: <strong>www.link.com/pager_common</strong>,<strong> www.link.com/paged_chain</strong>? You’ll not be happy to hear that it’s impossible because of lack of functionality of these two wildcards. It could be achieved only by creating a really huge manifest, like this:</p><pre>&lt;activity<br>    android:name=&quot;.view.activity.SomeActivity&quot;<br>    android:screenOrientation=&quot;portrait&quot;&gt;<br>    &lt;intent-filter android:autoVerify=&quot;true&quot;&gt;<br>        &lt;action android:name=&quot;android.intent.action.VIEW&quot;/&gt;<br>        &lt;category android:name=&quot;android.intent.category.DEFAULT&quot;/&gt;<br>        &lt;category android:name=&quot;android.intent.category.BROWSABLE&quot;/&gt;<br>        &lt;data android:host=&quot;www.host.com&quot; android:pathPattern=&quot;/page0.*/&quot; android:scheme=&quot;http&quot;/&gt;<br>        &lt;data android:host=&quot;www.host.com&quot; android:pathPattern=&quot;/page1.*/&quot; android:scheme=&quot;http&quot;/&gt;<br>        &lt;data android:host=&quot;www.host.com&quot; android:pathPattern=&quot;/page2.*/&quot; android:scheme=&quot;http&quot;/&gt;<br>        &lt;data android:host=&quot;www.host.com&quot; android:pathPattern=&quot;/page3.*/&quot; android:scheme=&quot;http&quot;/&gt;<br>        &lt;data android:host=&quot;www.host.com&quot; android:pathPattern=&quot;/page4.*/&quot; android:scheme=&quot;http&quot;/&gt;<br>        &lt;data android:host=&quot;www.host.com&quot; android:pathPattern=&quot;/page5.*/&quot; android:scheme=&quot;http&quot;/&gt;<br>        &lt;data android:host=&quot;www.host.com&quot; android:pathPattern=&quot;/page6.*/&quot; android:scheme=&quot;http&quot;/&gt;<br>        &lt;data android:host=&quot;www.host.com&quot; android:pathPattern=&quot;/page7.*/&quot; android:scheme=&quot;http&quot;/&gt;<br>        &lt;data android:host=&quot;www.host.com&quot; android:pathPattern=&quot;/page8.*/&quot; android:scheme=&quot;http&quot;/&gt;<br>        &lt;data android:host=&quot;www.host.com&quot; android:pathPattern=&quot;/page9.*/&quot; android:scheme=&quot;http&quot;/&gt;<br>    &lt;/intent-filter&gt;<br>&lt;/activity&gt;</pre><p>If your website supports <strong>https, </strong>and you want to deep link<strong> https </strong>links<strong> too, </strong>you’ll have to duplicate these lines again, with <strong>https</strong> as scheme!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/358/1*gy8g-yohrXupN6PKoaNmsw.png" /></figure><p>What about adding also pages like these <a href="http://www.link.com/wall2323232?"><strong>www.link.com/wall2323232</strong>?</a> You’ll have to write another ten lines for <strong>http</strong>, and ten lines again for <strong>https</strong>. Isn’t it confusing?</p><p>Anyway, I don’t want to criticize Google for this.</p><p>So, user can open our links in app instead of browser now. But how to get that link?</p><pre>Uri data = getIntent().getData();</pre><p>Not a rocket science, huh?</p><p>Also, there is <a href="https://github.com/airbnb/DeepLinkDispatch">simple noteworthy library from Airbnb</a>.</p><p>You will still have to add thousand lines of XML code to manifest file, and this library will not save you from Google’s ugly pattern realisation. But it will be much easier to handle links in your app.</p><p>So, instead of adding <strong>intent-filter </strong>child to your Activity tag, you should define new NoDisplay activity named <strong>.DeepLinkActivity</strong>. This activity is provided by library:</p><pre>&lt;activity<br>    android:name=&quot;com.airbnb.deeplinkdispatch.DeepLinkActivity&quot;<br>    android:theme=&quot;@android:style/Theme.NoDisplay&quot;&gt;<br>    &lt;intent-filter&gt;<br>        &lt;action android:name=&quot;android.intent.action.VIEW&quot; /&gt;<br>        &lt;category android:name=&quot;android.intent.category.DEFAULT&quot; /&gt;<br>        &lt;category android:name=&quot;android.intent.category.BROWSABLE&quot;/&gt;<br>        &lt;data android:host=&quot;www.host.com&quot; android:pathPattern=&quot;/page0.*/&quot; android:scheme=&quot;http&quot;/&gt;<br>        &lt;data android:host=&quot;www.host.com&quot; android:pathPattern=&quot;/page1.*/&quot; android:scheme=&quot;http&quot;/&gt;<br>        &lt;data android:host=&quot;www.host.com&quot; android:pathPattern=&quot;/page2.*/&quot; android:scheme=&quot;http&quot;/&gt;<br>        &lt;data android:host=&quot;www.host.com&quot; android:pathPattern=&quot;/page3.*/&quot; android:scheme=&quot;http&quot;/&gt;<br>        &lt;data android:host=&quot;www.host.com&quot; android:pathPattern=&quot;/page4.*/&quot; android:scheme=&quot;http&quot;/&gt;<br>        &lt;data android:host=&quot;www.host.com&quot; android:pathPattern=&quot;/page5.*/&quot; android:scheme=&quot;http&quot;/&gt;<br>        &lt;data android:host=&quot;www.host.com&quot; android:pathPattern=&quot;/page6.*/&quot; android:scheme=&quot;http&quot;/&gt;<br>        &lt;data android:host=&quot;www.host.com&quot; android:pathPattern=&quot;/page7.*/&quot; android:scheme=&quot;http&quot;/&gt;<br>        &lt;data android:host=&quot;www.host.com&quot; android:pathPattern=&quot;/page8.*/&quot; android:scheme=&quot;http&quot;/&gt;<br>        &lt;data android:host=&quot;www.host.com&quot; android:pathPattern=&quot;/page9.*/&quot; android:scheme=&quot;http&quot;/&gt;<br>    &lt;/intent-filter&gt;<br>&lt;/activity&gt;</pre><p>And here’s links handling:</p><pre>@DeepLink(&quot;foo://example.com/deepLink/{id}&quot;)<br>public class MainActivity extends Activity {<br>  @Override protected void onCreate(Bundle savedInstanceState) {<br>    super.onCreate(savedInstanceState);<br>    Intent intent = getIntent();<br>    if (intent.getBooleanExtra(DeepLink.IS_DEEP_LINK, false)) {<br>      Bundle parameters = intent.getExtras();<br>      String idString = parameters.getString(&quot;id&quot;);<br>      // Do something with the ID...<br>    }<br>    ...<br>  }<br>}</pre><p>Personally, I didn’t find this library useful for me, but you can give it a try.</p><p>Happy deep linking and I wish you short manifest files.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=46bc61bd9750" width="1" height="1" alt=""><hr><p><a href="https://medium.com/android-news/deep-linking-in-android-46bc61bd9750">Deep Linking in Android</a> was originally published in <a href="https://medium.com/android-news">AndroidPub</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>