<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Rao Asad</title>
    <description>The latest articles on DEV Community by Rao Asad (@rao_asad_fb657aebdb761ad4).</description>
    <link>https://dev.to/rao_asad_fb657aebdb761ad4</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4166165%2F42ed3b35-e2df-4ac4-92b1-cc1157048356.jpeg</url>
      <title>DEV Community: Rao Asad</title>
      <link>https://dev.to/rao_asad_fb657aebdb761ad4</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/rao_asad_fb657aebdb761ad4"/>
    <language>en</language>
    <item>
      <title>Grading spoken answers for a U.S. citizenship mock interview</title>
      <dc:creator>Rao Asad</dc:creator>
      <pubDate>Wed, 11 Nov 2026 14:40:17 +0000</pubDate>
      <link>https://dev.to/rao_asad_fb657aebdb761ad4/grading-spoken-answers-for-a-us-citizenship-mock-interview-3ae0</link>
      <guid>https://dev.to/rao_asad_fb657aebdb761ad4/grading-spoken-answers-for-a-us-citizenship-mock-interview-3ae0</guid>
      <description>&lt;p&gt;At the U.S. naturalization interview, the officer reads civics questions aloud and you answer in English, out loud. Many study apps practise this as a multiple-choice quiz, which is a different skill: recognising an answer is easier than producing one under pressure.&lt;/p&gt;

&lt;p&gt;So &lt;a href="https://play.google.com/store/apps/details?id=org.truetechsol.belong.us" rel="noopener noreferrer"&gt;Belong&lt;/a&gt;, my citizenship test app for Android, has a mock interview that works the way the real one does: each question is read aloud, you answer by voice or by typing, and it stops when the result is settled. The interesting part turned out to be deciding whether a spoken answer is right. (Belong isn't affiliated with USCIS; the questions come from the official USCIS study materials.)&lt;/p&gt;

&lt;h2&gt;
  
  
  The rules, as plain Kotlin
&lt;/h2&gt;

&lt;p&gt;All of the test logic lives in a &lt;code&gt;:core&lt;/code&gt; module with no Android dependencies, so it's fast to unit test.&lt;/p&gt;

&lt;p&gt;There are two tests in use. On the 2025 test the officer asks up to 20 questions and you pass at 12 correct. On the 2008 test it's up to 10 questions, passing at 6. The interview doesn't run to the end: it stops as soon as the outcome is decided.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight kotlin"&gt;&lt;code&gt;&lt;span class="n"&gt;data&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;TestRules&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="n"&gt;maxQuestions&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;Int&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="n"&gt;passAt&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;Int&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="n"&gt;failAt&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;Int&lt;/span&gt; &lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;maxQuestions&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;passAt&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;   &lt;span class="c1"&gt;// 2025: 9 wrong ends it&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;MockInterview&lt;/span&gt; &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="nf"&gt;constructor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="n"&gt;questions&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;List&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Question&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="n"&gt;rules&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;TestRules&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="n"&gt;answers&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;mutableListOf&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;AnsweredQuestion&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="n"&gt;correctCount&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;Int&lt;/span&gt; &lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;answers&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;count&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;it&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;correct&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="n"&gt;wrongCount&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;Int&lt;/span&gt; &lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;answers&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;size&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;correctCount&lt;/span&gt;

    &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="n"&gt;isFinished&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;Boolean&lt;/span&gt;
        &lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;correctCount&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="n"&gt;rules&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;passAt&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="n"&gt;wrongCount&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="n"&gt;rules&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;failAt&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="n"&gt;answers&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;size&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="n"&gt;questions&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;size&lt;/span&gt;

    &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="n"&gt;current&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;Question&lt;/span&gt;&lt;span class="o"&gt;?&lt;/span&gt; &lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;isFinished&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;null&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="n"&gt;questions&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;answers&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;size&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;failAt&lt;/code&gt; falls out of the other two numbers: once you can no longer reach the pass mark, there's no point asking more. Questions are drawn at random from the pool you study, and the drawn order is saved, so an interview in progress can be restored with the same questions.&lt;/p&gt;

&lt;h2&gt;
  
  
  Matching answers: lenient like the officer, strict where it matters
&lt;/h2&gt;

&lt;p&gt;The speech recognizer gives you a string like "the president of the united states". USCIS lists accepted answers, sometimes several, sometimes with optional parts. A naive &lt;code&gt;==&lt;/code&gt; fails almost everything; a naive "contains" accepts nonsense.&lt;/p&gt;

&lt;p&gt;The rule I settled on: &lt;strong&gt;every word of an accepted answer must be there, extra words are fine, but certain extra words are not.&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight kotlin"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Extra words are fine ("the President of the United States"), except these:&lt;/span&gt;
&lt;span class="c1"&gt;// each turns an accepted answer into a different one.&lt;/span&gt;
&lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="n"&gt;meaningChangers&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;setOf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"vice"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"not"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"no"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"never"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"former"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"deputy"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"lieutenant"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"assistant"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;fun&lt;/span&gt; &lt;span class="nf"&gt;matchedAnswers&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;given&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;String&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;accepted&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;List&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;String&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;List&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;String&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="n"&gt;words&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;AnswerText&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;words&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;given&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;words&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;isEmpty&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;emptyList&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;accepted&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;filter&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;answer&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;
        &lt;span class="nf"&gt;variants&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;answer&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;any&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;variant&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;
            &lt;span class="nf"&gt;containsAll&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;words&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;variant&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="n"&gt;words&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;none&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;it&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;meaningChangers&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="n"&gt;it&lt;/span&gt; &lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;variant&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Without that list, "the Vice President" would match the accepted answer "the President", because every word of "the President" is present. With it, the extra "vice" flips the match off, unless the accepted answer itself contains it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Variants: what the officer would also accept
&lt;/h2&gt;

&lt;p&gt;The official answers are written for people, not parsers:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Words in parentheses are optional.&lt;/strong&gt; "(U.S.) Constitution" is also just "Constitution".&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;A number in parentheses is the same answer in digits.&lt;/strong&gt; "One hundred (100)" is also "100".&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;"The United States" inside a longer answer is optional&lt;/strong&gt;, because every question is about the country: "Obey the laws of the United States" is also "obey the laws". An answer that is only the country still needs it.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Each accepted answer expands into these variants, and a match against any variant counts. Some questions need more than one answer ("name two rights"), so the matcher counts distinct accepted answers found in what you said.&lt;/p&gt;

&lt;h2&gt;
  
  
  Absorbing recognizer slips, but not in numbers
&lt;/h2&gt;

&lt;p&gt;Speech recognition mishears, and people misspell when typing. So words count as matching when they're within a small edit distance, scaled by length:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight kotlin"&gt;&lt;code&gt;&lt;span class="k"&gt;internal&lt;/span&gt; &lt;span class="k"&gt;fun&lt;/span&gt; &lt;span class="nf"&gt;close&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;String&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;String&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;Boolean&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;any&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Char&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;isDigit&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;any&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Char&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;isDigit&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;   &lt;span class="c1"&gt;// numbers must match exactly&lt;/span&gt;
    &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="n"&gt;allowed&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;when&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;minOf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;length&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;length&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;
        &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="mi"&gt;7&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
        &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;allowed&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nc"&gt;Edits&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;distance&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;limit&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;allowed&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="n"&gt;allowed&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Short words get no slack, because "war" and "was", or "law" and "low", are one letter apart and mean different things. "constitusion" still matches "constitution". Numbers get no slack at all: 27 amendments is not 28. The Levenshtein check gives up early once it passes the limit, since it runs for every word pair.&lt;/p&gt;

&lt;p&gt;Each accepted word also has to match a &lt;em&gt;different&lt;/em&gt; spoken word, so one "states" can't satisfy an answer that needs it twice.&lt;/p&gt;

&lt;h2&gt;
  
  
  Testing it
&lt;/h2&gt;

&lt;p&gt;Because it's all plain functions, the matcher, the interview rules and the review schedule are covered by ordinary JVM unit tests: a recognizer-style string in, a verdict out. Adding a tricky phrase is one more test case, with no device or emulator involved.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I'd pass on
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;If your app grades free-form answers, write down &lt;em&gt;why&lt;/em&gt; each answer is accepted. The edge cases come from that reasoning, not from the answer list.&lt;/li&gt;
&lt;li&gt;Be lenient about form and strict about meaning, and decide explicitly which words carry meaning.&lt;/li&gt;
&lt;li&gt;Keep the rules in a pure module, so every tricky phrase can become a fast unit test.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Belong is on &lt;a href="https://play.google.com/store/apps/details?id=org.truetechsol.belong.us" rel="noopener noreferrer"&gt;Google Play&lt;/a&gt;. Every civics question, flashcards, quizzes and audio are always free, with no account, and it works offline. Your first mock interview is free, and Pro unlocks unlimited ones. If you've been through the interview, I'd like to know what would have helped you most.&lt;/p&gt;

</description>
      <category>android</category>
      <category>kotlin</category>
      <category>testing</category>
      <category>showdev</category>
    </item>
    <item>
      <title>Opening Word, Excel and PowerPoint files on Android without uploading them</title>
      <dc:creator>Rao Asad</dc:creator>
      <pubDate>Wed, 11 Nov 2026 14:39:02 +0000</pubDate>
      <link>https://dev.to/rao_asad_fb657aebdb761ad4/opening-word-excel-and-powerpoint-files-on-android-without-uploading-them-3gf7</link>
      <guid>https://dev.to/rao_asad_fb657aebdb761ad4/opening-word-excel-and-powerpoint-files-on-android-without-uploading-them-3gf7</guid>
      <description>&lt;p&gt;Someone sends you a .docx on WhatsApp. On a lot of phones, opening it means installing a large office suite, or a "document reader" that uploads the file somewhere to convert it.&lt;/p&gt;

&lt;p&gt;I wanted &lt;a href="https://play.google.com/store/apps/details?id=org.truetechsol.pagewell" rel="noopener noreferrer"&gt;Pagewell&lt;/a&gt;, my document reader for Android, to open PDF, Word, Excel and PowerPoint files entirely on the phone. There's no single library that does that well, so it's a different engine per format, chosen by testing rather than by reputation. Here's how it fits together.&lt;/p&gt;

&lt;h2&gt;
  
  
  Pick engines with ugly files, not pretty ones
&lt;/h2&gt;

&lt;p&gt;Before choosing anything, I collected 30 hard files and opened each candidate on a mid-range phone (a Redmi Note 12): Urdu and Arabic text, documents full of images and charts, a 300-chapter book, a 50,000-row spreadsheet, and a few damaged files. Most libraries handle a tidy sample document fine. The difference shows up on these.&lt;/p&gt;

&lt;p&gt;What won:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Format&lt;/th&gt;
&lt;th&gt;Engine&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;PDF&lt;/td&gt;
&lt;td&gt;Android's own &lt;code&gt;PdfRenderer&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;DOCX&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;docx-preview&lt;/code&gt; in a WebView&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;PPTX&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;pptx-to-html&lt;/code&gt; in a WebView, patched&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;XLSX&lt;/td&gt;
&lt;td&gt;A native Office preview view, with a plain-table fallback&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;XLS and very large XLSX&lt;/td&gt;
&lt;td&gt;SheetJS in a WebView, values only&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;TXT, CSV, MD, LOG&lt;/td&gt;
&lt;td&gt;A plain &lt;code&gt;TextView&lt;/code&gt;, first 2 MB&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Old binary &lt;code&gt;.doc&lt;/code&gt; and &lt;code&gt;.ppt&lt;/code&gt; files get a clear "old Office format" message instead of a half-broken render. I'd rather say no than show a wrong page.&lt;/p&gt;

&lt;h2&gt;
  
  
  A WebView that can't reach the internet
&lt;/h2&gt;

&lt;p&gt;Three of those engines are JavaScript, so they run in a WebView. A document is untrusted input, and an HTML-based viewer is exactly where a crafted file could try to load something from the network. So the WebView is locked down:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The viewer page and its scripts are served from the APK through &lt;code&gt;WebViewAssetLoader&lt;/code&gt;, not from a URL.&lt;/li&gt;
&lt;li&gt;The document is copied privately and served at one fixed path, &lt;code&gt;/doc/current&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Every other request gets an empty response.&lt;/strong&gt; A document can't fetch a tracking pixel, a font, or anything else.&lt;/li&gt;
&lt;li&gt;File and content access are switched off, and links open in the browser, outside the viewer.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;textZoom = 100&lt;/code&gt;, so the phone's font-size setting doesn't reflow the page into something unreadable.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The result: reading a file never sends it, or anything in it, off the phone.&lt;/p&gt;

&lt;h2&gt;
  
  
  Two things I had to fix in other people's code
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Invisible PowerPoint text.&lt;/strong&gt; In some decks, text with no colour of its own vanished. The converter fell back to the shape's fill colour, which made white text on a white shape. The fix was to read the colour from the shape style's font reference (&lt;code&gt;fontRef&lt;/code&gt;) instead. The patched script ships inside the app.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;A dependency with a security advisory.&lt;/strong&gt; The &lt;code&gt;xlsx&lt;/code&gt; package on npm has an unfixed advisory. SheetJS publishes fixed builds on its own CDN, so Pagewell bundles version 0.20.3 from there, not from npm. It's an easy one to miss if you install packages on autopilot.&lt;/p&gt;

&lt;h2&gt;
  
  
  PDFs: native first
&lt;/h2&gt;

&lt;p&gt;PDFs use the platform's &lt;code&gt;PdfRenderer&lt;/code&gt;, which is fast and has no extra dependency. Pages render on one background thread as they scroll into view, with a 96 MB bitmap cache, and they're drawn as sheets of paper with a gap and a soft shadow, sized from the list's real width so they keep their shape.&lt;/p&gt;

&lt;p&gt;The one gap: &lt;code&gt;PdfRenderer&lt;/code&gt; only accepts a password from Android 15. So for a locked PDF, Pagewell asks for the password, uses PDFBox to decrypt it into a private copy, and renders that.&lt;/p&gt;

&lt;h2&gt;
  
  
  Getting picked from "Open with"
&lt;/h2&gt;

&lt;p&gt;A reader is only useful if it shows up when you tap a file in another app. The manifest has to match by MIME type, but apps are inconsistent about what they send. WhatsApp, Telegram and many file managers send &lt;code&gt;application/octet-stream&lt;/code&gt; for everything, so Pagewell also matches that, plus older and macro-enabled Office types, and falls back to the file extension when no type is sent. The viewer then decides what the file is by its name first.&lt;/p&gt;

&lt;p&gt;One phone-specific surprise: Xiaomi's File Manager sends a tapped document straight to WPS Office. There, Pagewell is reachable through a long-press, then "Open in another app".&lt;/p&gt;

&lt;p&gt;Remembering recent files had its own catch. Apps usually grant access to a file only until the receiving app closes, so a saved link stops working tomorrow. Pagewell stores a lasting grant when the source offers one, and otherwise (with All files access) the file's own path. An entry that truly can't be reached any more says so and drops off the list.&lt;/p&gt;

&lt;h2&gt;
  
  
  Editing without breaking the original
&lt;/h2&gt;

&lt;p&gt;The editing tools never change your file; every result is saved as a new copy in &lt;code&gt;Downloads/Pagewell&lt;/code&gt;.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Edit PDF&lt;/strong&gt;: marks (pen strokes, highlights, text notes) are stored as fractions of the page, so they survive zoom. On save, each edited page gets one transparent PNG at twice the page size laid over it with PDFBox. That keeps handwriting and every language exactly as drawn.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Edit Word&lt;/strong&gt;: each paragraph of &lt;code&gt;word/document.xml&lt;/code&gt; becomes a text field. A changed paragraph keeps its first run's formatting, unchanged ones stay exactly as they were, and every other part of the zip is copied untouched. The honest limit: mixed formatting inside a paragraph you edit gets flattened.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Compress&lt;/strong&gt; redraws each page as a JPEG at 72, 110 or 150 dpi. It's the only approach that shrinks any PDF, at the cost of turning text into pictures.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Known limits
&lt;/h2&gt;

&lt;p&gt;Excel charts and images inside sheets aren't drawn, right-to-left sheets can clip text, and very large sheets open as a plain table. Old &lt;code&gt;.doc&lt;/code&gt; and &lt;code&gt;.ppt&lt;/code&gt; files don't open at all. Better to list these than pretend the engines cover everything.&lt;/p&gt;

&lt;p&gt;Pagewell is on &lt;a href="https://play.google.com/store/apps/details?id=org.truetechsol.pagewell" rel="noopener noreferrer"&gt;Google Play&lt;/a&gt;. Reading is free, with no ads while you read and no account. Pro unlocks the tools: signing and editing PDFs, editing Word text, and merging, extracting, compressing or locking PDFs. If you've found a file format that breaks a WebView viewer, send it my way.&lt;/p&gt;

</description>
      <category>android</category>
      <category>kotlin</category>
      <category>webview</category>
      <category>showdev</category>
    </item>
    <item>
      <title>There are no fancy fonts in your Instagram bio: Unicode, its holes, and Android's text menu</title>
      <dc:creator>Rao Asad</dc:creator>
      <pubDate>Wed, 11 Nov 2026 14:37:46 +0000</pubDate>
      <link>https://dev.to/rao_asad_fb657aebdb761ad4/there-are-no-fancy-fonts-in-your-instagram-bio-unicode-its-holes-and-androids-text-menu-3lp5</link>
      <guid>https://dev.to/rao_asad_fb657aebdb761ad4/there-are-no-fancy-fonts-in-your-instagram-bio-unicode-its-holes-and-androids-text-menu-3lp5</guid>
      <description>&lt;p&gt;When someone writes their name as 𝐀𝐬𝐚𝐝 or 𝒜𝓈𝒶𝒹 in a bio, it looks like a font. It isn't. Instagram, WhatsApp and TikTok only let you send plain text, so the "font" is really a different set of characters that happen to look like styled letters.&lt;/p&gt;

&lt;p&gt;I built &lt;a href="https://play.google.com/store/apps/details?id=org.truetechsol.wryte" rel="noopener noreferrer"&gt;Wryte&lt;/a&gt;, a fancy-text app for Android, around that idea. Here's how the styles actually work, the gaps in Unicode that trip up a naive converter, and how Wryte restyles text inside any other app through Android's text-selection menu.&lt;/p&gt;

&lt;h2&gt;
  
  
  The trick: Mathematical Alphanumeric Symbols
&lt;/h2&gt;

&lt;p&gt;Unicode has a block called Mathematical Alphanumeric Symbols, starting at U+1D400. It exists so mathematicians can write a bold 𝐀 that means something different from a plain A. For us, it's a full set of bold, italic, script, gothic (fraktur), double-struck, sans-serif and monospace alphabets.&lt;/p&gt;

&lt;p&gt;Within each style, A–Z and a–z are laid out in order. So a style is just an offset:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight kotlin"&gt;&lt;code&gt;&lt;span class="cm"&gt;/** Maps A–Z, a–z and optionally 0–9 onto a contiguous block, with per-letter exceptions. */&lt;/span&gt;
&lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="k"&gt;fun&lt;/span&gt; &lt;span class="nf"&gt;math&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;String&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;upper&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;Int&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;lower&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;Int&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;digits&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;Int&lt;/span&gt;&lt;span class="o"&gt;?&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;holes&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;Map&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Char&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;Char&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;emptyMap&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;String&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="n"&gt;sb&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;StringBuilder&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="n"&gt;hole&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;holes&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
        &lt;span class="k"&gt;when&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="n"&gt;hole&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="k"&gt;null&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;sb&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;hole&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="n"&gt;c&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="s1"&gt;'A'&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="s1"&gt;'Z'&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;sb&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;appendCodePoint&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;upper&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="s1"&gt;'A'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="n"&gt;c&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="s1"&gt;'a'&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="s1"&gt;'z'&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;sb&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;appendCodePoint&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;lower&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="s1"&gt;'a'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="n"&gt;c&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="s1"&gt;'0'&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="s1"&gt;'9'&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="n"&gt;digits&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="k"&gt;null&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;sb&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;appendCodePoint&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;digits&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="s1"&gt;'0'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;sb&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;sb&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;toString&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nf"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"bold"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"Bold"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;FontGroup&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&gt;CLASSIC&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nf"&gt;math&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;it&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mh"&gt;0x1D400&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mh"&gt;0x1D41A&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mh"&gt;0x1D7CE&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note &lt;code&gt;appendCodePoint&lt;/code&gt;, not &lt;code&gt;append(Char)&lt;/code&gt;. These characters are outside the Basic Multilingual Plane, so each one is two UTF-16 chars (a surrogate pair). That has a visible side effect: code that counts &lt;code&gt;String.length&lt;/code&gt; sees your bold name as twice as long as it is, so a character limit can fill up faster with styled text.&lt;/p&gt;

&lt;h2&gt;
  
  
  The holes
&lt;/h2&gt;

&lt;p&gt;Apply that offset blindly to the italic alphabet and the word "the" comes out with an empty box where the &lt;em&gt;h&lt;/em&gt; should be. Some letters in the math block are reserved and empty. The reason is history: a few of these letters were already in Unicode, in the older Letterlike Symbols block, before the math block existed. Italic &lt;em&gt;h&lt;/em&gt; was already there as ℎ (U+210E, the Planck constant), so its slot in the new block was left empty rather than encoded twice.&lt;/p&gt;

&lt;p&gt;Every style has its own set of holes, so every style carries its own exceptions:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight kotlin"&gt;&lt;code&gt;&lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="no"&gt;ITALIC&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;mapOf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'h'&lt;/span&gt; &lt;span class="n"&gt;to&lt;/span&gt; &lt;span class="s1"&gt;'ℎ'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="no"&gt;SCRIPT&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;mapOf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="s1"&gt;'B'&lt;/span&gt; &lt;span class="n"&gt;to&lt;/span&gt; &lt;span class="s1"&gt;'ℬ'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'E'&lt;/span&gt; &lt;span class="n"&gt;to&lt;/span&gt; &lt;span class="s1"&gt;'ℰ'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'F'&lt;/span&gt; &lt;span class="n"&gt;to&lt;/span&gt; &lt;span class="s1"&gt;'ℱ'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'H'&lt;/span&gt; &lt;span class="n"&gt;to&lt;/span&gt; &lt;span class="s1"&gt;'ℋ'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'I'&lt;/span&gt; &lt;span class="n"&gt;to&lt;/span&gt; &lt;span class="s1"&gt;'ℐ'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'L'&lt;/span&gt; &lt;span class="n"&gt;to&lt;/span&gt; &lt;span class="s1"&gt;'ℒ'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'M'&lt;/span&gt; &lt;span class="n"&gt;to&lt;/span&gt; &lt;span class="s1"&gt;'ℳ'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s1"&gt;'R'&lt;/span&gt; &lt;span class="n"&gt;to&lt;/span&gt; &lt;span class="s1"&gt;'ℛ'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'e'&lt;/span&gt; &lt;span class="n"&gt;to&lt;/span&gt; &lt;span class="s1"&gt;'ℯ'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'g'&lt;/span&gt; &lt;span class="n"&gt;to&lt;/span&gt; &lt;span class="s1"&gt;'ℊ'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'o'&lt;/span&gt; &lt;span class="n"&gt;to&lt;/span&gt; &lt;span class="s1"&gt;'ℴ'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="no"&gt;FRAKTUR&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;mapOf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'C'&lt;/span&gt; &lt;span class="n"&gt;to&lt;/span&gt; &lt;span class="s1"&gt;'ℭ'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'H'&lt;/span&gt; &lt;span class="n"&gt;to&lt;/span&gt; &lt;span class="s1"&gt;'ℌ'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'I'&lt;/span&gt; &lt;span class="n"&gt;to&lt;/span&gt; &lt;span class="s1"&gt;'ℑ'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'R'&lt;/span&gt; &lt;span class="n"&gt;to&lt;/span&gt; &lt;span class="s1"&gt;'ℜ'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'Z'&lt;/span&gt; &lt;span class="n"&gt;to&lt;/span&gt; &lt;span class="s1"&gt;'ℨ'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="no"&gt;DOUBLE&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;mapOf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'C'&lt;/span&gt; &lt;span class="n"&gt;to&lt;/span&gt; &lt;span class="s1"&gt;'ℂ'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'H'&lt;/span&gt; &lt;span class="n"&gt;to&lt;/span&gt; &lt;span class="s1"&gt;'ℍ'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'N'&lt;/span&gt; &lt;span class="n"&gt;to&lt;/span&gt; &lt;span class="s1"&gt;'ℕ'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'P'&lt;/span&gt; &lt;span class="n"&gt;to&lt;/span&gt; &lt;span class="s1"&gt;'ℙ'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'Q'&lt;/span&gt; &lt;span class="n"&gt;to&lt;/span&gt; &lt;span class="s1"&gt;'ℚ'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'R'&lt;/span&gt; &lt;span class="n"&gt;to&lt;/span&gt; &lt;span class="s1"&gt;'ℝ'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'Z'&lt;/span&gt; &lt;span class="n"&gt;to&lt;/span&gt; &lt;span class="s1"&gt;'ℤ'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you ever write one of these converters, test every letter of every style, not just "Hello". The holes are exactly the letters a quick test skips.&lt;/p&gt;

&lt;p&gt;Not every style comes from the math block. Circled letters (Ⓐ) sit at U+24B6, small caps and similar styles are hand-built tables of lookalike characters, and frames and decorations wrap the result rather than changing it. In total Wryte has 154 fonts and 52 frames.&lt;/p&gt;

&lt;h2&gt;
  
  
  Styling text inside any app
&lt;/h2&gt;

&lt;p&gt;Copying from one app and pasting into another gets old quickly. Android has a better hook: &lt;code&gt;ACTION_PROCESS_TEXT&lt;/code&gt;. Any activity that declares it appears in the menu that pops up over selected text, in every app that uses the standard text views.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight xml"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;activity&lt;/span&gt; &lt;span class="na"&gt;android:name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;".ProcessTextActivity"&lt;/span&gt; &lt;span class="na"&gt;android:exported&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"true"&lt;/span&gt; &lt;span class="na"&gt;android:theme&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"@style/Theme.Wryte.Sheet"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;intent-filter&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;action&lt;/span&gt; &lt;span class="na"&gt;android:name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"android.intent.action.PROCESS_TEXT"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;category&lt;/span&gt; &lt;span class="na"&gt;android:name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"android.intent.category.DEFAULT"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;data&lt;/span&gt; &lt;span class="na"&gt;android:mimeType&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"text/plain"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/intent-filter&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/activity&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The activity receives the selection in &lt;code&gt;EXTRA_PROCESS_TEXT&lt;/code&gt;, and a flag that matters: &lt;code&gt;EXTRA_PROCESS_TEXT_READONLY&lt;/code&gt;. If the text is in an editable field, you return the new text as the result and Android puts it in place of the selection. If it's read-only (a message someone sent you, say), there's nowhere to put it back, so Wryte copies it instead.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight kotlin"&gt;&lt;code&gt;&lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="k"&gt;fun&lt;/span&gt; &lt;span class="nf"&gt;deliver&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;String&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;readOnly&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;Boolean&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;readOnly&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nf"&gt;copyToClipboard&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nf"&gt;setResult&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;RESULT_OK&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;Intent&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;putExtra&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Intent&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&gt;EXTRA_PROCESS_TEXT&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="nf"&gt;finish&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The styles open in a bottom sheet over the other app, so it feels like part of the menu rather than a jump into a different app.&lt;/p&gt;

&lt;h2&gt;
  
  
  A caution I'd give anyone using these
&lt;/h2&gt;

&lt;p&gt;Styled text looks great, but these are mathematical symbols, not letters. Screen readers may read them out symbol by symbol or skip them, and search won't match them against the plain word. It's fine for a name or a bio line; I wouldn't write a whole post in it.&lt;/p&gt;

&lt;p&gt;Wryte is on &lt;a href="https://play.google.com/store/apps/details?id=org.truetechsol.wryte" rel="noopener noreferrer"&gt;Google Play&lt;/a&gt;. It has no ads and needs no account, everything is generated on the phone and works offline, and 20 fonts are free. If you know a Unicode block I should mine next, tell me.&lt;/p&gt;

</description>
      <category>android</category>
      <category>kotlin</category>
      <category>unicode</category>
      <category>showdev</category>
    </item>
    <item>
      <title>Building a QR scanner that never opens a link for you</title>
      <dc:creator>Rao Asad</dc:creator>
      <pubDate>Wed, 11 Nov 2026 14:36:22 +0000</pubDate>
      <link>https://dev.to/rao_asad_fb657aebdb761ad4/building-a-qr-scanner-that-never-opens-a-link-for-you-1261</link>
      <guid>https://dev.to/rao_asad_fb657aebdb761ad4/building-a-qr-scanner-that-never-opens-a-link-for-you-1261</guid>
      <description>&lt;p&gt;Most QR scanner apps do the same thing the moment they see a code: open it. That's convenient right up until the code on a parking meter or a restaurant table has been swapped for a sticker that points somewhere else.&lt;/p&gt;

&lt;p&gt;For &lt;a href="https://play.google.com/store/apps/details?id=org.truetechsol.mintscan" rel="noopener noreferrer"&gt;MintScan&lt;/a&gt;, my QR and barcode scanner for Android, I wanted the opposite default: scan fast, show what the code actually contains, and let you decide. Here's how the scanning side works, and the small safety checks that sit between "decoded" and "opened".&lt;/p&gt;

&lt;h2&gt;
  
  
  Scanning: keep only the latest frame
&lt;/h2&gt;

&lt;p&gt;The camera side is CameraX with an &lt;code&gt;ImageAnalysis&lt;/code&gt; use case, and recognition is Google's bundled ML Kit barcode model, so decoding works offline and nothing is downloaded at first run.&lt;/p&gt;

&lt;p&gt;The thing that matters most for feel is not the decoder, it's what you do with frames you can't process yet:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;STRATEGY_KEEP_ONLY_LATEST&lt;/code&gt;.&lt;/strong&gt; If analysis is still busy, older frames are dropped rather than queued. A queue means the result you see belongs to where the camera was pointing half a second ago.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;One engine, created once.&lt;/strong&gt; An application-scoped &lt;code&gt;ScanEngine&lt;/code&gt; caches an ML Kit client per mode (All, QR only, barcodes only) and warms the All client off the main thread, so the first scan isn't the slow one.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;No overlapping work.&lt;/strong&gt; Analysis runs on its own executor, with a guard so a second frame can't start while the first is still decoding, and a single-shot scan can't be delivered twice.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Mode changes don't restart the camera.&lt;/strong&gt; Frames that were captured under the previous mode are simply ignored, and every &lt;code&gt;ImageProxy&lt;/code&gt; is closed when its work finishes.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The result doesn't wait for the database.&lt;/strong&gt; The parsed record goes straight to the screen; saving it to history happens behind it.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The "All" mode reads QR, Aztec, Data Matrix and PDF417 plus the linear formats (EAN-13, EAN-8, UPC-A, UPC-E, Code 128, Code 39, Code 93, Codabar and ITF): 13 formats in total.&lt;/p&gt;

&lt;h2&gt;
  
  
  Decoded is not the same as opened
&lt;/h2&gt;

&lt;p&gt;When a code contains a web address, MintScan shows it and offers an Open button. It never opens it by itself. Before you tap, it runs a few cheap checks on the URL:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight kotlin"&gt;&lt;code&gt;&lt;span class="k"&gt;fun&lt;/span&gt; &lt;span class="nf"&gt;linkWarnings&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;String&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;List&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;String&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;buildList&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="n"&gt;uri&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="no"&gt;URI&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;uri&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;scheme&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;equals&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"http"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="nf"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"This address uses an unencrypted HTTP connection."&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;uri&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;userInfo&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="k"&gt;null&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="nf"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"This address contains a username section. Check the actual destination carefully."&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;uri&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;host&lt;/span&gt;&lt;span class="o"&gt;?&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;contains&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"xn--"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="nf"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"The domain uses international characters. Check that it matches the site you expect."&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;uri&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;host&lt;/span&gt;&lt;span class="o"&gt;?&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;matches&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Regex&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"[0-9.]+"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="nf"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"This address uses an IP address instead of a domain name."&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Each one catches a classic trick:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;userInfo&lt;/code&gt;&lt;/strong&gt;: &lt;code&gt;https://yourbank.com@evil.example/&lt;/code&gt; reads like your bank's address, but everything before the &lt;code&gt;@&lt;/code&gt; is a username. The real host is &lt;code&gt;evil.example&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;xn--&lt;/code&gt;&lt;/strong&gt;: an internationalised domain arrives as punycode. A domain that looks like a familiar name but uses a lookalike letter from another alphabet shows up this way.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;A bare IP address&lt;/strong&gt; where you'd expect a brand's domain.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Plain HTTP&lt;/strong&gt;, which anyone on the same network can read or alter.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I want to be honest about what this is: these are advisory checks, not malware detection, and they can't promise a site is safe. What they do is turn "it opened" into "here's what it is, and here's anything unusual about it".&lt;/p&gt;

&lt;h2&gt;
  
  
  Sensitive codes aren't saved without asking
&lt;/h2&gt;

&lt;p&gt;Some codes carry things you don't want lying around in a history list. A Wi-Fi code contains the network password; a contact code contains someone's phone number and email.&lt;/p&gt;

&lt;p&gt;So history is on by default, but &lt;strong&gt;Wi-Fi and contact scans are not saved automatically&lt;/strong&gt;. You can still save or favourite them yourself. Wi-Fi passwords stay hidden until you tap to reveal them, and copying or sharing one asks first. On Android 11 and later, MintScan can join the network directly from the code.&lt;/p&gt;

&lt;h2&gt;
  
  
  Two export details worth stealing
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;CSV formula injection.&lt;/strong&gt; MintScan can export your library as CSV. A QR code's content is attacker-controlled text, and a cell starting with &lt;code&gt;=&lt;/code&gt;, &lt;code&gt;+&lt;/code&gt;, &lt;code&gt;-&lt;/code&gt; or &lt;code&gt;@&lt;/code&gt; is a formula when the CSV is opened in a spreadsheet. So every cell is neutralised before it's written:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight kotlin"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Neutralise spreadsheet formula prefixes even when a payload is quoted.&lt;/span&gt;
&lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="n"&gt;value&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;trimStart&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;firstOrNull&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="nf"&gt;listOf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'='&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'+'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'-'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'@'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'\t'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'\r'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="s2"&gt;"'$s"&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt;
&lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s2"&gt;"\"${value.replace("&lt;/span&gt;\&lt;span class="s2"&gt;""&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"\"\""&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;\&lt;span class="s2"&gt;""&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Encrypted backups.&lt;/strong&gt; The backup file is AES-256-GCM with a random salt and IV, the key derived with PBKDF2 at 600,000 iterations, and the file header authenticated as additional data, so a tampered header fails just like a wrong password. Input is capped at 32 MiB, and restore merges by record ID instead of wiping what's already there. There's no password recovery: if there were, the encryption wouldn't mean much.&lt;/p&gt;

&lt;h2&gt;
  
  
  Creating codes
&lt;/h2&gt;

&lt;p&gt;The other half of the app makes codes: websites, text, Wi-Fi, contacts, email, phone, SMS, locations and calendar events as QR, plus Code 128, EAN-13, EAN-8 and UPC-A barcodes. Generation uses ZXing, which also helps check that a styled code still scans. Wi-Fi and vCard payloads need their own escaping (&lt;code&gt;;&lt;/code&gt;, &lt;code&gt;:&lt;/code&gt;, &lt;code&gt;,&lt;/code&gt; and quotes in a network name break a Wi-Fi code surprisingly easily).&lt;/p&gt;

&lt;h2&gt;
  
  
  What I took from it
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Drop frames instead of queueing them. Responsiveness is about freshness, not throughput.&lt;/li&gt;
&lt;li&gt;Treat every decoded string as untrusted input, the same way you'd treat a form field: before opening it, before saving it, and before exporting it.&lt;/li&gt;
&lt;li&gt;Make the safe behaviour the default and the convenient one a single tap away.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;MintScan is on &lt;a href="https://play.google.com/store/apps/details?id=org.truetechsol.mintscan" rel="noopener noreferrer"&gt;Google Play&lt;/a&gt;. Scanning, creating codes and history are free, with no ads and no account; Pro is a one-time purchase for batch scanning, collections, CSV export and custom-styled codes. If you've seen a QR trick these checks would miss, I'd like to hear it.&lt;/p&gt;

</description>
      <category>android</category>
      <category>kotlin</category>
      <category>security</category>
      <category>showdev</category>
    </item>
    <item>
      <title>I wrote my own document scanner and PDF engine for Android. Here's what that involved</title>
      <dc:creator>Rao Asad</dc:creator>
      <pubDate>Mon, 19 Oct 2026 13:00:00 +0000</pubDate>
      <link>https://dev.to/rao_asad_fb657aebdb761ad4/i-wrote-my-own-document-scanner-and-pdf-engine-for-android-heres-what-that-involved-30m2</link>
      <guid>https://dev.to/rao_asad_fb657aebdb761ad4/i-wrote-my-own-document-scanner-and-pdf-engine-for-android-heres-what-that-involved-30m2</guid>
      <description>&lt;p&gt;There are already great ways to add document scanning to an Android app. Google's ML Kit has a ready-made scanner screen, OpenCV can find a page in a few lines, and plenty of libraries write PDFs.&lt;/p&gt;

&lt;p&gt;For &lt;a href="https://keepscan.truetechsol.org" rel="noopener noreferrer"&gt;Keepscan&lt;/a&gt;, I used none of them for the core. The page detection, the camera screen, the perspective correction and the PDF writer are all plain Kotlin on top of platform APIs. The only ML library in the app is on-device text recognition, for copying text out of a scan.&lt;/p&gt;

&lt;p&gt;That wasn't purity. A scanner app &lt;em&gt;is&lt;/em&gt; its engine, and I wanted to be able to change any part of it later without waiting on someone else's roadmap. Here's what building it involved, and the parts that surprised me.&lt;/p&gt;

&lt;h2&gt;
  
  
  Finding the page: lines, not contours
&lt;/h2&gt;

&lt;p&gt;The classic tutorial approach is: edge detection, find the largest closed contour with four corners, done. It works beautifully on a clean page on a dark desk.&lt;/p&gt;

&lt;p&gt;Real photos aren't like that. A thumb covers a corner, a shadow falls across an edge, a white page sits on a light table. Any gap breaks the contour, and the page is lost.&lt;/p&gt;

&lt;p&gt;So Keepscan looks for &lt;strong&gt;straight lines&lt;/strong&gt; instead, and assembles the page from them:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Shrink the frame to 256 px on its long side and blur it. Page edges survive easily; text strokes and paper texture mostly don't.&lt;/li&gt;
&lt;li&gt;Canny edge detection: Sobel gradients, thinned to one-pixel ridges, strong ones kept.&lt;/li&gt;
&lt;li&gt;A Hough transform turns edge pixels into line candidates. A line survives gaps that would break a contour.&lt;/li&gt;
&lt;li&gt;Try every pair of roughly horizontal lines against every pair of roughly vertical ones, and score each quadrilateral.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Two details made the difference.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Rank each direction separately.&lt;/strong&gt; Rows of text produce lots of strong horizontal lines. Ranked together, they crowd out the page's vertical edges entirely. Keeping the top 10 of each direction fixed that.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Score like a page, not like a line.&lt;/strong&gt; A pen lying on the desk is a long straight edge too. What a pen doesn't have is paper on one side and desk on the other. So each side of a candidate is sampled at 48 points, and a point only counts if it sits on an edge pixel &lt;em&gt;and&lt;/em&gt; there's a consistent brightness step across it: the page side brighter (or darker) than the outside, with the same polarity along the whole side. The weakest side weighs heavily in the score, because three good sides and one fake one isn't a page.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight kotlin"&gt;&lt;code&gt;&lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="n"&gt;support&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;total&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mf"&gt;0.6f&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;weakest&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mf"&gt;0.4f&lt;/span&gt;
&lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;support&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mf"&gt;0.55f&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mf"&gt;0.45f&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nf"&gt;sqrt&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;q&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;area&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;   &lt;span class="c1"&gt;// bigger pages get a modest bonus&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;One more refinement: Hough lines are quantised to whole degrees, and over a page-length edge a fraction of a degree moves the ends by several pixels, enough for the scorer to sample &lt;em&gt;beside&lt;/em&gt; the real edge. So each winning line is refitted to the edge pixels within 2 px of it with a total least-squares fit (the direction of least spread in their covariance). That puts it exactly on the edge.&lt;/p&gt;

&lt;p&gt;All of this is pure functions on plain &lt;code&gt;IntArray&lt;/code&gt;s, so it runs identically on a camera frame, a gallery photo and a unit test.&lt;/p&gt;

&lt;h2&gt;
  
  
  Making it feel steady
&lt;/h2&gt;

&lt;p&gt;Per-frame detection flickers. A tracker sits between the detector and the screen:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A new outline only replaces the shown one after it's been seen &lt;strong&gt;twice in a row&lt;/strong&gt;, so one odd frame doesn't make the overlay jump. Small movements are eased rather than snapped.&lt;/li&gt;
&lt;li&gt;A few missed frames keep the last outline, so a passing shadow doesn't blink it away.&lt;/li&gt;
&lt;li&gt;It reports how long the page has held still. &lt;strong&gt;Auto-capture fires after 1.1 seconds of stillness.&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Flattening the page
&lt;/h2&gt;

&lt;p&gt;Once you have four corners, the platform already has what you need: &lt;code&gt;Matrix.setPolyToPoly&lt;/code&gt; with four point pairs is a full perspective transform. The output keeps the page's real proportions (width from the longer of the top and bottom edges, height from the longer side), so a receipt stays receipt-shaped instead of being stretched to A4.&lt;/p&gt;

&lt;h2&gt;
  
  
  Writing PDFs by hand
&lt;/h2&gt;

&lt;p&gt;Android has &lt;code&gt;PdfDocument&lt;/code&gt;, and I started with it. The problem: it re-encodes bitmaps losslessly. A phone scan came out at several megabytes per page, and no quality setting could shrink it.&lt;/p&gt;

&lt;p&gt;A PDF page that's just an image is a small amount of structure around the image bytes, and PDF can embed a JPEG as-is with the &lt;code&gt;/DCTDecode&lt;/code&gt; filter. So Keepscan writes the file itself: catalog, page tree, and for each page a page object, a one-line content stream that draws the image, and the JPEG bytes untouched.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight kotlin"&gt;&lt;code&gt;&lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="n"&gt;content&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"q ${w} 0 0 ${h} 0 0 cm /Im0 Do Q\n"&lt;/span&gt;   &lt;span class="c1"&gt;// scale the image to the page, draw it&lt;/span&gt;
&lt;span class="nf"&gt;stream&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"&amp;lt;&amp;lt; /Type /XObject /Subtype /Image /Width ${page.widthPx} /Height ${page.heightPx} "&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt;
       &lt;span class="s2"&gt;"/ColorSpace /DeviceRGB /BitsPerComponent 8 /Filter /DCTDecode /Length ${jpeg.size} &amp;gt;&amp;gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;jpeg&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The file ends up the size of its images, which is what the size presets promise. Each page is sized so its long side matches A4's (842 pt), keeping the scan's own aspect ratio.&lt;/p&gt;

&lt;h2&gt;
  
  
  "Exactly under 2 MB"
&lt;/h2&gt;

&lt;p&gt;Upload forms love hard limits: "max 2 MB". So Keepscan can save a PDF that's the best quality that still fits under a size you pick.&lt;/p&gt;

&lt;p&gt;There's no formula from settings to file size; it depends on what's on the pages. So there's a ladder of resolution and JPEG-quality pairs, and the exporter &lt;strong&gt;binary-searches&lt;/strong&gt; it: render at the middle rung, check the size, go up or down. A long document is rendered a few times instead of once per rung. Each attempt is written to a file rather than held in memory, because a 30-page document at a high rung is large. If even the smallest rung is too big, you get that file plus an honest "didn't fit".&lt;/p&gt;

&lt;h2&gt;
  
  
  Password-protected PDFs without a PDF library
&lt;/h2&gt;

&lt;p&gt;I added PDFBox for encryption, then removed it the same day. It was a big dependency for one feature. Writing an encrypted PDF is only ever done to Keepscan's own files, and that turns out to be a well-specified, contained job. (PDFBox did come back later for a different job: opening password-protected PDFs that people import, because Android's own PDF renderer only accepts a password from Android 15.)&lt;/p&gt;

&lt;p&gt;It's the PDF Standard security handler, revision 6 (AES-256), from ISO 32000-2, written on &lt;code&gt;javax.crypto&lt;/code&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;One random 256-bit file key encrypts every stream with AES-256-CBC and a random IV in front.&lt;/li&gt;
&lt;li&gt;The user password unlocks that key.&lt;/li&gt;
&lt;li&gt;The owner password also unlocks it, so it's generated randomly and &lt;strong&gt;thrown away&lt;/strong&gt;. There's no second, hidden way into the file.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  The bugs a real phone found
&lt;/h2&gt;

&lt;p&gt;Two came only from testing on an actual device:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Camera callbacks after close.&lt;/strong&gt; Leaving the scanner the moment it opened crashed with "CameraDevice was already closed". The screen closes the camera on the main thread while Camera2 callbacks are still arriving on the camera thread. The fix is a generation counter: every &lt;code&gt;open()&lt;/code&gt; increments it, and every callback checks it still belongs to the current opening before touching anything.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The crop handles you couldn't drag.&lt;/strong&gt; On my Xiaomi, dragging a corner near the screen edge triggered the system back gesture instead. &lt;code&gt;setSystemGestureExclusionRects&lt;/code&gt; is the documented fix, and HyperOS ignores it. I moved the handles 40 dp inward instead. It's less elegant, and it works on every phone.&lt;/p&gt;

&lt;h2&gt;
  
  
  Was it worth it?
&lt;/h2&gt;

&lt;p&gt;It took longer than wiring up libraries would have. But every piece of the pipeline is now code I can read, test and change, and the APK doesn't carry an image-processing library for one screen.&lt;/p&gt;

&lt;p&gt;Keepscan is on &lt;a href="https://play.google.com/store/apps/details?id=org.truetechsol.keepscan" rel="noopener noreferrer"&gt;Google Play&lt;/a&gt;: free to scan, edit and share with no watermark, and Pro is a weekly, monthly or yearly plan or a one-time purchase. If you've built something similar and solved detection differently, I'd like to hear how.&lt;/p&gt;

</description>
      <category>android</category>
      <category>kotlin</category>
      <category>computervision</category>
      <category>showdev</category>
    </item>
    <item>
      <title>Turning bank notifications into expenses on Android, without a bank login</title>
      <dc:creator>Rao Asad</dc:creator>
      <pubDate>Tue, 13 Oct 2026 13:00:00 +0000</pubDate>
      <link>https://dev.to/rao_asad_fb657aebdb761ad4/turning-bank-notifications-into-expenses-on-android-without-a-bank-login-5af2</link>
      <guid>https://dev.to/rao_asad_fb657aebdb761ad4/turning-bank-notifications-into-expenses-on-android-without-a-bank-login-5af2</guid>
      <description>&lt;p&gt;Every time I pay for something, my bank sends a notification: "You spent Rs. 1,250 at ‚Ä¶". The expense tracker on the same phone has no idea it happened, and later I'm expected to type it in by hand.&lt;/p&gt;

&lt;p&gt;That gap is the reason &lt;a href="https://onetap.truetechsol.org" rel="noopener noreferrer"&gt;Onetap&lt;/a&gt; exists. You pick which banking or wallet apps it should watch, and when one of them posts a payment notification, it becomes an expense entry. There's no bank login and no bank API. It only reads notifications you already get, from apps you chose.&lt;/p&gt;

&lt;p&gt;It sounds like a weekend feature. It took a lot longer, mostly because of what has to happen &lt;em&gt;before&lt;/em&gt; any text leaves the phone. Here is how it works and what I got wrong along the way.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Listen to everything, read almost nothing
&lt;/h2&gt;

&lt;p&gt;The entry point is a &lt;code&gt;NotificationListenerService&lt;/code&gt;. Once the user grants notification access, Android hands it &lt;strong&gt;every&lt;/strong&gt; notification on the phone: chats, emails, OTPs, all of it.&lt;/p&gt;

&lt;p&gt;So the very first thing the handler does is look at the package name, and nothing else:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight kotlin"&gt;&lt;code&gt;&lt;span class="k"&gt;fun&lt;/span&gt; &lt;span class="nf"&gt;onPosted&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;Context&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;sbn&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;StatusBarNotification&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="n"&gt;packageName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;sbn&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;packageName&lt;/span&gt; &lt;span class="o"&gt;?:&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;packageName&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;packageName&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt;
    &lt;span class="n"&gt;scope&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;launch&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;// Only apps the user explicitly added. Nothing else about any&lt;/span&gt;
        &lt;span class="c1"&gt;// other notification is ever read.&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="n"&gt;bankApps&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;contains&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;packageName&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt;@&lt;span class="n"&gt;launch&lt;/span&gt;
        &lt;span class="nf"&gt;capture&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;sbn&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A WhatsApp message is dropped before its text is ever touched. I considered auto-detecting finance apps instead, but an explicit list is easier to explain and easier to trust.&lt;/p&gt;

&lt;p&gt;Then a few cheap filters: group summaries repeat their children, and ongoing, foreground-service and progress notifications are status, not events. All of those are skipped.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. One-time codes are never stored or sent
&lt;/h2&gt;

&lt;p&gt;Banking apps send OTPs through the same channel as payment alerts, and an OTP is the most sensitive thing a phone receives. Those are dropped on the device, before anything is saved.&lt;/p&gt;

&lt;p&gt;The naive check ("does it contain 'OTP'?") is wrong in both directions:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Lots of real &lt;strong&gt;payment&lt;/strong&gt; alerts end with "Never share your OTP with anyone." A keyword check throws those away.&lt;/li&gt;
&lt;li&gt;"Rs 5000" is a 4-digit number, but it's an amount, not a code.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So a message counts as a one-time code only when both are true: it names a code (OTP, verification code, MPIN‚Ä¶) &lt;strong&gt;outside&lt;/strong&gt; a safety reminder, and it contains a bare 4‚Äì8 digit number that isn't preceded by a currency mark.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight kotlin"&gt;&lt;code&gt;&lt;span class="k"&gt;fun&lt;/span&gt; &lt;span class="nf"&gt;isOneTimeCode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;String&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;Boolean&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="n"&gt;lower&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;lowercase&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Locale&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&gt;ROOT&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="n"&gt;withoutReminders&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;lower&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;replace&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;REMINDER&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;" "&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;   &lt;span class="c1"&gt;// "never share your otp‚Ä¶"&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="no"&gt;CODE_WORD&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;containsMatchIn&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;withoutReminders&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="no"&gt;BARE_NUMBER&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;findAll&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;lower&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;any&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;number&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;
        &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="n"&gt;before&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;lower&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;substring&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;maxOf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;number&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;range&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;first&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;number&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;range&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;first&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="no"&gt;CURRENCY_BEFORE&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;containsMatchIn&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;before&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;          &lt;span class="c1"&gt;// "rs 5000" is money&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It's all pure functions, so every real notification that ever confused it became a unit test.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Mask account numbers before anything leaves
&lt;/h2&gt;

&lt;p&gt;The text of a payment alert does need to be read by a language model: bank formats vary far too much for regexes alone. But the model doesn't need your card number. Card, account, IBAN and phone numbers are masked on the phone first, keeping the last four digits:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Before: Rs 2,000 sent from a/c 01234567890123 to 0300 1234567
After:  Rs 2,000 sent from a/c ****0123 to 0300 1234567
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Wait, the phone number survived. That's the interesting part: the rules have to mask long identifiers &lt;em&gt;without&lt;/em&gt; masking amounts, dates or times. What I settled on:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;9 or more digits written together ‚Üí masked&lt;/li&gt;
&lt;li&gt;12 or more digits in groups of 3+ separated by spaces or dashes (&lt;code&gt;4111 1111 1111 1234&lt;/code&gt;) ‚Üí masked&lt;/li&gt;
&lt;li&gt;IBAN-shaped strings ‚Üí masked&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;1,250,000&lt;/code&gt; (commas) and &lt;code&gt;15-09-2026 14:32&lt;/code&gt; (short groups) ‚Üí left alone&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A local 11-digit phone number written as &lt;code&gt;0300 1234567&lt;/code&gt; is two groups, so it isn't caught by the grouped rule. Written as &lt;code&gt;03001234567&lt;/code&gt; it is. That's a known gap I'd rather tell you about than hide. Every rule is a test case, and each new bank format adds more.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Don't let the model guess what it can't know
&lt;/h2&gt;

&lt;p&gt;The model gets the masked text plus the user's categories, and returns structured JSON: amount, merchant, category, date. That part works well.&lt;/p&gt;

&lt;p&gt;What went wrong was currency. A real alert read "You spent Rs. 5,930.18" and was recorded as &lt;strong&gt;$62.00&lt;/strong&gt; in a USD list. The model had been asked which currency "Rs" was, and it said INR. The correct answer was Pakistani rupees: $21.40.&lt;/p&gt;

&lt;p&gt;"Rs" is written by Pakistan, India, Sri Lanka and Nepal. The model was reading the same two characters I was, with no extra information. Its answer &lt;em&gt;looked&lt;/em&gt; like knowledge and was really a coin flip. I'd even written a function that refused to trust it, and then the very next line fell back to the model's answer anyway.&lt;/p&gt;

&lt;p&gt;The lesson I took: &lt;strong&gt;a model's answer to an ambiguous question isn't evidence.&lt;/strong&gt; Tie-breakers have to come from something that actually knows. For a rupee, that's the list's own currency, then the SIM's country (not the phone's language: my phone runs English on a Pakistani SIM). And if nothing knows, ask the user rather than guess.&lt;/p&gt;

&lt;p&gt;For now I've gone further and switched conversion off: Onetap records the amount the alert states, in the list's currency, and you keep a rupee bank on a rupee list. The cleaner fix, which I haven't built yet, is binding each bank app to its own list, so conversion is never needed in the first place.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. Never lose a payment
&lt;/h2&gt;

&lt;p&gt;A notification shows up once. If the app drops it, that payment is gone from the record and the user won't know. So:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Write to disk first.&lt;/strong&gt; Each kept notification goes into an encrypted inbox before any network call.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Retry with WorkManager.&lt;/strong&gt; No network in the metro? The entry waits, and a worker tries again when connectivity returns, however long that takes.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;De-duplicate with a fingerprint.&lt;/strong&gt; Banks sometimes post the same alert twice, and retries can overlap. A SHA-256 of the package, the normalised words and the post time means the same payment is never recorded twice, even if the process dies halfway through.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Catch up on reconnect.&lt;/strong&gt; While the listener isn't bound, nothing is heard. When it reconnects, it reads the bank notifications still sitting in the shade from the last three days, skipping ones it has already handled.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  6. The phone that kills your listener
&lt;/h2&gt;

&lt;p&gt;On my Xiaomi (HyperOS), the first real test failed silently. From logcat:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Swiping the app away from recents &lt;strong&gt;kills the process&lt;/strong&gt;, listener included.&lt;/li&gt;
&lt;li&gt;With "Autostart" off, the system &lt;strong&gt;refuses to rebind&lt;/strong&gt; the notification listener, so nothing is heard until the user opens the app again.&lt;/li&gt;
&lt;li&gt;After an app &lt;strong&gt;update&lt;/strong&gt;, the listener can stay unbound even though access is still granted. Calling &lt;code&gt;requestRebind()&lt;/code&gt; and toggling the listener component's enabled state brings it back.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Onetap now asks for Autostart only on Xiaomi, Redmi and POCO phones, inside the bank-automation setup, with an explanation of why. With it on, a real wallet payment of Rs 1 was recorded 1.2 seconds after its notification arrived.&lt;/p&gt;

&lt;h2&gt;
  
  
  Testing it without spending money
&lt;/h2&gt;

&lt;p&gt;You don't want to make a real payment for every test. Debug builds also accept notifications posted from the shell:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;adb shell cmd notification post -S bigtext -t &lt;span class="s2"&gt;"HBL"&lt;/span&gt; test-1 \
  &lt;span class="s2"&gt;"PKR 1,250.00 debited from a/c 01234567890123 at FOODPANDA on 06-10-2026"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;These come from &lt;code&gt;com.android.shell&lt;/code&gt;, which the debug build treats as a bank app (never in release). That gave me a repeatable way to run real-looking bank text, OTPs and odd formats through the whole pipeline on a real phone.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I'd tell anyone building this
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Filter by package &lt;strong&gt;before&lt;/strong&gt; reading content. It's the difference between "reads my bank alerts" and "reads my messages".&lt;/li&gt;
&lt;li&gt;Decide what must never leave the device, and enforce it in pure, tested functions.&lt;/li&gt;
&lt;li&gt;Treat model output as a suggestion, not a fact, wherever the input is ambiguous.&lt;/li&gt;
&lt;li&gt;Assume Android will kill you, and write things down before doing anything slow.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Onetap is on &lt;a href="https://play.google.com/store/apps/details?id=org.truetechsol.onetap" rel="noopener noreferrer"&gt;Google Play&lt;/a&gt; with a 3-day free trial if you want to try it with your own bank. If yours sends a format it misreads, I'd really like to see it (with the numbers removed).&lt;/p&gt;

</description>
      <category>android</category>
      <category>kotlin</category>
      <category>privacy</category>
      <category>showdev</category>
    </item>
    <item>
      <title>5 Android bugs my tests didn't catch while shipping an expense tracker</title>
      <dc:creator>Rao Asad</dc:creator>
      <pubDate>Tue, 06 Oct 2026 10:58:27 +0000</pubDate>
      <link>https://dev.to/rao_asad_fb657aebdb761ad4/5-android-bugs-my-tests-didnt-catch-while-shipping-an-expense-tracker-131h</link>
      <guid>https://dev.to/rao_asad_fb657aebdb761ad4/5-android-bugs-my-tests-didnt-catch-while-shipping-an-expense-tracker-131h</guid>
      <description>&lt;p&gt;I've spent the last few months building and shipping &lt;a href="https://coinly.truetechsol.org" rel="noopener noreferrer"&gt;Coinly&lt;/a&gt;, an expense tracker for Android. It's a normal Kotlin app: MVVM, coroutines and Flow, Room, Gson, R8 in release.&lt;/p&gt;

&lt;p&gt;It also had a reasonable test suite. None of these five bugs failed a single test. Every one of them reached a real build, and a couple of them reached real users.&lt;/p&gt;

&lt;p&gt;Here they are, with the fix for each, in case they save you an evening.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Gson + R8: fields that silently come back as defaults
&lt;/h2&gt;

&lt;p&gt;Exchange rates stopped working in the first release build. No crash, no error. Rates just came back empty, and Drive backup quietly decided there was no existing backup to restore.&lt;/p&gt;

&lt;p&gt;The cause: when a field has no &lt;code&gt;@SerializedName&lt;/code&gt;, Gson matches JSON keys &lt;strong&gt;by field name&lt;/strong&gt;. R8 renames fields in release builds. So the JSON key &lt;code&gt;rates&lt;/code&gt; no longer matched a field called &lt;code&gt;rates&lt;/code&gt;, because that field was now called &lt;code&gt;a&lt;/code&gt;. Gson didn't complain. It left the field at its default.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight kotlin"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Works in debug, silently broken in release&lt;/span&gt;
&lt;span class="n"&gt;data&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;RatesResponse&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;String&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;""&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="n"&gt;rates&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;Map&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;String&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;Double&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;emptyMap&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;// Works in both&lt;/span&gt;
&lt;span class="n"&gt;data&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;RatesResponse&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="nd"&gt;@SerializedName&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"result"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;String&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;""&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nd"&gt;@SerializedName&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"rates"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="n"&gt;rates&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;Map&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;String&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;Double&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;emptyMap&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Two things made this nasty:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Debug builds aren't minified&lt;/strong&gt;, so every test on my phone passed.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Default values turn a crash into a wrong answer.&lt;/strong&gt; &lt;code&gt;emptyList()&lt;/code&gt; for "files in Drive" reads as "no backup exists", so a release build would have happily written a second backup next to the one it couldn't see.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A &lt;code&gt;-keep&lt;/code&gt; rule alone isn't enough either: it stops the class from being removed, but its fields can still be renamed. I now put &lt;code&gt;@SerializedName&lt;/code&gt; on every field of every Gson class, including the ones whose Kotlin name already matches the key. Those are exactly the ones people leave bare.&lt;/p&gt;

&lt;p&gt;The general lesson: a release smoke test that checks "the app opens and the screens render" proves very little. R8 breaks data paths, not layouts.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. &lt;code&gt;StateFlow.value&lt;/code&gt; that is forever the initial value
&lt;/h2&gt;

&lt;p&gt;This one showed up three separate times.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight kotlin"&gt;&lt;code&gt;&lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="n"&gt;history&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;StateFlow&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;List&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Period&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;repo&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;observeHistory&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;stateIn&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;viewModelScope&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;SharingStarted&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;WhileSubscribed&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;5_000&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;emptyList&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;fun&lt;/span&gt; &lt;span class="nf"&gt;onDeleteClicked&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;history&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;isNotEmpty&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="nf"&gt;showTwoWayDialog&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="nf"&gt;showSimpleDialog&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;WhileSubscribed&lt;/code&gt; only starts the upstream flow when something collects it. Nothing collected &lt;code&gt;history&lt;/code&gt;. It was only ever read as &lt;code&gt;.value&lt;/code&gt; from a click handler. So &lt;code&gt;.value&lt;/code&gt; was always &lt;code&gt;emptyList()&lt;/code&gt;, and a budget with three months of history reported "no history".&lt;/p&gt;

&lt;p&gt;The worst instance was on the Delete Account dialog: a user who was connected to Google Drive was told "you're not connected, so nothing is stored outside this device". The deletion itself was correct; the sentence was false.&lt;/p&gt;

&lt;p&gt;The rule I use now: &lt;strong&gt;if a StateFlow is only read through &lt;code&gt;.value&lt;/code&gt; and never collected, it must be &lt;code&gt;SharingStarted.Eagerly&lt;/code&gt;.&lt;/strong&gt; To audit, grep every &lt;code&gt;stateIn(... WhileSubscribed ...)&lt;/code&gt; for &lt;code&gt;.collect&lt;/code&gt;. If there are zero collectors and any &lt;code&gt;.value&lt;/code&gt; reads, that's the bug.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. The splash screen that hung forever
&lt;/h2&gt;

&lt;p&gt;For my first five releases, Coinly could get stuck on its splash screen until you force-stopped it. I never saw it in testing.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight kotlin"&gt;&lt;code&gt;&lt;span class="c1"&gt;// ViewModel&lt;/span&gt;
&lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="n"&gt;_destination&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;MutableSharedFlow&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Destination&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;   &lt;span class="c1"&gt;// replay = 0&lt;/span&gt;
&lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="n"&gt;destination&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;_destination&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;asSharedFlow&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;// Activity&lt;/span&gt;
&lt;span class="n"&gt;lifecycleScope&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;launch&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;repeatOnLifecycle&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Lifecycle&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;State&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&gt;STARTED&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;viewModel&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;destination&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;collect&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nf"&gt;navigate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;it&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;repeatOnLifecycle(STARTED)&lt;/code&gt; cancels the collector whenever the activity is stopped. A &lt;code&gt;SharedFlow&lt;/code&gt; with &lt;code&gt;replay = 0&lt;/code&gt; drops anything it can't deliver right now. So if the ViewModel decided where to go while the app wasn't in the foreground, the event was gone, and the splash waited for a second event that never came.&lt;/p&gt;

&lt;p&gt;That sounds rare until you notice how often it happens: tapping a notification on a locked phone, opening the app during a call, switching away during the splash animation. Coinly's daily reminder opens the splash screen, so this was on a real path.&lt;/p&gt;

&lt;p&gt;You can reproduce it deterministically with adb:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;adb shell input keyevent 26        &lt;span class="c"&gt;# screen off&lt;/span&gt;
adb shell am start -n com.example/.SplashActivity
sleep 8                            &lt;span class="c"&gt;# the ViewModel emits with no collector&lt;/span&gt;
adb shell input keyevent 224       &lt;span class="c"&gt;# wake, then unlock and look&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The fix is one argument: &lt;code&gt;MutableSharedFlow&amp;lt;Destination&amp;gt;(replay = 1)&lt;/code&gt;. A late collector still gets the value, and since the splash finishes itself after navigating, there's nothing to re-navigate. Leave a comment next to it, because &lt;code&gt;replay = 1&lt;/code&gt; on a "one-shot event" looks wrong and someone will revert it.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. The in-app language picker that worked everywhere except Google Play
&lt;/h2&gt;

&lt;p&gt;Coinly ships in English, Spanish, Portuguese and Indonesian, with a language picker inside the app. On my test phone it worked perfectly. For people who installed from Play and picked a language other than their phone's, it showed English text with, say, Spanish number formatting.&lt;/p&gt;

&lt;p&gt;The reason: with an Android App Bundle, &lt;strong&gt;Play only installs the language resources that match the phone's system languages&lt;/strong&gt;. My test installs were APKs, which carry every language, so the bug couldn't happen on my device.&lt;/p&gt;

&lt;p&gt;The fix is in &lt;code&gt;build.gradle.kts&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight kotlin"&gt;&lt;code&gt;&lt;span class="n"&gt;android&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;bundle&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;language&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="c1"&gt;// The app has its own language picker, so every language must be installed.&lt;/span&gt;
            &lt;span class="n"&gt;enableSplit&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The alternative is downloading languages on demand with Play Core. I didn't find this bug by testing. Lint found it (&lt;code&gt;AppBundleLocaleChanges&lt;/code&gt;). If you have an in-app language picker, check your bundle config today.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. A crash on a device nobody owns
&lt;/h2&gt;

&lt;p&gt;Crashlytics reported an &lt;code&gt;InflateException&lt;/code&gt; on the onboarding screen, caused by &lt;code&gt;NoSuchMethodError&lt;/code&gt; in Material's &lt;code&gt;FocusRingDrawable&lt;/code&gt;. The device was &lt;code&gt;sdk_gphone_arm64&lt;/code&gt; on Android 11.&lt;/p&gt;

&lt;p&gt;That's not a user. It's Google Play's pre-launch test robot, which crawls every new release. It loads its own un-shrunk copy of Material inside your app's process, and R8 had renamed a method that the robot's copy expected by its original name. Real users weren't affected, but a crash in pre-launch reports is noise you don't want, and it can hide a real one.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;-keep class com.google.android.material.focus.** { *; }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I got the same crash in my second app a few days later, from a slider this time, and widened the rule for that app.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I changed in how I work
&lt;/h2&gt;

&lt;p&gt;None of these were exotic. They were all "the build I test isn't the build people install":&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Test a minified release build&lt;/strong&gt;, not just debug, and exercise the network and storage paths, not just the screens.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Install from Play&lt;/strong&gt; (internal testing track) at least once per release. APKs hide bundle problems.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Test with the app not in the foreground&lt;/strong&gt;: locked screen, notification taps, switching away mid-launch.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Read Crashlytics device names&lt;/strong&gt; before panicking. &lt;code&gt;sdk_gphone&lt;/code&gt; is a robot.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Coinly is free on &lt;a href="https://play.google.com/store/apps/details?id=org.truetechsol.coinly" rel="noopener noreferrer"&gt;Google Play&lt;/a&gt; if you want to see the app these came out of. I'd like to hear the bug your tests missed.&lt;/p&gt;

</description>
      <category>android</category>
      <category>kotlin</category>
      <category>debugging</category>
      <category>showdev</category>
    </item>
  </channel>
</rss>
