It is possible. I finally got it. My app opens when the user clics on email attachments of a predefined mimetype (mine ends in ".mb8") and copy the attached file to a local directory. First, we have to assigne the mimetype to our app in the manifest file, adding these lines:
AddActivityText(myActivity,
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<action android:name="android.intent.action.EDIT" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:mimeType="application/octet-stream"
android:host="*"
android:pathPattern=".*\\.xxx"
/>
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<action android:name="android.intent.action.EDIT" />
<category android:name="android.intent.category.DEFAULT" />
<data
android:mimeType="application/xxx"
android:host="*"
android:pathPattern=".*\\.xxx"
/>
</intent-filter>)
Where xxx is the type chosen and myActivity is the activity that opens when the user clics on the attachment. Then, in the activity, we just write:
Dim Intent1 As Intent
Intent1 = Activity.GetStartingIntent
If Intent1.Action = "android.intent.action.VIEW" Then ' The activity has been called from outside the app
Dim jo As JavaObject
Dim cd As String = jo.InitializeStatic("anywheresoftware.b4a.objects.streams.File").GetField("ContentDir")
Dim UriString As String = intent1.GetData
Dim Inp As InputStream = File.OpenInput(cd , UriString)
Dim Out As OutputStream = File.OpenOutput(myFolder, myFile, False)
File.copy2(Inp, Out)
Inp.Close
Out.Close
End if
What we cannot do, of course, is modifying the original attachment, but it can be copied elsewhere.