handle get_content intent

This commit is contained in:
tibbi 2017-10-23 10:13:06 +02:00
parent e0703acd9d
commit 679d68fc26
3 changed files with 50 additions and 18 deletions

View File

@ -23,7 +23,15 @@
</intent-filter> </intent-filter>
</activity> </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 <activity
android:name="com.simplemobiletools.commons.activities.AboutActivity" android:name="com.simplemobiletools.commons.activities.AboutActivity"

View File

@ -1,15 +1,14 @@
package com.simplemobiletools.filemanager.activities package com.simplemobiletools.filemanager.activities
import android.app.Activity
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
import android.view.MenuItem import android.view.MenuItem
import com.simplemobiletools.commons.dialogs.RadioGroupDialog import com.simplemobiletools.commons.dialogs.RadioGroupDialog
import com.simplemobiletools.commons.extensions.checkWhatsNew import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.extensions.handleHiddenFolderPasswordProtection
import com.simplemobiletools.commons.extensions.storeStoragePaths
import com.simplemobiletools.commons.extensions.toast
import com.simplemobiletools.commons.helpers.LICENSE_KOTLIN import com.simplemobiletools.commons.helpers.LICENSE_KOTLIN
import com.simplemobiletools.commons.helpers.LICENSE_MULTISELECT import com.simplemobiletools.commons.helpers.LICENSE_MULTISELECT
import com.simplemobiletools.commons.helpers.LICENSE_PATTERN import com.simplemobiletools.commons.helpers.LICENSE_PATTERN
@ -25,11 +24,13 @@ import com.simplemobiletools.filemanager.helpers.RootHelpers
import com.stericson.RootTools.RootTools import com.stericson.RootTools.RootTools
import kotlinx.android.synthetic.main.activity_main.* import kotlinx.android.synthetic.main.activity_main.*
import kotlinx.android.synthetic.main.items_fragment.* import kotlinx.android.synthetic.main.items_fragment.*
import java.io.File
import java.util.* import java.util.*
class MainActivity : SimpleActivity() { class MainActivity : SimpleActivity() {
private val BACK_PRESS_TIMEOUT = 5000 private val BACK_PRESS_TIMEOUT = 5000
private var wasBackJustPressed = false private var wasBackJustPressed = false
private var isGetContentIntent = false
private lateinit var fragment: ItemsFragment private lateinit var fragment: ItemsFragment
@ -39,6 +40,9 @@ class MainActivity : SimpleActivity() {
storeStoragePaths() storeStoragePaths()
fragment = fragment_holder as ItemsFragment fragment = fragment_holder as ItemsFragment
isGetContentIntent = intent.action == Intent.ACTION_GET_CONTENT
fragment.isGetContentIntent = isGetContentIntent
tryInitFileManager() tryInitFileManager()
checkWhatsNewDialog() checkWhatsNewDialog()
checkIfRootAvailable() checkIfRootAvailable()
@ -191,6 +195,16 @@ class MainActivity : SimpleActivity() {
}).start() }).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() { private fun checkWhatsNewDialog() {
arrayListOf<Release>().apply { arrayListOf<Release>().apply {
add(Release(26, R.string.release_26)) add(Release(26, R.string.release_26))

View File

@ -18,6 +18,7 @@ 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.R import com.simplemobiletools.filemanager.R
import com.simplemobiletools.filemanager.activities.MainActivity
import com.simplemobiletools.filemanager.activities.SimpleActivity import com.simplemobiletools.filemanager.activities.SimpleActivity
import com.simplemobiletools.filemanager.adapters.ItemsAdapter import com.simplemobiletools.filemanager.adapters.ItemsAdapter
import com.simplemobiletools.filemanager.dialogs.CreateNewItemDialog import com.simplemobiletools.filemanager.dialogs.CreateNewItemDialog
@ -33,6 +34,7 @@ import kotlin.collections.ArrayList
class ItemsFragment : Fragment(), ItemsAdapter.ItemOperationsListener, Breadcrumbs.BreadcrumbsListener { class ItemsFragment : Fragment(), ItemsAdapter.ItemOperationsListener, Breadcrumbs.BreadcrumbsListener {
var currentPath = "" var currentPath = ""
var isGetContentIntent = false
private var storedTextColor = 0 private var storedTextColor = 0
private var showHidden = false private var showHidden = false
@ -219,6 +221,15 @@ class ItemsFragment : Fragment(), ItemsAdapter.ItemOperationsListener, Breadcrum
openPath(item.path) openPath(item.path)
} else { } else {
val path = item.path val path = item.path
if (isGetContentIntent) {
(activity as MainActivity).pickedPath(path)
} else {
fileClicked(path)
}
}
}
private fun fileClicked(path: String) {
val file = File(path) val file = File(path)
var mimeType: String? = MimeTypeMap.getSingleton().getMimeTypeFromExtension(path.getFilenameExtension().toLowerCase()) var mimeType: String? = MimeTypeMap.getSingleton().getMimeTypeFromExtension(path.getFilenameExtension().toLowerCase())
if (mimeType == null) if (mimeType == null)
@ -236,7 +247,6 @@ 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 genericMimeType = getGenericMimeType(mimeType) val genericMimeType = getGenericMimeType(mimeType)