Open Nextcloud files in Nextcloud app if installed
This commit is contained in:
parent
7ba13a8ba7
commit
7ad36684ae
@ -2,10 +2,8 @@ package de.mm20.launcher2.search.data
|
||||
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.pm.PackageManager
|
||||
import android.net.Uri
|
||||
import de.mm20.launcher2.files.R
|
||||
import de.mm20.launcher2.helper.NetworkUtils
|
||||
import de.mm20.launcher2.nextcloud.NextcloudApiHelper
|
||||
|
||||
class NextcloudFile(
|
||||
fileId: Long,
|
||||
@ -25,9 +23,26 @@ class NextcloudFile(
|
||||
get() = true
|
||||
|
||||
override fun getLaunchIntent(context: Context): Intent? {
|
||||
var nextcloudApp: String? = null
|
||||
return Intent(Intent.ACTION_VIEW).apply {
|
||||
data = Uri.parse("$server/f/$id")
|
||||
flags = Intent.FLAG_ACTIVITY_NEW_TASK
|
||||
`package` = getNextcloudAppPackage(context)
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
private fun getNextcloudAppPackage(context: Context): String? {
|
||||
val candidates = listOf("com.nextcloud.client", "com.nextcloud.android.beta")
|
||||
|
||||
for (c in candidates) {
|
||||
try {
|
||||
context.packageManager.getPackageInfo(c, 0)
|
||||
return c
|
||||
} catch (e: PackageManager.NameNotFoundException) {
|
||||
}
|
||||
}
|
||||
return null
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user