fixed copy to clipboard action on older devices
This commit is contained in:
parent
bb5ff51a64
commit
6a3e830d14
1 changed files with 17 additions and 7 deletions
|
@ -4,6 +4,8 @@ import android.content.*
|
|||
import android.content.pm.ApplicationInfo
|
||||
import android.content.res.Configuration
|
||||
import android.net.Uri
|
||||
import android.os.Handler
|
||||
import android.os.Looper
|
||||
import android.util.Log
|
||||
import androidx.core.content.FileProvider
|
||||
import com.bumptech.glide.Glide
|
||||
|
@ -141,6 +143,10 @@ class AppAdapterHandler(private val context: Context) : MethodCallHandler {
|
|||
return
|
||||
}
|
||||
|
||||
// on older devices, `ClipboardManager` initialization must happen on the main thread
|
||||
// (e.g. Samsung S7 with Android 8.0 / API 26, but not on Tab A 10.1 with Android 8.1 / API 27)
|
||||
Handler(Looper.getMainLooper()).post {
|
||||
try {
|
||||
val clipboard = context.getSystemService(Context.CLIPBOARD_SERVICE) as? ClipboardManager
|
||||
if (clipboard != null) {
|
||||
val clip = ClipData.newUri(context.contentResolver, label, getShareableUri(uri))
|
||||
|
@ -149,6 +155,10 @@ class AppAdapterHandler(private val context: Context) : MethodCallHandler {
|
|||
} else {
|
||||
result.success(false)
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
result.error("copyToClipboard-exception", "failed to set clip", e.message)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun edit(call: MethodCall, result: MethodChannel.Result) {
|
||||
|
|
Loading…
Reference in a new issue