@@ -4,11 +4,11 @@ import android.content.ClipDescription
44import android.content.Context
55import android.content.Intent
66import android.graphics.Bitmap
7+ import android.util.Log
78import android.view.inputmethod.EditorInfo
89import android.view.inputmethod.InputConnection
910import androidx.core.content.FileProvider
1011import androidx.core.graphics.drawable.toBitmap
11- import androidx.core.view.inputmethod.EditorInfoCompat
1212import androidx.core.view.inputmethod.InputConnectionCompat
1313import androidx.core.view.inputmethod.InputContentInfoCompat
1414import coil.ImageLoader
@@ -96,40 +96,22 @@ class StickerSender(
9696 }
9797
9898 fun sendSticker (file : File ) {
99- var stickerType = Utils .getMimeType(file) ? : " __unknown__"
100-
101-
102-
103-
104-
105- // Here we 'mock' the mime for misbehaving applications such as whatsapp
106- // if (this.packageName == "com.whatsapp"){
107- // stickerType = when (stickerType) {
108- // null -> null
109- // "image/webp" -> "image/webp.wasticker"
110- // "video/mp4" -> "video/x.looping_mp4"
111- // else -> stickerType
112- // }
113- // }
99+ val stickerType = Utils .getMimeType(file) ? : " __unknown__"
114100
101+ // Try and only send as is if the app explicitly supports it
102+ // Note: Many apps do not support svg, so send as png regardless!
115103 if ((stickerType in supportedMimes
116104 || " image/*" in supportedMimes && stickerType.startsWith(" image/" )
117105 || " video/*" in supportedMimes && stickerType.startsWith(" video/" ))
106+ && stickerType != " image/svg+xml"
118107 ) {
119- // Deal with any exceptions here such as telegram messenger
120- if (this .packageName == " org.telegram.messenger" && stickerType == " image/svg+xml"
121- || this .packageName == " com.discord" && stickerType == " image/svg+xml"
122- || this .packageName == " im.vector.app" && stickerType == " image/svg+xml"
123- || this .packageName == " com.google.android.keep" && stickerType == " image/svg+xml" ) {
108+
109+ if (! doCommitContent(stickerType, file)) {
124110 CoroutineScope (Dispatchers .Main ).launch {
125111 doFallbackCommitContent(file)
126112 }
127- } else {
128- // Commit content normally
129- doCommitContent(stickerType, file)
130113 }
131114 } else {
132- // Use fallback for unsupported types
133115 CoroutineScope (Dispatchers .Main ).launch {
134116 doFallbackCommitContent(file)
135117 }
@@ -162,14 +144,14 @@ class StickerSender(
162144 if (" image/png" in supportedMimes || " image/*" in supportedMimes) {
163145 val compatSticker = createCompatSticker(file)
164146 if (compatSticker != null ) {
165- doCommitContent(" image/png" , compatSticker)
147+ if (! doCommitContent(" image/png" , compatSticker)) {
148+ openShareSheet(file)
149+ }
166150 return
167151 }
168152 }
169153 openShareSheet(file)
170154
171-
172-
173155 }
174156
175157 /* *
@@ -178,7 +160,8 @@ class StickerSender(
178160 * @param mimeType String
179161 * @param file File
180162 */
181- private fun doCommitContent (mimeType : String , file : File ) {
163+ private fun doCommitContent (mimeType : String , file : File ): Boolean {
164+ // Log.d("QWERTY", "Sending ${file.name} ($mimeType) to ${this.packageName}")
182165 val inputContentInfoCompat = InputContentInfoCompat (
183166 FileProvider .getUriForFile(
184167 context,
@@ -191,14 +174,15 @@ class StickerSender(
191174
192175 if (currentInputConnection != null && currentInputEditorInfo != null ) {
193176
194- InputConnectionCompat .commitContent(
177+ return InputConnectionCompat .commitContent(
195178 currentInputConnection,
196179 currentInputEditorInfo,
197180 inputContentInfoCompat,
198181 InputConnectionCompat .INPUT_CONTENT_GRANT_READ_URI_PERMISSION ,
199182 null ,
200183 )
201184 }
185+ return false
202186 }
203187
204188}
0 commit comments