use custom user agent for onlyOffice

Signed-off-by: tobiasKaminsky <[email protected]>
This commit is contained in:
tobiasKaminsky committed 2019-12-19 08:57:39 +01:00
1 parent 0178499596
commit ddffaf7b49
2 files changed
+27

No files matched your search

@@ -22,9 +22,13 @@
package com.owncloud.android.ui.activity
import android.annotation.SuppressLint
import android.content.pm.PackageManager.NameNotFoundException
import android.os.Build
import android.os.Bundle
import androidx.annotation.RequiresApi
import com.owncloud.android.R
import com.owncloud.android.files.FileMenuFilter
import com.owncloud.android.lib.common.utils.Log_OC
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
class TextEditorWebView : EditorWebView() {
@@ -34,8 +38,30 @@ class TextEditorWebView : EditorWebView() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val editor = FileMenuFilter.getEditor(contentResolver, account, file.mimeType)
if (editor != null && editor.id == "onlyoffice") {
webview.settings.userAgentString = generateOnlyOfficeUserAgent()
}
webview.addJavascriptInterface(MobileInterface(), "DirectEditingMobileInterface")
loadUrl(intent.getStringExtra(ExternalSiteWebView.EXTRA_URL), file)
}
private fun generateOnlyOfficeUserAgent(): String {
val appString = applicationContext.resources.getString(R.string.only_office_user_agent)
val packageName = applicationContext.packageName
val androidVersion = Build.VERSION.RELEASE
var appVersion = ""
try {
val pInfo = applicationContext.packageManager.getPackageInfo(packageName, 0)
if (pInfo != null) {
appVersion = pInfo.versionName
}
} catch (e: NameNotFoundException) {
Log_OC.e(this, "Trying to get packageName", e.cause)
}
return String.format(appString, androidVersion, appVersion)
}
}
+1
View File
@@ -18,6 +18,7 @@
<string name="data_folder">nextcloud</string>
<string name="default_display_name_for_root_folder">Nextcloud</string>
<string name="nextcloud_user_agent">Mozilla/5.0 (Android) Nextcloud-android/%1$s</string>
<string name="only_office_user_agent">Mozilla/5.0 (Android %1$s) Mobile Nextcloud-android/%2$s</string>
<!-- URLs and flags related -->
<string name="server_url"></string>