Add Accept-Language to extra header when opening CustomChromeTab
Follow good practice from https://developer.android.com/guide/topics/resources/app-languages#consider-header
This commit is contained in:
parent
4bb860f9af
commit
35bbb3a139
1 changed files with 6 additions and 0 deletions
|
|
@ -10,10 +10,13 @@ package io.element.android.libraries.androidutils.browser
|
||||||
import android.app.Activity
|
import android.app.Activity
|
||||||
import android.content.ActivityNotFoundException
|
import android.content.ActivityNotFoundException
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
|
import android.os.Bundle
|
||||||
|
import android.provider.Browser
|
||||||
import androidx.browser.customtabs.CustomTabColorSchemeParams
|
import androidx.browser.customtabs.CustomTabColorSchemeParams
|
||||||
import androidx.browser.customtabs.CustomTabsIntent
|
import androidx.browser.customtabs.CustomTabsIntent
|
||||||
import androidx.browser.customtabs.CustomTabsSession
|
import androidx.browser.customtabs.CustomTabsSession
|
||||||
import io.element.android.libraries.androidutils.system.openUrlInExternalApp
|
import io.element.android.libraries.androidutils.system.openUrlInExternalApp
|
||||||
|
import java.util.Locale
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Open url in custom tab or, if not available, in the default browser.
|
* Open url in custom tab or, if not available, in the default browser.
|
||||||
|
|
@ -51,6 +54,9 @@ fun Activity.openUrlInChromeCustomTab(
|
||||||
intent.putExtra("org.chromium.chrome.browser.customtabs.EXTRA_DISABLE_DOWNLOAD_BUTTON", true)
|
intent.putExtra("org.chromium.chrome.browser.customtabs.EXTRA_DISABLE_DOWNLOAD_BUTTON", true)
|
||||||
// Disable bookmark button
|
// Disable bookmark button
|
||||||
intent.putExtra("org.chromium.chrome.browser.customtabs.EXTRA_DISABLE_START_BUTTON", true)
|
intent.putExtra("org.chromium.chrome.browser.customtabs.EXTRA_DISABLE_START_BUTTON", true)
|
||||||
|
intent.putExtra(Browser.EXTRA_HEADERS, Bundle().apply {
|
||||||
|
putString("Accept-Language", Locale.getDefault().toLanguageTag())
|
||||||
|
})
|
||||||
}
|
}
|
||||||
.launchUrl(this, Uri.parse(url))
|
.launchUrl(this, Uri.parse(url))
|
||||||
} catch (activityNotFoundException: ActivityNotFoundException) {
|
} catch (activityNotFoundException: ActivityNotFoundException) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue