adding FileProvider intent handling
This commit is contained in:
parent
2e16d023c8
commit
3c0cd4ff6e
|
@ -37,7 +37,7 @@ android {
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
compile 'com.simplemobiletools:commons:2.33.1'
|
compile 'com.simplemobiletools:commons:2.33.2'
|
||||||
compile 'com.bignerdranch.android:recyclerview-multiselect:0.2'
|
compile 'com.bignerdranch.android:recyclerview-multiselect:0.2'
|
||||||
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
||||||
|
|
||||||
|
|
|
@ -73,5 +73,15 @@
|
||||||
android:name="com.simplemobiletools.commons.activities.CustomizationActivity"
|
android:name="com.simplemobiletools.commons.activities.CustomizationActivity"
|
||||||
android:label="@string/customize_colors"
|
android:label="@string/customize_colors"
|
||||||
android:parentActivityName=".activities.SettingsActivity"/>
|
android:parentActivityName=".activities.SettingsActivity"/>
|
||||||
|
|
||||||
|
<provider
|
||||||
|
android:name="android.support.v4.content.FileProvider"
|
||||||
|
android:authorities="${applicationId}.provider"
|
||||||
|
android:exported="false"
|
||||||
|
android:grantUriPermissions="true">
|
||||||
|
<meta-data
|
||||||
|
android:name="android.support.FILE_PROVIDER_PATHS"
|
||||||
|
android:resource="@xml/provider_paths"/>
|
||||||
|
</provider>
|
||||||
</application>
|
</application>
|
||||||
</manifest>
|
</manifest>
|
||||||
|
|
|
@ -3,7 +3,6 @@ package com.simplemobiletools.filemanager.activities
|
||||||
import android.app.Activity
|
import android.app.Activity
|
||||||
import android.content.ClipData
|
import android.content.ClipData
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.net.Uri
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.os.Handler
|
import android.os.Handler
|
||||||
import android.view.Menu
|
import android.view.Menu
|
||||||
|
@ -223,16 +222,16 @@ class MainActivity : SimpleActivity() {
|
||||||
|
|
||||||
fun pickedPath(path: String) {
|
fun pickedPath(path: String) {
|
||||||
val resultIntent = Intent()
|
val resultIntent = Intent()
|
||||||
val uri = Uri.fromFile(File(path))
|
val uri = getFilePublicUri(File(path), BuildConfig.APPLICATION_ID)
|
||||||
val type = path.getMimeTypeFromPath()
|
val type = path.getMimeTypeFromPath()
|
||||||
resultIntent.setDataAndTypeAndNormalize(uri, type)
|
resultIntent.setDataAndTypeAndNormalize(uri, type)
|
||||||
resultIntent.flags = Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION
|
resultIntent.flags = Intent.FLAG_GRANT_READ_URI_PERMISSION
|
||||||
setResult(Activity.RESULT_OK, resultIntent)
|
setResult(Activity.RESULT_OK, resultIntent)
|
||||||
finish()
|
finish()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun pickedPaths(paths: ArrayList<String>) {
|
fun pickedPaths(paths: ArrayList<String>) {
|
||||||
val uris = paths.map { Uri.fromFile(File(it)) } as ArrayList
|
val uris = paths.map { getFilePublicUri(File(it), BuildConfig.APPLICATION_ID) } as ArrayList
|
||||||
val clipData = ClipData("Attachment", arrayOf(uris.getMimeType()), ClipData.Item(uris.removeAt(0)))
|
val clipData = ClipData("Attachment", arrayOf(uris.getMimeType()), ClipData.Item(uris.removeAt(0)))
|
||||||
|
|
||||||
uris.forEach {
|
uris.forEach {
|
||||||
|
|
|
@ -4,6 +4,7 @@ import android.content.Intent
|
||||||
import android.graphics.drawable.Drawable
|
import android.graphics.drawable.Drawable
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
|
import android.os.TransactionTooLargeException
|
||||||
import android.support.v7.view.ActionMode
|
import android.support.v7.view.ActionMode
|
||||||
import android.support.v7.widget.RecyclerView
|
import android.support.v7.widget.RecyclerView
|
||||||
import android.util.SparseArray
|
import android.util.SparseArray
|
||||||
|
@ -21,6 +22,7 @@ import com.simplemobiletools.commons.dialogs.PropertiesDialog
|
||||||
import com.simplemobiletools.commons.dialogs.RenameItemDialog
|
import com.simplemobiletools.commons.dialogs.RenameItemDialog
|
||||||
import com.simplemobiletools.commons.extensions.*
|
import com.simplemobiletools.commons.extensions.*
|
||||||
import com.simplemobiletools.commons.models.FileDirItem
|
import com.simplemobiletools.commons.models.FileDirItem
|
||||||
|
import com.simplemobiletools.filemanager.BuildConfig
|
||||||
import com.simplemobiletools.filemanager.R
|
import com.simplemobiletools.filemanager.R
|
||||||
import com.simplemobiletools.filemanager.activities.SimpleActivity
|
import com.simplemobiletools.filemanager.activities.SimpleActivity
|
||||||
import com.simplemobiletools.filemanager.dialogs.CompressAsDialog
|
import com.simplemobiletools.filemanager.dialogs.CompressAsDialog
|
||||||
|
@ -54,13 +56,14 @@ class ItemsAdapter(val activity: SimpleActivity, var mItems: MutableList<FileDir
|
||||||
fun toggleItemSelection(select: Boolean, pos: Int) {
|
fun toggleItemSelection(select: Boolean, pos: Int) {
|
||||||
if (select) {
|
if (select) {
|
||||||
if (itemViews[pos] != null) {
|
if (itemViews[pos] != null) {
|
||||||
itemViews[pos].item_frame?.isSelected = select
|
|
||||||
selectedPositions.add(pos)
|
selectedPositions.add(pos)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
selectedPositions.remove(pos)
|
selectedPositions.remove(pos)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
itemViews[pos]?.item_frame?.isSelected = select
|
||||||
|
|
||||||
if (selectedPositions.isEmpty()) {
|
if (selectedPositions.isEmpty()) {
|
||||||
actMode?.finish()
|
actMode?.finish()
|
||||||
return
|
return
|
||||||
|
@ -191,6 +194,8 @@ class ItemsAdapter(val activity: SimpleActivity, var mItems: MutableList<FileDir
|
||||||
|
|
||||||
try {
|
try {
|
||||||
activity.startActivity(Intent.createChooser(this, shareTitle))
|
activity.startActivity(Intent.createChooser(this, shareTitle))
|
||||||
|
} catch (e: TransactionTooLargeException) {
|
||||||
|
activity.toast(R.string.maximum_share_reached)
|
||||||
} catch (exception: Exception) {
|
} catch (exception: Exception) {
|
||||||
activity.showErrorToast(exception.cause.toString())
|
activity.showErrorToast(exception.cause.toString())
|
||||||
}
|
}
|
||||||
|
@ -203,7 +208,7 @@ class ItemsAdapter(val activity: SimpleActivity, var mItems: MutableList<FileDir
|
||||||
addFileUris(it, uris)
|
addFileUris(it, uris)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
uris.add(Uri.fromFile(file))
|
uris.add(activity.getFilePublicUri(file, BuildConfig.APPLICATION_ID))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,9 +13,11 @@ import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import com.simplemobiletools.commons.dialogs.StoragePickerDialog
|
import com.simplemobiletools.commons.dialogs.StoragePickerDialog
|
||||||
import com.simplemobiletools.commons.extensions.*
|
import com.simplemobiletools.commons.extensions.*
|
||||||
|
import com.simplemobiletools.commons.helpers.REAL_FILE_PATH
|
||||||
import com.simplemobiletools.commons.models.FileDirItem
|
import com.simplemobiletools.commons.models.FileDirItem
|
||||||
import com.simplemobiletools.commons.views.Breadcrumbs
|
import com.simplemobiletools.commons.views.Breadcrumbs
|
||||||
import com.simplemobiletools.commons.views.MyScalableRecyclerView
|
import com.simplemobiletools.commons.views.MyScalableRecyclerView
|
||||||
|
import com.simplemobiletools.filemanager.BuildConfig
|
||||||
import com.simplemobiletools.filemanager.R
|
import com.simplemobiletools.filemanager.R
|
||||||
import com.simplemobiletools.filemanager.activities.MainActivity
|
import com.simplemobiletools.filemanager.activities.MainActivity
|
||||||
import com.simplemobiletools.filemanager.activities.SimpleActivity
|
import com.simplemobiletools.filemanager.activities.SimpleActivity
|
||||||
|
@ -231,9 +233,16 @@ class ItemsFragment : Fragment(), ItemsAdapter.ItemOperationsListener, Breadcrum
|
||||||
val file = File(path)
|
val file = File(path)
|
||||||
val mimeType = path.getMimeTypeFromPath()
|
val mimeType = path.getMimeTypeFromPath()
|
||||||
|
|
||||||
|
val uri = context.getFilePublicUri(file, BuildConfig.APPLICATION_ID)
|
||||||
Intent(Intent.ACTION_VIEW).apply {
|
Intent(Intent.ACTION_VIEW).apply {
|
||||||
setDataAndType(Uri.fromFile(file), mimeType)
|
setDataAndType(uri, mimeType)
|
||||||
flags = Intent.FLAG_ACTIVITY_NEW_TASK
|
flags = Intent.FLAG_ACTIVITY_NEW_TASK
|
||||||
|
addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
|
||||||
|
|
||||||
|
if (context.isNougatPlus()) {
|
||||||
|
putExtra(REAL_FILE_PATH, Uri.fromFile(file))
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
startActivity(this)
|
startActivity(this)
|
||||||
} catch (e: ActivityNotFoundException) {
|
} catch (e: ActivityNotFoundException) {
|
||||||
|
@ -245,8 +254,10 @@ class ItemsFragment : Fragment(), ItemsAdapter.ItemOperationsListener, Breadcrum
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun tryGenericMimeType(intent: Intent, mimeType: String, file: File): Boolean {
|
private fun tryGenericMimeType(intent: Intent, mimeType: String, file: File): Boolean {
|
||||||
|
val uri = context.getFilePublicUri(file, BuildConfig.APPLICATION_ID)
|
||||||
val genericMimeType = getGenericMimeType(mimeType)
|
val genericMimeType = getGenericMimeType(mimeType)
|
||||||
intent.setDataAndType(Uri.fromFile(file), genericMimeType)
|
intent.setDataAndType(uri, genericMimeType)
|
||||||
|
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
|
||||||
return try {
|
return try {
|
||||||
startActivity(intent)
|
startActivity(intent)
|
||||||
true
|
true
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<paths>
|
||||||
|
<external-path name="external_files" path="."/>
|
||||||
|
<root-path name="external_files" path="/storage/" />
|
||||||
|
</paths>
|
Loading…
Reference in New Issue