handle get_content intent
This commit is contained in:
parent
e0703acd9d
commit
679d68fc26
3 changed files with 50 additions and 18 deletions
|
@ -23,7 +23,15 @@
|
|||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
<activity android:name=".activities.MainActivity"/>
|
||||
<activity android:name=".activities.MainActivity">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.GET_CONTENT"/>
|
||||
<data android:mimeType="*/*"/>
|
||||
|
||||
<category android:name="android.intent.category.OPENABLE"/>
|
||||
<category android:name="android.intent.category.DEFAULT"/>
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
<activity
|
||||
android:name="com.simplemobiletools.commons.activities.AboutActivity"
|
||||
|
|
|
@ -1,15 +1,14 @@
|
|||
package com.simplemobiletools.filemanager.activities
|
||||
|
||||
import android.app.Activity
|
||||
import android.content.Intent
|
||||
import android.net.Uri
|
||||
import android.os.Bundle
|
||||
import android.os.Handler
|
||||
import android.view.Menu
|
||||
import android.view.MenuItem
|
||||
import com.simplemobiletools.commons.dialogs.RadioGroupDialog
|
||||
import com.simplemobiletools.commons.extensions.checkWhatsNew
|
||||
import com.simplemobiletools.commons.extensions.handleHiddenFolderPasswordProtection
|
||||
import com.simplemobiletools.commons.extensions.storeStoragePaths
|
||||
import com.simplemobiletools.commons.extensions.toast
|
||||
import com.simplemobiletools.commons.extensions.*
|
||||
import com.simplemobiletools.commons.helpers.LICENSE_KOTLIN
|
||||
import com.simplemobiletools.commons.helpers.LICENSE_MULTISELECT
|
||||
import com.simplemobiletools.commons.helpers.LICENSE_PATTERN
|
||||
|
@ -25,11 +24,13 @@ import com.simplemobiletools.filemanager.helpers.RootHelpers
|
|||
import com.stericson.RootTools.RootTools
|
||||
import kotlinx.android.synthetic.main.activity_main.*
|
||||
import kotlinx.android.synthetic.main.items_fragment.*
|
||||
import java.io.File
|
||||
import java.util.*
|
||||
|
||||
class MainActivity : SimpleActivity() {
|
||||
private val BACK_PRESS_TIMEOUT = 5000
|
||||
private var wasBackJustPressed = false
|
||||
private var isGetContentIntent = false
|
||||
|
||||
private lateinit var fragment: ItemsFragment
|
||||
|
||||
|
@ -39,6 +40,9 @@ class MainActivity : SimpleActivity() {
|
|||
storeStoragePaths()
|
||||
|
||||
fragment = fragment_holder as ItemsFragment
|
||||
isGetContentIntent = intent.action == Intent.ACTION_GET_CONTENT
|
||||
fragment.isGetContentIntent = isGetContentIntent
|
||||
|
||||
tryInitFileManager()
|
||||
checkWhatsNewDialog()
|
||||
checkIfRootAvailable()
|
||||
|
@ -191,6 +195,16 @@ class MainActivity : SimpleActivity() {
|
|||
}).start()
|
||||
}
|
||||
|
||||
fun pickedPath(path: String) {
|
||||
val resultIntent = Intent()
|
||||
val uri = Uri.fromFile(File(path))
|
||||
val type = File(path).getMimeType("image/jpeg")
|
||||
resultIntent.setDataAndTypeAndNormalize(uri, type)
|
||||
resultIntent.flags = Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION
|
||||
setResult(Activity.RESULT_OK, resultIntent)
|
||||
finish()
|
||||
}
|
||||
|
||||
private fun checkWhatsNewDialog() {
|
||||
arrayListOf<Release>().apply {
|
||||
add(Release(26, R.string.release_26))
|
||||
|
|
|
@ -18,6 +18,7 @@ import com.simplemobiletools.commons.models.FileDirItem
|
|||
import com.simplemobiletools.commons.views.Breadcrumbs
|
||||
import com.simplemobiletools.commons.views.MyScalableRecyclerView
|
||||
import com.simplemobiletools.filemanager.R
|
||||
import com.simplemobiletools.filemanager.activities.MainActivity
|
||||
import com.simplemobiletools.filemanager.activities.SimpleActivity
|
||||
import com.simplemobiletools.filemanager.adapters.ItemsAdapter
|
||||
import com.simplemobiletools.filemanager.dialogs.CreateNewItemDialog
|
||||
|
@ -33,6 +34,7 @@ import kotlin.collections.ArrayList
|
|||
|
||||
class ItemsFragment : Fragment(), ItemsAdapter.ItemOperationsListener, Breadcrumbs.BreadcrumbsListener {
|
||||
var currentPath = ""
|
||||
var isGetContentIntent = false
|
||||
|
||||
private var storedTextColor = 0
|
||||
private var showHidden = false
|
||||
|
@ -219,20 +221,28 @@ class ItemsFragment : Fragment(), ItemsAdapter.ItemOperationsListener, Breadcrum
|
|||
openPath(item.path)
|
||||
} else {
|
||||
val path = item.path
|
||||
val file = File(path)
|
||||
var mimeType: String? = MimeTypeMap.getSingleton().getMimeTypeFromExtension(path.getFilenameExtension().toLowerCase())
|
||||
if (mimeType == null)
|
||||
mimeType = "text/plain"
|
||||
if (isGetContentIntent) {
|
||||
(activity as MainActivity).pickedPath(path)
|
||||
} else {
|
||||
fileClicked(path)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Intent(Intent.ACTION_VIEW).apply {
|
||||
setDataAndType(Uri.fromFile(file), mimeType)
|
||||
flags = Intent.FLAG_ACTIVITY_NEW_TASK
|
||||
try {
|
||||
startActivity(this)
|
||||
} catch (e: ActivityNotFoundException) {
|
||||
if (!tryGenericMimeType(this, mimeType!!, file)) {
|
||||
activity.toast(R.string.no_app_found)
|
||||
}
|
||||
private fun fileClicked(path: String) {
|
||||
val file = File(path)
|
||||
var mimeType: String? = MimeTypeMap.getSingleton().getMimeTypeFromExtension(path.getFilenameExtension().toLowerCase())
|
||||
if (mimeType == null)
|
||||
mimeType = "text/plain"
|
||||
|
||||
Intent(Intent.ACTION_VIEW).apply {
|
||||
setDataAndType(Uri.fromFile(file), mimeType)
|
||||
flags = Intent.FLAG_ACTIVITY_NEW_TASK
|
||||
try {
|
||||
startActivity(this)
|
||||
} catch (e: ActivityNotFoundException) {
|
||||
if (!tryGenericMimeType(this, mimeType!!, file)) {
|
||||
activity.toast(R.string.no_app_found)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue