adding FileProvider intent handling
This commit is contained in:
parent
2e16d023c8
commit
3c0cd4ff6e
|
@ -37,7 +37,7 @@ android {
|
|||
}
|
||||
|
||||
dependencies {
|
||||
compile 'com.simplemobiletools:commons:2.33.1'
|
||||
compile 'com.simplemobiletools:commons:2.33.2'
|
||||
compile 'com.bignerdranch.android:recyclerview-multiselect:0.2'
|
||||
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
||||
|
||||
|
|
|
@ -73,5 +73,15 @@
|
|||
android:name="com.simplemobiletools.commons.activities.CustomizationActivity"
|
||||
android:label="@string/customize_colors"
|
||||
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>
|
||||
</manifest>
|
||||
|
|
|
@ -3,7 +3,6 @@ package com.simplemobiletools.filemanager.activities
|
|||
import android.app.Activity
|
||||
import android.content.ClipData
|
||||
import android.content.Intent
|
||||
import android.net.Uri
|
||||
import android.os.Bundle
|
||||
import android.os.Handler
|
||||
import android.view.Menu
|
||||
|
@ -223,16 +222,16 @@ class MainActivity : SimpleActivity() {
|
|||
|
||||
fun pickedPath(path: String) {
|
||||
val resultIntent = Intent()
|
||||
val uri = Uri.fromFile(File(path))
|
||||
val uri = getFilePublicUri(File(path), BuildConfig.APPLICATION_ID)
|
||||
val type = path.getMimeTypeFromPath()
|
||||
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)
|
||||
finish()
|
||||
}
|
||||
|
||||
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)))
|
||||
|
||||
uris.forEach {
|
||||
|
|
|
@ -4,6 +4,7 @@ import android.content.Intent
|
|||
import android.graphics.drawable.Drawable
|
||||
import android.net.Uri
|
||||
import android.os.Build
|
||||
import android.os.TransactionTooLargeException
|
||||
import android.support.v7.view.ActionMode
|
||||
import android.support.v7.widget.RecyclerView
|
||||
import android.util.SparseArray
|
||||
|
@ -21,6 +22,7 @@ import com.simplemobiletools.commons.dialogs.PropertiesDialog
|
|||
import com.simplemobiletools.commons.dialogs.RenameItemDialog
|
||||
import com.simplemobiletools.commons.extensions.*
|
||||
import com.simplemobiletools.commons.models.FileDirItem
|
||||
import com.simplemobiletools.filemanager.BuildConfig
|
||||
import com.simplemobiletools.filemanager.R
|
||||
import com.simplemobiletools.filemanager.activities.SimpleActivity
|
||||
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) {
|
||||
if (select) {
|
||||
if (itemViews[pos] != null) {
|
||||
itemViews[pos].item_frame?.isSelected = select
|
||||
selectedPositions.add(pos)
|
||||
}
|
||||
} else {
|
||||
selectedPositions.remove(pos)
|
||||
}
|
||||
|
||||
itemViews[pos]?.item_frame?.isSelected = select
|
||||
|
||||
if (selectedPositions.isEmpty()) {
|
||||
actMode?.finish()
|
||||
return
|
||||
|
@ -191,6 +194,8 @@ class ItemsAdapter(val activity: SimpleActivity, var mItems: MutableList<FileDir
|
|||
|
||||
try {
|
||||
activity.startActivity(Intent.createChooser(this, shareTitle))
|
||||
} catch (e: TransactionTooLargeException) {
|
||||
activity.toast(R.string.maximum_share_reached)
|
||||
} catch (exception: Exception) {
|
||||
activity.showErrorToast(exception.cause.toString())
|
||||
}
|
||||
|
@ -203,7 +208,7 @@ class ItemsAdapter(val activity: SimpleActivity, var mItems: MutableList<FileDir
|
|||
addFileUris(it, uris)
|
||||
}
|
||||
} 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 com.simplemobiletools.commons.dialogs.StoragePickerDialog
|
||||
import com.simplemobiletools.commons.extensions.*
|
||||
import com.simplemobiletools.commons.helpers.REAL_FILE_PATH
|
||||
import com.simplemobiletools.commons.models.FileDirItem
|
||||
import com.simplemobiletools.commons.views.Breadcrumbs
|
||||
import com.simplemobiletools.commons.views.MyScalableRecyclerView
|
||||
import com.simplemobiletools.filemanager.BuildConfig
|
||||
import com.simplemobiletools.filemanager.R
|
||||
import com.simplemobiletools.filemanager.activities.MainActivity
|
||||
import com.simplemobiletools.filemanager.activities.SimpleActivity
|
||||
|
@ -231,9 +233,16 @@ class ItemsFragment : Fragment(), ItemsAdapter.ItemOperationsListener, Breadcrum
|
|||
val file = File(path)
|
||||
val mimeType = path.getMimeTypeFromPath()
|
||||
|
||||
val uri = context.getFilePublicUri(file, BuildConfig.APPLICATION_ID)
|
||||
Intent(Intent.ACTION_VIEW).apply {
|
||||
setDataAndType(Uri.fromFile(file), mimeType)
|
||||
setDataAndType(uri, mimeType)
|
||||
flags = Intent.FLAG_ACTIVITY_NEW_TASK
|
||||
addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
|
||||
|
||||
if (context.isNougatPlus()) {
|
||||
putExtra(REAL_FILE_PATH, Uri.fromFile(file))
|
||||
}
|
||||
|
||||
try {
|
||||
startActivity(this)
|
||||
} catch (e: ActivityNotFoundException) {
|
||||
|
@ -245,8 +254,10 @@ class ItemsFragment : Fragment(), ItemsAdapter.ItemOperationsListener, Breadcrum
|
|||
}
|
||||
|
||||
private fun tryGenericMimeType(intent: Intent, mimeType: String, file: File): Boolean {
|
||||
val uri = context.getFilePublicUri(file, BuildConfig.APPLICATION_ID)
|
||||
val genericMimeType = getGenericMimeType(mimeType)
|
||||
intent.setDataAndType(Uri.fromFile(file), genericMimeType)
|
||||
intent.setDataAndType(uri, genericMimeType)
|
||||
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
|
||||
return try {
|
||||
startActivity(intent)
|
||||
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