@@ -10,6 +10,7 @@ import android.os.Bundle
1010import androidx.annotation.IdRes
1111import androidx.core.content.ContextCompat
1212import androidx.core.content.FileProvider
13+ import androidx.core.content.IntentCompat
1314import androidx.fragment.app.Fragment
1415import androidx.lifecycle.lifecycleScope
1516import kotlinx.coroutines.Dispatchers
@@ -226,15 +227,17 @@ abstract class ScreenLockActionBarActivity : BaseActionBarActivity() {
226227
227228 // Clear original clipData
228229 rewrittenIntent.clipData = null
229-
230- // If we couldn't find one then we have nothing to re-write and we'll just return the original intent
231- if (! rewrittenIntent.hasExtra(Intent .EXTRA_STREAM )) {
232- Log .i(TAG , " No stream to rewrite - returning original intent" )
233- return @withContext originalIntent
234- }
230+ rewrittenIntent.removeExtra(Intent .EXTRA_STREAM )
235231
236232 // Grab and rewrite the original intent's clipData - adding it to our rewrittenIntent as we go
237233 val originalClipData = originalIntent.clipData
234+ ? : IntentCompat .getParcelableExtra(originalIntent, Intent .EXTRA_STREAM , Uri ::class .java)?.let { uri ->
235+ // If the original intent has a single Uri in the Intent.EXTRA_STREAM extra, we create a ClipData
236+ // with that Uri to mimic the original clipData structure.
237+ ClipData .newUri(contentResolver, " Shared data" , uri)
238+ }
239+
240+
238241 originalClipData?.let { clipData ->
239242 var newClipData: ClipData ? = null
240243 for (i in 0 until clipData.itemCount) {
@@ -267,10 +270,6 @@ abstract class ScreenLockActionBarActivity : BaseActionBarActivity() {
267270 Log .i(TAG , " Adding newClipData to rewrittenIntent." )
268271 rewrittenIntent.clipData = newClipData
269272 rewrittenIntent.addFlags(Intent .FLAG_GRANT_READ_URI_PERMISSION )
270- } else {
271- // If no newClipData was created, clear it to prevent referencing the old inaccessible URIs
272- Log .i(TAG , " There was no newClipData - setting the clipData to null." )
273- rewrittenIntent.clipData = null
274273 }
275274 }
276275
0 commit comments