From c520c8c557ae10846920fbab46cac785ab78981f Mon Sep 17 00:00:00 2001 From: tibbi Date: Fri, 27 Oct 2017 10:54:49 +0200 Subject: [PATCH] send real filepath as an extra with View intent --- .../gallery/activities/MediaActivity.kt | 4 +--- .../gallery/activities/PhotoVideoActivity.kt | 5 +++++ .../com/simplemobiletools/gallery/extensions/activity.kt | 9 +++++---- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt index 3c262657d..f20aa4c39 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt @@ -24,7 +24,6 @@ import com.simplemobiletools.commons.extensions.* import com.simplemobiletools.commons.helpers.PERMISSION_WRITE_STORAGE import com.simplemobiletools.commons.models.RadioItem import com.simplemobiletools.commons.views.MyScalableRecyclerView -import com.simplemobiletools.gallery.BuildConfig import com.simplemobiletools.gallery.R import com.simplemobiletools.gallery.adapters.MediaAdapter import com.simplemobiletools.gallery.asynctasks.GetMediaAsynctask @@ -505,8 +504,7 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { val file = File(path) val isVideo = file.isVideoFast() if (isVideo) { - val uri = getFilePublicUri(file, BuildConfig.APPLICATION_ID) - openFile(uri) + openFile(Uri.fromFile(file)) } else { Intent(this, ViewPagerActivity::class.java).apply { putExtra(MEDIUM, path) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/PhotoVideoActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/PhotoVideoActivity.kt index 1f79262f0..732ca17a6 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/PhotoVideoActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/PhotoVideoActivity.kt @@ -21,6 +21,7 @@ import com.simplemobiletools.gallery.fragments.ViewPagerFragment import com.simplemobiletools.gallery.helpers.IS_FROM_GALLERY import com.simplemobiletools.gallery.helpers.IS_VIEW_INTENT import com.simplemobiletools.gallery.helpers.MEDIUM +import com.simplemobiletools.gallery.helpers.REAL_FILE_PATH import com.simplemobiletools.gallery.models.Medium import kotlinx.android.synthetic.main.fragment_holder.* import java.io.File @@ -50,6 +51,10 @@ open class PhotoVideoActivity : SimpleActivity(), ViewPagerFragment.FragmentList private fun checkIntent(savedInstanceState: Bundle? = null) { mUri = intent.data ?: return + if (intent.extras.containsKey(REAL_FILE_PATH)) { + mUri = intent.extras.get(REAL_FILE_PATH) as Uri + } + mIsFromGallery = intent.getBooleanExtra(IS_FROM_GALLERY, false) if (mUri.scheme == "file") { diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/activity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/activity.kt index 454c05955..b2b64e339 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/activity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/activity.kt @@ -18,10 +18,7 @@ import com.simplemobiletools.commons.helpers.* import com.simplemobiletools.gallery.BuildConfig import com.simplemobiletools.gallery.R import com.simplemobiletools.gallery.activities.SimpleActivity -import com.simplemobiletools.gallery.helpers.IS_FROM_GALLERY -import com.simplemobiletools.gallery.helpers.NOMEDIA -import com.simplemobiletools.gallery.helpers.REQUEST_EDIT_IMAGE -import com.simplemobiletools.gallery.helpers.REQUEST_SET_AS +import com.simplemobiletools.gallery.helpers.* import com.simplemobiletools.gallery.models.Directory import com.simplemobiletools.gallery.models.Medium import com.simplemobiletools.gallery.views.MySquareImageView @@ -90,6 +87,10 @@ fun Activity.openFile(uri: Uri) { addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION) putExtra(IS_FROM_GALLERY, true) + if (isNougatPlus()) { + putExtra(REAL_FILE_PATH, uri) + } + if (resolveActivity(packageManager) != null) { val chooser = Intent.createChooser(this, getString(R.string.open_with)) startActivity(chooser)