fix opening .apk files, treat them specially

This commit is contained in:
tibbi 2017-11-19 19:42:42 +01:00
parent a6f82c466a
commit 0605b85b35
3 changed files with 25 additions and 6 deletions

View File

@ -165,7 +165,7 @@ class ItemsAdapter(activity: SimpleActivity, var fileDirItems: MutableList<FileD
private fun openWith() {
val file = File(getSelectedMedia().first().path)
activity.openFile(Uri.fromFile(file), true)
activity.openFile(file, true)
}
private fun copyMoveTo(isCopyOperation: Boolean) {

View File

@ -1,17 +1,37 @@
package com.simplemobiletools.filemanager.extensions
import android.app.Activity
import android.content.Intent
import android.net.Uri
import com.simplemobiletools.commons.extensions.openFile
import com.simplemobiletools.commons.extensions.setAs
import com.simplemobiletools.commons.extensions.shareUris
import android.support.v4.content.FileProvider
import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.filemanager.BuildConfig
import java.io.File
import java.util.*
fun Activity.shareUris(uris: ArrayList<Uri>) {
shareUris(uris, BuildConfig.APPLICATION_ID)
}
fun Activity.openFile(file: File, forceChooser: Boolean) {
if (!forceChooser && file.absolutePath.endsWith(".apk", true)) {
val uri = if (isNougatPlus()) {
FileProvider.getUriForFile(this, "${BuildConfig.APPLICATION_ID}.provider", file)
} else {
Uri.fromFile(file)
}
Intent().apply {
action = Intent.ACTION_VIEW
setDataAndType(uri, getMimeTypeFromUri(uri))
addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
startActivity(this)
}
} else {
openFile(Uri.fromFile(file), forceChooser)
}
}
fun Activity.openFile(uri: Uri, forceChooser: Boolean) {
openFile(uri, forceChooser, BuildConfig.APPLICATION_ID)
}

View File

@ -1,6 +1,5 @@
package com.simplemobiletools.filemanager.fragments
import android.net.Uri
import android.os.Bundle
import android.os.Parcelable
import android.support.v4.app.Fragment
@ -220,7 +219,7 @@ class ItemsFragment : Fragment(), ItemsAdapter.ItemOperationsListener, Breadcrum
}
} else {
val file = File(path)
activity!!.openFile(Uri.fromFile(file), false)
activity!!.openFile(file, false)
}
}
}