Code Monkey home page Code Monkey logo

Comments (8)

MateusRodCosta avatar MateusRodCosta commented on June 26, 2024 1

@CyberShadow So, I did search about what would be the best way to programmatically add and remove intent filters...
The most interesting option I found was to use activity aliases and use the enabling/disabling of components based on a setting.

Unfortunately I'm currently running on issue trying to get this working, but I believe I made some progress.

from share2storage.

CyberShadow avatar CyberShadow commented on June 26, 2024

This does it:

diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 48e55b4..323fb7c 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -25,6 +25,7 @@
 
             <intent-filter>
                 <action android:name="android.intent.action.SEND" />
+                <action android:name="android.intent.action.VIEW" />
 
                 <category android:name="android.intent.category.DEFAULT" />
 
diff --git a/app/src/main/kotlin/com/mateusrodcosta/apps/share2storage/DetailsActivity.kt b/app/src/main/kotlin/com/mateusrodcosta/apps/share2storage/DetailsActivity.kt
index 4e4daf6..ebb8a94 100644
--- a/app/src/main/kotlin/com/mateusrodcosta/apps/share2storage/DetailsActivity.kt
+++ b/app/src/main/kotlin/com/mateusrodcosta/apps/share2storage/DetailsActivity.kt
@@ -81,13 +81,16 @@ class DetailsActivity : ComponentActivity() {
     }
 
     private fun handleIntent() {
-        if (intent.action == Intent.ACTION_SEND) {
-            val fileUri: Uri? =
+        if (intent.action == Intent.ACTION_SEND || intent.action == Intent.ACTION_VIEW) {
+            var fileUri: Uri? =
                 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) intent.getParcelableExtra(
                     Intent.EXTRA_STREAM,
                     Uri::class.java
                 )
                 else @Suppress("DEPRECATION") intent.getParcelableExtra(Intent.EXTRA_STREAM)
+            if (fileUri == null) {
+                fileUri = intent.data;
+            }
             Log.d("fileUri", fileUri.toString())
             uriData = getUriData(contentResolver, fileUri)
 

Probably should be optional, which means that the intent-filter needs to be set programmatically, so maybe a bit more code than that.

Or maybe there's no reason why it should be optional.

from share2storage.

MateusRodCosta avatar MateusRodCosta commented on June 26, 2024

@CyberShadow Hey, thanks for the feature request!

Well, since it's just a bit outside of the main use case but adjacent to it, I believe I could do it but it would have to be gated behind a preference.

So, yeah, I will have to figure out how to dynamically add (or at least enable) new intent filters.

Thanks for the code excerpt, I will take a look into this in the near future.

from share2storage.

CyberShadow avatar CyberShadow commented on June 26, 2024

Thanks for considering it.

For the record, the use case is that for some reason, my bank app does not allow saving/sharing/exporting receipts - only viewing them.

The above patch allowed me to actually save the receipt and attach it to a customs declaration.

from share2storage.

MateusRodCosta avatar MateusRodCosta commented on June 26, 2024

@CyberShadow I managed to implement this and it will make it into the next version!
The next version is planned for either the end of this month or start of next month, in the mean time you can compile the current dev branch yourself.

from share2storage.

CyberShadow avatar CyberShadow commented on June 26, 2024

Excellent!

Does it need testing?

I'm surprised that your diff almost doesn't touch DetailsActivity like mine did.

from share2storage.

MateusRodCosta avatar MateusRodCosta commented on June 26, 2024

I'm surprised that your diff almost doesn't touch DetailsActivity like mine did.

Actually, I got so distracted focusing on the manifest (the activity alias) and on the setting that I might have forgot completely to edit the DetailsActivity code that actually grabs the intent.

I will fix that in a bit.

from share2storage.

MateusRodCosta avatar MateusRodCosta commented on June 26, 2024

Actually, I got so distracted focusing on the manifest (the activity alias) and on the setting that I might have forgot completely to edit the DetailsActivity code that actually grabs the intent.

Should be fixed now.

Does it need testing?

Sure, feel free to test it!

from share2storage.

Related Issues (13)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.