Android Question How Intent Filters can read files on /data/data folder?

ivan.tellez

Active Member
Licensed User
Longtime User
Yes, i already know, data/data/appname/files it can be readed only by the owner app or by any app with root.

BUT, this is actually not true, for example, the outlook app, when you open a email with attachments, this files are stores in a folder under file:///data/data/com.microsoft.office.outlook/

Then, a chooser will appear to open the file, for example, WPS office, and those apps CAN READ the file from the private data/data folder (you can click on file info to see the path)


So, I added the Intent Filter on my app to read XML files, and its working great for any location but /data/data.

This app worked with the hotmail app that saved the attacments on the publick doenloads folder.

When i click a XML file on the Outlook app, my app opens and the intent data is correct (file:///data/data/com.microsoft.office.outlook/app_1-1%253AKgDirMsBwsNWyd0aRctGLQ/SEP210905778.282.1.X.cfdi.xml), but the file.exists function returns false.

B4X:
Sub Activity_Resume
Dim XmlData As String
Dim XmlPath As String
Dim XmlFile As String

Dim In As Intent

    In = Activity.GetStartingIntent
    If In <> Null Then

        XmlData = In.GetData

         If XmlData <> Null Then
            XmlPath = XmlData.SubString2(0,XmlData.LastIndexOf("/"))
            XmlPath = XmlPath.Replace("file:///","")
             XmlFile = XmlData.SubString(XmlData.LastIndexOf("/")+1)
           
            If File.Exists(XmlPath, XmlFile) = True Then    
                Log(File.GetText(XmlPath, XmlFile))  'this works on otrher paths
            Else
                Log("ERROR")

        End If
     End If
End Sub


Any ideas on this?

thanks
 

ivan.tellez

Active Member
Licensed User
Longtime User
It is not possible to open an internal file of another app.

Yea, its weird, for example, in the screenshot, the WPS office has the file open. It shows the data/data path, but if i close the file, the close the app, restar the phone, open wps and select the file again from "recent files", wps can open it again. o_O

Same with the other apps, like solid explorer.

If outlook its implementing a content provider, can B4A implement the filter to pen this file? Is there an example to use the "content" scheme instead of the "file" in the
GetStartingIntent?

Thanks
 

Attachments

  • Screenshot_2015-11-29-09-17-10.png
    Screenshot_2015-11-29-09-17-10.png
    134.8 KB · Views: 219
Upvote 0

ivan.tellez

Active Member
Licensed User
Longtime User
Monitor the unfiltered logs and see which intent is being sent when you open the file.


In the logs I can only see this:

B4X:
findPreferredActivity: We found 1 PreferredActivities set, but no match
Adding preferred activity ComponentInfo{com.ioxsoft.cfdivalidadorplus/com.ioxsoft.cfdivalidadorplus.main} for user 0 :
  Action: "android.intent.action.VIEW"
  Category: "android.intent.category.DEFAULT"
  Type: "text/xml"

But this is the Intent Filter declared in the manifest

B4X:
AddActivityText(Main,
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/xml" />
</intent-filter>)



In the debug, after calling:

B4X:
In = Activity.GetStartingIntent

Looks like this:

intent.jpg
 
Upvote 0

ivan.tellez

Active Member
Licensed User
Longtime User
Hi @Erel

After lots of intents XD, finaly i could open the file.

But its kind strange, maybe a bug in B4A.

As you can see in the picture on my last post, the path in the mData of the intent has 2 different versions; encoded and decoded.

I was debugging and put manualy on the starting intent the decoded part:

B4X:
XmlPath = "data/data/com.microsoft.office.outlook/app_1-1%3At3iOwd16NDIx-oP-o6U3dg"
XmlFile = "A5192 06-12-15.xml"


When you use the XmlData = In.GetData, the intent returns a path based on the encoded, this fails.

So, I used the decoded path, and this way, the file oppens o_O

(All the paths had a %, encoded as %25 )

Is this a Bug?

how can you get the decoded path?


I already tried:

B4X:
    XmlData = In.GetData
        Dim jo As JavaObject = In
        test1 = jo.RunMethod("getData", Null)
        test2 = jo.RunMethod("getDataString", Null)

Both return the encoded path :(
 
Upvote 0

ivan.tellez

Active Member
Licensed User
Longtime User
Well, adding this works on my device:

B4X:
Dim jo As JavaObject
jo.InitializeStatic("android.net.Uri")
XmlData = jo.RunMethod("decode", Array(XmlData))


Why the FILE operations did not work with the encoded path?
 
Upvote 0
Top