Skip to main content
Level 1.5: Cupcake
Jul 10, 2023 7:56 AM UTC
Question

Persistent preferred activity

  • 5 replies
  • 44 views
  • Translate All • Beta, powered by Gemini

I have implemented a function in my Android app to set Brave browser as the default browser using the provided code snippet. However, when I click on a link, it still opens in Chrome instead of Brave. Could you please review the code snippet below and let me know if there's anything I am doing wrong?

 

private fun setBraveAsDefaultBrowser() {
val filter = IntentFilter(Intent.ACTION_VIEW)
filter.addCategory(Intent.CATEGORY_BROWSABLE)
filter.addDataScheme("http")
filter.addDataScheme("https")

val defaultBrowser: ComponentName = packageManager.getLaunchIntentForPackage("com.brave.browser")?.component ?: return

dpm.addPersistentPreferredActivity(
AdminReceiver.componentName,
filter,
defaultBrowser
)
}

I have used addPersistentPreferredActivity()

5 replies

Moombas
Level 4.4: KitKat
Jul 10, 2023 9:14 AM UTC

Are you talking about a "normal" app or an admin (like MDM) app where it's set as device admin app on the device itself?

Translate • Beta, powered by Gemini
Android Enterprise Expert
SohailAuthor
Level 1.5: Cupcake
Jul 10, 2023 1:03 PM UTC

I am talking about an MDM app and Yes, the app is set as device admin app on the device itself. It uses DevicePolicyManager to enforce the restrictions. @Moombas 

Translate • Beta, powered by Gemini
SohailAuthor
Level 1.5: Cupcake
Jul 10, 2023 1:07 PM UTC

Yes, the app is set as device admin app on the device itself. It uses DevicePolicyManager to enforce the restrictions.

Translate • Beta, powered by Gemini
Moombas
Level 4.4: KitKat
Jul 18, 2023 7:44 AM UTC

Sorry, i took a look into that last week but haven't found anything related which could help you.

Sorry. Maybe someone else a bit more confident with this topic may be able to help you.

Translate • Beta, powered by Gemini
Android Enterprise Expert