Question
Can I can set a default app on a build if two apps of the same category are installed?
Example
I am adding a custom browser on AOSP. I want to set it as the default browser before the build starts.
On the Android.mk
file for packages there is an option to specify 'LOCAL_OVERRIDES_PACKAGES'
which basically overrides the install of the packages mentioned making my app as the default.
But I would want the other app to be a part of the ROM with my app as the default.
Any ideas will be appreciated.
Find and tap Settings → Apps & notifications → Default apps. Tap the type of app you want to set, then tap the app you want to use as default.
Open the Settings apps. Tap Apps & Notifications. Tap Advanced. Tap Default Apps.
So I found a solution for setting an application as default at build time. I am documenting it in the hope that it helps someone else down the line.
The Android system keeps a list of the default applications/activities in a block in a file located at /data/system/users/{*user-id*}/package-restrictions.xml
called as <preferred-activities></preferred-activities>
This file is generated by the Settings.java and the PackageManager.java upon build time. Whenever the defaults on the android system change, the flags on this xml block change accordingly.
/system/etc/preferred-activities/*.xml
Example
Adding a custom browser to AOSP
If only the default browser is being installed on the device other that 'mybrowser' the following xml file should be created. In this case, I am naming it as preferred-activies-home.xml
<?xml version="1.0" encoding="UTF-8"?>
<preferred-activities>
<item name="com.mybrowser.MainActivity" match="200000" always="true" set="2">
<set name="com.mybrowser./.MainActivity" />
<set name="com.android.browser/.BrowserActivity" />
<filter>
<action name="android.intent.action.VIEW" />
<cat name="android.intent.category.DEFAULT" />
<scheme name="http" />
</filter>
</item>
</preferred-activities>
Copy the above xml to the /system/etc/preferred-apps/
location by adding the following line in <!--AOSP_SOURCE-->/build/target/product/full_base.mk
PRODUCT_COPY_FILES +=/<location-of-file>/preferred-activities-home.xml:system/etc/preferred-apps/preferred-activities-home.xml
After build, the browser activity will be set as default
Limitations and Caveats
There are some limitations to the above mentioned process. They are as follows:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With