Last active
April 4, 2025 06:08
-
-
Save SeongUgJung/3405bed6adf923188e6055224adcc630 to your computer and use it in GitHub Desktop.
distractionOptimized for android auto
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// in app/build.gradle.kts | |
// to configure ProcessApplicationManifest task | |
tasks.withType<com.android.build.gradle.tasks.ProcessApplicationManifest>().configureEach { | |
doLast { | |
val manifestFile = mergedManifest.get().asFile | |
if (manifestFile.exists()) { | |
// Read the content | |
val document = DocumentBuilderFactory.newInstance() | |
.newDocumentBuilder() | |
.parse(manifestFile) | |
// Add <meta-data> to <activity> | |
val activityNodes = document.getElementsByTagName("activity") | |
//noinspection WrongGradleMethod | |
activityNodes.forEach { activityNode -> | |
val metaDataElement = document.createElement("meta-data") | |
metaDataElement.setAttribute("android:name", "distractionOptimized") | |
metaDataElement.setAttribute("android:value", "true") | |
activityNode.appendChild(metaDataElement) | |
} | |
// Save the updated content back to the file | |
val transformer = TransformerFactory.newInstance().newTransformer() | |
val source = DOMSource(document) | |
val result = StreamResult(manifestFile) | |
transformer.transform(source, result) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment