mirror of
				https://github.com/SimpleMobileTools/Simple-File-Manager.git
				synced 2025-06-05 22:09:15 +02:00 
			
		
		
		
	handle get_content intent
This commit is contained in:
		| @@ -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" | ||||||
|   | |||||||
| @@ -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)) | ||||||
|   | |||||||
| @@ -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,20 +221,28 @@ class ItemsFragment : Fragment(), ItemsAdapter.ItemOperationsListener, Breadcrum | |||||||
|             openPath(item.path) |             openPath(item.path) | ||||||
|         } else { |         } else { | ||||||
|             val path = item.path |             val path = item.path | ||||||
|             val file = File(path) |             if (isGetContentIntent) { | ||||||
|             var mimeType: String? = MimeTypeMap.getSingleton().getMimeTypeFromExtension(path.getFilenameExtension().toLowerCase()) |                 (activity as MainActivity).pickedPath(path) | ||||||
|             if (mimeType == null) |             } else { | ||||||
|                 mimeType = "text/plain" |                 fileClicked(path) | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  |  | ||||||
|             Intent(Intent.ACTION_VIEW).apply { |     private fun fileClicked(path: String) { | ||||||
|                 setDataAndType(Uri.fromFile(file), mimeType) |         val file = File(path) | ||||||
|                 flags = Intent.FLAG_ACTIVITY_NEW_TASK |         var mimeType: String? = MimeTypeMap.getSingleton().getMimeTypeFromExtension(path.getFilenameExtension().toLowerCase()) | ||||||
|                 try { |         if (mimeType == null) | ||||||
|                     startActivity(this) |             mimeType = "text/plain" | ||||||
|                 } catch (e: ActivityNotFoundException) { |  | ||||||
|                     if (!tryGenericMimeType(this, mimeType!!, file)) { |         Intent(Intent.ACTION_VIEW).apply { | ||||||
|                         activity.toast(R.string.no_app_found) |             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) | ||||||
|                 } |                 } | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user