<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Phyoe Maung on Medium]]></title>
        <description><![CDATA[Stories by Phyoe Maung on Medium]]></description>
        <link>https://medium.com/@phyoemaungmaunghtun?source=rss-a282f66c7314------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*akAllIjSO2uwbJaYnb4yQg.jpeg</url>
            <title>Stories by Phyoe Maung on Medium</title>
            <link>https://medium.com/@phyoemaungmaunghtun?source=rss-a282f66c7314------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 21 Nov 2026 10:12:04 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@phyoemaungmaunghtun/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Dexing Error in API 22: com.android.tools.r8.internal.Fq:]]></title>
            <link>https://medium.com/@phyoemaungmaunghtun/dexing-error-in-api-22-com-android-tools-r8-internal-fq-9a0010bf3560?source=rss-a282f66c7314------2</link>
            <guid isPermaLink="false">https://medium.com/p/9a0010bf3560</guid>
            <category><![CDATA[androiddev]]></category>
            <category><![CDATA[android-app-development]]></category>
            <dc:creator><![CDATA[Phyoe Maung]]></dc:creator>
            <pubDate>Fri, 14 Mar 2025 06:43:33 GMT</pubDate>
            <atom:updated>2025-03-14T06:43:33.757Z</atom:updated>
            <content:encoded><![CDATA[<h3>Dexing Error in API 22: com.android.tools.r8.internal.Fq: No VersionRequirement with the Given ID in the Table</h3><p>When I encountered this Gradle error while syncing my Android project, I initially thought it could be resolved by simply syncing the Gradle files, cleaning the project, and rebuilding it — but it wasn’t that straightforward.</p><p>So, the first step was to investigate <strong>how and why this error occurred</strong>. The error specifically happened when running the app on <strong>Android 5.1.1 (API 22)</strong>. However, the same app worked fine on Android 13 and other newer versions. After debugging, I found that the issue was related to <strong>one specific third-party library</strong> used in the project.</p><h3>The Error Message</h3><pre>* What went wrong:<br>Execution failed for task &#39;:app:mergeExtDexPartnerUATDebug&#39;.<br>&gt; Could not resolve all files for configuration &#39;:app:partnerUATDebugRuntimeClasspath&#39;.<br>   &gt; Failed to transform ********-2.7.0.aar (io.********:********:2.7.0) to match attributes {artifactType=android-dex, asm-transformed-variant=partnerUATDebug, dexing-enable-desugaring=true, dexing-enable-jacoco-instrumentation=false, dexing-is-debuggable=true, dexing-min-sdk=21, org.gradle.status=release, org.gradle.usage=java-runtime}.<br>      &gt; Execution failed for DexingWithClasspathTransform: /Users/***********/.gradle/caches/transforms-3/8cb590033ad9ec98838fbbbade697e36/transformed/jetified-********-2.7.0-runtime.jar.<br>         &gt; Error while dexing.</pre><h3>Finding the Cause</h3><p>The error explicitly states that the failure occurred <strong>during the dexing process</strong>, specifically when trying to transform the library into a <strong>DEX</strong> file for <strong>Android 5.1.1</strong>. This led me to investigate the compatibility between:</p><ol><li>The <strong>library’s bytecode format</strong> and the <strong>Android version</strong>.</li><li>The <strong>Java version used in the app</strong> versus the <strong>Java version used by the library</strong>.</li></ol><h3>What is Dexing in Android?</h3><p><strong>Dexing (Dalvik Executable Conversion)</strong> is the process of converting <strong>Java .class bytecode</strong> into <strong>.dex (Dalvik Executable) format </strong>,which is required for execution in Android’s runtime environments — <strong>Dalvik (DVM) or ART (Android Runtime)</strong>.</p><h3>How Dexing Works</h3><ul><li><strong>Android Gradle Plugin (AGP)</strong> uses <strong>D8 (or the legacy DX tool)</strong> to convert <strong>JAR/AAR files</strong> into <strong>DEX files</strong>.</li><li><strong>Android does not run standard JVM bytecode</strong>; it requires a special <strong>DEX format</strong> optimized for execution in ART or DVM.</li></ul><h3>Why Did Dexing Fail on Android 5.1.1?</h3><p>After investigating, I found <strong>two key reasons</strong> why the <strong>dexing process failed</strong> for <strong>API 22</strong>:</p><h3>1. DEX Bytecode Compatibility Issues</h3><ul><li>Android 5.0 (API 21) introduced <strong>ART (Android Runtime)</strong>, replacing <strong>Dalvik (DVM)</strong>.</li><li>However, the <strong>ART version in Android 5.1.1 (API 22) remained largely unchanged from API 21</strong>.</li><li>This means API 22 <strong>only properly supports</strong> the <strong>traditional DEX bytecode</strong> optimized for API 21 or lower.</li><li><strong>Newer versions of R8/D8 (optimized for API 26+)</strong> generate <strong>Compact DEX (CDex)</strong> bytecode and apply <strong>other optimizations</strong>, which <strong>older ART versions (like Android 5.1.1) do not support</strong>.</li></ul><h3>2. Java Version Mismatch</h3><ul><li>In the project, <strong>Java 17</strong> was used for development, while the <strong>third-party library was compiled with Java 8</strong>.</li><li><strong>Android 5.1.1 does not fully support Java 8</strong> features unless desugaring is enabled.</li><li>Without <strong>desugaring</strong>, Java 8+ features <strong>cannot be properly converted into compatible DEX bytecode</strong> for Android 5.1.1, leading to transformation errors.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*exaqXgCtzciLAVxvDlzwUw.png" /></figure><h3>The Solution</h3><p>Based on these findings, the solution involved ensuring that <strong>DEX transformation was properly handled</strong> without upgrading AGP (which could introduce new Gradle issues). Instead of upgrading AGP, I <strong>explicitly upgraded the R8 version</strong> used in the project.</p><h3>How Upgrading R8 Fixed the Issue</h3><p>By overriding the <strong>default R8 version (4.0.48)</strong> used by <strong>AGP 7.4.2</strong> and upgrading it to <strong>R8 8.3.37</strong>, the problem was resolved.</p><h4>Updated build.gradle Configuration</h4><pre>repositories {<br>    google()<br>    jcenter()<br>    maven {<br>        url = uri(&quot;https://storage.googleapis.com/r8-releases/raw&quot;)<br>    }<br>}<br>dependencies {<br>    classpath(&quot;com.android.tools:r8:8.3.37&quot;)  // Upgraded R8 version<br>    classpath &#39;com.android.tools.build:gradle:7.4.2&#39;  // AGP with default R8 (4.0.48)<br>}</pre><h3>Why This Worked</h3><ul><li><strong>D8 (which handles actual dexing) is a subcomponent of R8.</strong> By upgrading R8, I indirectly upgraded D8.</li><li>The <strong>newer R8 version (8.3.37)</strong> correctly handled the <strong>Java 8+ transformations</strong> and ensured that <strong>DEX bytecode was compatible with Android 5.1.1</strong>.</li><li>The <strong>dexing process was successfully completed</strong> without triggering incompatibility errors.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0PTJdNPwN-7biTVcxc_CLw.png" /></figure><h3>Conclusion</h3><ul><li>The error <strong>occurred due to incompatibilities in DEX bytecode transformation</strong> when running the app on <strong>Android 5.1.1 (API 22)</strong>.</li><li>The <strong>root cause</strong> was a mix of <strong>DEX format mismatches</strong> and <strong>Java version incompatibilities</strong>.</li><li>Upgrading <strong>R8 from 4.0.48 to 8.3.37</strong> resolved the issue by ensuring <strong>proper DEX transformation for lower API levels</strong>.</li><li>The <strong>actual dexing process is handled by D8</strong>, and since <strong>D8 is a subcomponent of R8</strong>, upgrading R8 fixed all related dexing issues.</li></ul><p>This experience highlights the <strong>importance of understanding DEX bytecode compatibility</strong> when targeting <strong>older Android versions</strong>, especially when dealing with <strong>newer libraries and Java versions</strong>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9a0010bf3560" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Tackling Garbage Collector in Android App]]></title>
            <link>https://medium.com/@phyoemaungmaunghtun/tackling-with-garbage-collector-in-android-app-5da3145e684a?source=rss-a282f66c7314------2</link>
            <guid isPermaLink="false">https://medium.com/p/5da3145e684a</guid>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[garbage-collector]]></category>
            <dc:creator><![CDATA[Phyoe Maung]]></dc:creator>
            <pubDate>Mon, 24 Jun 2024 16:54:49 GMT</pubDate>
            <atom:updated>2024-06-24T17:00:01.842Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2uW_qxRSZCzgv96VY-z7Uw.jpeg" /></figure><h3>The Garbage Collector</h3><p>The garbage collector helps programmers by automatically reclaiming unreferenced heap memory from the program. In the early days, programmers had to manually handle memory allocation and deallocation while writing code in languages like C and C++. Later, languages like Java introduced garbage collection to automate this process. In Android, the type of virtual machine (Dalvik or ART) determines the garbage collection (GC) method used. In my case, improper coding practices caused the app to behave inappropriately due to GC-related issues. This experience provided valuable insights into GC behavior, which I want to share.</p><h3>The Root Cause of the Issue</h3><p>Modern Android devices generally have more memory than early versions, reducing the frequency of out-of-memory errors. However, my situation was different. I was working with Android set-top boxes from less-known brands like Pendoo, X95, and T96, which often have misleading specifications. For example, a device might claim to have 4GB of RAM but only have 1.8GB available. This limited memory, combined with bad coding practices, led to significant memory pressure and GC issues.</p><h3>The Problem</h3><p>The task involved handling a sequence of tickets from AppSync, processing them as a queue, and making voice announcements using MediaPlayer and Text-to-Speech (TTS) for each ticket. The issue arose when repeatedly recalling tickets: sometimes the process worked fine, but other times it stopped, causing tasks to fail, tickets to be skipped, and the screen to freeze. This inconsistency was difficult to predict and debug.</p><h3>The Debugging</h3><p>To diagnose the issue, I first examined the code. I had used brute-force coding to meet tight deadlines, which included recursive methods for processing tickets. These methods created many heap stacks and local MediaPlayer objects, leading to memory pressure and performance degradation. The frequent creation and destruction of MediaPlayer objects increased GC overhead, causing the app to slow down and become unresponsive.</p><h3>The Solution</h3><p>The root cause was the memory pressure from using recursive methods and creating objects within these methods. The solution was to refactor the code from recursive to iterative.</p><p><strong>Original Recursive Method:</strong></p><pre>kotlinCopy code<br>fun speak(data: OnCreateTicketSubscription.Data) {<br>    var mediaPlayer = MediaPlayer()<br>    var descriptor = getApplication&lt;Application&gt;().assets.openFd(&quot;doorbell.mp3&quot;)<br>    mediaPlayer.apply {<br>        setDataSource(descriptor.fileDescriptor, descriptor.startOffset, descriptor.length)<br>        prepare()<br>        start()<br>    }<br>    mediaPlayer.setOnCompletionListener {<br>        val text = &quot;Ticket number,&quot; + data.onCreateTicket()?.ticketNo()?.toList()?.joinToString(&quot;,&quot;) + &quot;, go to counter,&quot; + data.onCreateTicket()?.deskName()?.split(&quot; &quot;)?.last()<br>        val utteranceId = hashCode().toString()<br>        textToSpeech?.speak(text, TextToSpeech.QUEUE_ADD, null, utteranceId)<br>    }<br>    textToSpeech?.setOnUtteranceProgressListener(object : UtteranceProgressListener() {<br>        override fun onStart(utteranceId: String?) {<br>            mediaPlayer.release()<br>        }<br>        override fun onDone(utteranceId: String?) {<br>            subscriptionQueue.removeAt(0)<br>            if (subscriptionQueue.isNotEmpty()) {<br>                speak(subscriptionQueue[0])<br>            }<br>        }<br>        override fun onError(utteranceId: String?) {<br>            // Called on an error.<br>        }<br>    })<br>}</pre><p><strong>Issues:</strong></p><ul><li><strong>Object Creation</strong>: Each call to speak creates a new MediaPlayer instance.</li><li><strong>Memory Pressure</strong>: Frequent creation of MediaPlayer instances increases memory pressure.</li><li><strong>GC Impact</strong>: The GC needs to collect these MediaPlayer instances once they go out of scope, leading to performance overhead.</li></ul><p><strong>Refactored Iterative Method:</strong></p><pre><br>private fun processNextItem() {<br>    if (subscriptionQueue.isNotEmpty()) {<br>        if (!isProcessingItem) {<br>            muteSound.value = true  // Mute sound when starting to process the first item<br>            isProcessingItem = true<br>            val data = subscriptionQueue.removeAt(0)<br>            preSound(data)<br>        }<br>    } else {<br>        muteSound.value = false  // Unmute sound after all items have been processed<br>    }<br>}<br><br>private fun preSound(data: OnCreateTicketSubscription.Data){<br>    val mediaPlayer = MediaPlayer()<br>    try {<br>        val descriptor = getApplication&lt;Application&gt;().assets.openFd(&quot;doorbell.mp3&quot;)<br>        mediaPlayer.apply {<br>            setDataSource(descriptor.fileDescriptor, descriptor.startOffset, descriptor.length)<br>            prepare()<br>            start()<br>        }<br>        mediaPlayer.setOnCompletionListener {<br>            mediaPlayer.release()<br>            speak(data)<br>        }<br>    } catch (e: Exception) {<br>        isProcessingItem = false<br>        processNextItem()  // Continue with the next item if there&#39;s an error<br>    }<br>}<br>private fun speak(data: OnCreateTicketSubscription.Data) {<br>    val text = &quot;Ticket number, ${data.onCreateTicket()?.ticketNo()?.toList()?.joinToString(&quot;,&quot;)}, go to counter, ${data.onCreateTicket()?.deskName()?.split(&quot; &quot;)?.last()}&quot;<br>    val utteranceId = hashCode().toString()<br>    textToSpeech?.speak(text, TextToSpeech.QUEUE_ADD, null, utteranceId)<br>}</pre><p><strong>Improvements:</strong></p><ul><li><strong>Object Creation</strong>: The MediaPlayer instance is created only when preSound is called, and the recursive calls are eliminated.</li><li><strong>Memory Pressure</strong>: The number of MediaPlayer instances is controlled, and they are released immediately after use.</li><li><strong>GC Efficiency</strong>: The GC can more efficiently collect MediaPlayer instances, reducing memory pressure and potential performance overhead.</li></ul><h3>The Remaining Issue</h3><p>Despite the improvements, the issue persisted: calling a series of tickets and hitting the memory threshold caused the GC to collect the newly created MediaPlayer objects before they could be released properly. This interrupted the process, preventing subsequent tasks from executing.</p><pre>kotlinCopy code<br>mediaPlayer.setOnCompletionListener {<br>    mediaPlayer.release()<br>    speak(data)<br>}</pre><p><strong>Problem</strong>: The GC collected the MediaPlayer object before this method could complete, causing subsequent logic to fail and new tickets to conflict with the remaining tasks in the subscriptionQueue.</p><h3>The Final Solution</h3><p>To prevent premature GC collection, I implemented a strategy to keep a strong reference to the MediaPlayer instance.</p><p><strong>Strong Reference Strategy:</strong></p><pre>kotlinCopy code<br><br>private var mediaPlayer: MediaPlayer? = null<br><br>    init {<br>        mediaPlayer = MediaPlayer()<br>        val descriptor = getApplication&lt;Application&gt;().assets.openFd(&quot;doorbell.mp3&quot;)<br>        mediaPlayer?.setDataSource(<br>            descriptor.fileDescriptor,<br>            descriptor.startOffset,<br>            descriptor.length<br>        )<br>        mediaPlayer?.prepare()<br>        }<br>        <br>        //All the rest code<br>        <br>        override fun onCleared() {<br>        textToSpeech?.stop()<br>        textToSpeech?.shutdown()<br>        releaseMediaPlayer(mediaPlayer!!)<br>        super.onCleared()<br>    }</pre><p>By using a global variable for the MediaPlayer instance, the GC no longer prematurely collects the object. This ensures that even with frequent calls, the MediaPlayer instance remains available until the ViewModel is destroyed.</p><p>This experience taught me the importance of understanding garbage collection behavior and implementing best practices to manage memory effectively.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5da3145e684a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Along with the Android Compilation]]></title>
            <link>https://medium.com/@phyoemaungmaunghtun/along-with-the-android-compilation-bbeafb183b13?source=rss-a282f66c7314------2</link>
            <guid isPermaLink="false">https://medium.com/p/bbeafb183b13</guid>
            <category><![CDATA[compilers]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[technical-analysis]]></category>
            <dc:creator><![CDATA[Phyoe Maung]]></dc:creator>
            <pubDate>Mon, 10 Jun 2024 16:38:27 GMT</pubDate>
            <atom:updated>2024-06-10T16:38:27.149Z</atom:updated>
            <content:encoded><![CDATA[<p>In Android, there are two types of compilation needed to build and run an APK. The first stage involves compiling the source code into Java bytecode, which is done using the javac or kotlinc compiler. The second stage involves translating this bytecode into machine code using a native compiler, which is part of the Dalvik Virtual Machine (<strong>DVM</strong>) or Android Runtime (<strong>ART</strong>). The specific type of compiler used—Just-In-Time (<strong>JIT</strong>) or Ahead-Of-Time (<strong>AOT</strong>)—depends on the Android version. Below is a detailed explanation of the <strong>first stage</strong> of the compilation process:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9jEE1laXYCPUyH4iQS72Nw.png" /></figure><h3>Second Stage: Native Compilation</h3><p>In this stage, the Dalvik Virtual Machine (DVM) — a variant of the Java Virtual Machine (JVM) designed for Android — plays the central role. The DVM was responsible for translating bytecode into machine code before Android Lollipop (5.0). Starting with Android Lollipop, the Android Runtime (ART) took over this responsibility as the successor to DVM.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OYNIEOnKpS3ezR7GPFp5hA.png" /></figure><p>Now it is time to focus on the compilers used in Android. As mentioned before, different virtual machines in Android have utilized various compilers. The two main compilers used in Android are <strong>JIT</strong> and <strong>AOT</strong>.</p><p><strong>JIT (Just-In-Time Compilation)</strong></p><ul><li><strong>Usage Period</strong>: From Android version Froyo (2.2) to KitKat (4.4) in DVM.</li><li><strong>Function</strong>: JIT compiles code during program execution. It compiles DEX files, which include Java bytecode, into machine code at runtime.</li></ul><p><strong>AOT (Ahead-Of-Time Compilation)</strong></p><ul><li><strong>Usage Period</strong>: From Android version Lollipop (5.0) onwards with ART.</li><li><strong>Function</strong>: AOT compiles bytecode into machine code during the installation process, rather than at runtime.</li></ul><h3>Compilation Strategies</h3><p>As mentioned, Android uses two main compilation tools, each with its own advantages and drawbacks.</p><p><strong>JIT Compiler</strong>:</p><ul><li><strong>Pros</strong>: JIT allows for code to be compiled just in time, which can be useful for quick iterations and changes.</li><li><strong>Cons</strong>: Using JIT can result in laggy performance and is not suitable for large applications due to the overhead of compiling during execution.</li></ul><p><strong>AOT Compiler</strong>:</p><ul><li><strong>Pros</strong>: AOT significantly improves application execution speed, making it up to 20 times faster than JIT. It compiles code ahead of time during installation, reducing runtime overhead.</li><li><strong>Cons</strong>: AOT increases installation time and requires more RAM space, which can be a limitation for some devices.</li></ul><p>To balance these pros and cons, Google introduced a hybrid compilation strategy in Android Nougat (7.0). This strategy combines both JIT and AOT compilers based on user behavior. ART uses Profile-Guided Optimization to record the most frequently executed code paths during runtime. These profiles are used to further optimize the application during idle time or the next installation/upgrade process, improving both performance and efficiency.</p><p>Starting with Android Pie (9.0), Google enhanced this approach by integrating cloud-based profile information. This allows ART to use anonymized usage patterns collected from various devices to further optimize app performance, even before the app is run for the first time on a new device. This cloud-based profile sharing helps in achieving better out-of-the-box performance for apps.</p><h3>Conclusion</h3><p>The journey of Android app compilation has evolved significantly over time. From the early days of JIT compilation with the Dalvik VM to the introduction of AOT compilation with ART, and finally to the hybrid approach combining both JIT and AOT in Android Nougat and cloud-based profiles in Android Pie, each step has aimed to enhance the performance and efficiency of Android applications. This evolution reflects Google’s continuous efforts to optimize the Android ecosystem for both developers and users.</p><h4>Reference links</h4><p><a href="https://source.android.com/docs/core/runtime">Android runtime and Dalvik | Android Open Source Project</a></p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FQp-5stxpTz4%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DQp-5stxpTz4&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FQp-5stxpTz4%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/b3750db5a949db0e57244b8c963f9f46/href">https://medium.com/media/b3750db5a949db0e57244b8c963f9f46/href</a></iframe><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2F0J1bm585UCc%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3D0J1bm585UCc&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2F0J1bm585UCc%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/7627f8212c54d922ab0892af27089250/href">https://medium.com/media/7627f8212c54d922ab0892af27089250/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bbeafb183b13" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Package Visibility in API 30 or Higher with the TTS service]]></title>
            <link>https://medium.com/@phyoemaungmaunghtun/package-visibility-in-api-30-or-higher-with-the-tts-service-9ef0d861fdb1?source=rss-a282f66c7314------2</link>
            <guid isPermaLink="false">https://medium.com/p/9ef0d861fdb1</guid>
            <category><![CDATA[android-framework]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[androidfeatures]]></category>
            <category><![CDATA[android-app-development]]></category>
            <dc:creator><![CDATA[Phyoe Maung]]></dc:creator>
            <pubDate>Thu, 25 Jan 2024 05:12:01 GMT</pubDate>
            <atom:updated>2024-01-25T05:12:01.454Z</atom:updated>
            <content:encoded><![CDATA[<p>In order to get full list of apps those are installed on system, on the android 10 and earlier you just simply call methods like queryIntentActivities(). But later version 11 and higher the app will see default filtered list of installed apps. If you want to access a broader list of installed apps, an app need to declare package visibility with the query tag in manifest file.</p><p>Along with the time, google have issued many policies according to user security and privacy concern for android depend on version. Package visibility is one of those policies that helps app stores like Google Play assess the privacy and security that your app provides for users.</p><p>In my experience with the package visibility, one of my TV application was used text to speech service of TTS engine app on the android set top box and its version is android 9. All the things was fine until we have changed new set top box with android 11. On the new device the application couldn’t produce voice based on the text. As a android developer, we all know which thing we need to check as a first step if the application is smoothly fine with the original device. Yes, the version of android. At the first step, I have found the different of android version the old one is android 9 and newer one is 11. Based on that information, I need to find out what can I do with the TTS service in android 11. After take a while spending on googling, I have got final answer for that case that is like I mention before that I need to declare specific package visibility in query tag</p><pre>&lt;queries&gt;<br>        &lt;intent&gt;<br>            &lt;action android:name=&quot;android.intent.action.TTS_SERVICE&quot; /&gt;<br>        &lt;/intent&gt;<br>    &lt;/queries&gt;</pre><p>It is the use case of mine and, everything is fine again after I put that action. I just call</p><pre>private val textToSpeech = TextToSpeech(application) { status -&gt;<br>            if (status != TextToSpeech.ERROR) {<br>                textToSpeech?.language = Locale.US<br>            }<br>        }<br>textToSpeech?.speak(text, TextToSpeech.QUEUE_ADD, null, utteranceId)</pre><p>This is one of the many scenario of common use case of android development and you can check <a href="https://developer.android.com/training/package-visibility/use-cases">this android developer document</a> for other scenario. In some rare use case where the &lt;queries&gt; element doesn&#39;t provide adequate package visibility, you can declare the QUERY_ALL_PACKAGES permission. But one situation is your app&#39;s use of this permission is <a href="https://support.google.com/googleplay/android-developer/answer/10158779">subject to approval</a> for using this kind of permission if you publish your app on Google Play.</p><p>Thank for reading :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9ef0d861fdb1" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>