From 6d3ce28b480767c6044e05b20ddacc7b6d92093c Mon Sep 17 00:00:00 2001 From: Billy Brawner Date: Mon, 5 Nov 2018 22:37:30 -0600 Subject: [PATCH] Fix sharing --- app/src/main/java/com/wbrawner/cowsay/MainActivity.kt | 9 +++++++-- app/src/main/res/layout/activity_main.xml | 1 + 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/wbrawner/cowsay/MainActivity.kt b/app/src/main/java/com/wbrawner/cowsay/MainActivity.kt index 6d8a0b7..821bd30 100644 --- a/app/src/main/java/com/wbrawner/cowsay/MainActivity.kt +++ b/app/src/main/java/com/wbrawner/cowsay/MainActivity.kt @@ -41,9 +41,14 @@ class MainActivity : AppCompatActivity() { cowImage.outputStream().use { cowOut -> cowBitmap.compress(Bitmap.CompressFormat.JPEG, 100, cowOut) } + val fileUri = FileProvider.getUriForFile(this@MainActivity, "com.wbrawner.cowsay.fileprovider", cowImage) val shareIntent = Intent(Intent.ACTION_SEND).apply { - data = FileProvider.getUriForFile(this@MainActivity, "com.wbrawner.cowsay.fileprovider", cowImage) - type = contentResolver.getType(data!!) + setDataAndType( + fileUri, + contentResolver.getType(fileUri) + ) + putExtra(Intent.EXTRA_STREAM, fileUri) + addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION) } runOnUiThread { diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index db196fa..b94a7e8 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -42,6 +42,7 @@