Android Question Opening specified file

microbox

Active Member
Licensed User
Longtime User
Hello everyone, I need to have an alternative way to open documents in a USB storage device...I've been using Polaris Office, but not really what I'm aiming for. I need a way to open it by folder name/ specified path. Can anyone suggest how can it be doable? I'm looking similar way done in vbnet
System.Diagnostics.Process.Start("C:\path\filename.doc"). Is there any library available? I Appreciate any help.
BTW Just to make it clear, this is how I call Polaris Office in my program...
StartActivity(pm.GetApplicationIntent("com.infraware.office.link"))

Thanks in advance,
Joe
 
Last edited:
Hi Erel, I'm using this code below..
B4X:
Expand Collapse Copy
Sub OpenMsWord
Dim MyPath As String
Dim i As Intent 'Requires a reference to the Phone library
MyPath = "/mnt/sdcard/extStorages/UsbDriveA/MayMay.docx"
i.Initialize(i.ACTION_VIEW, MyPath)
i.SetType("application/vnd.ms-word")
StartActivity(i)
End Sub
It opens up the WPS Office application but does not open the specified file.
export_04.jpg

export_03.jpg


should be opening the MayMay.docx file.
 
Last edited:
Upvote 0
No problem When trying to open from file explorer, just don't work as expected when trying with the code.
I don't know if its related to android version issue, right now I'm running the demo code in honeycomb. I appreciate if anyone can confirm if my code above is bad or something is missing.

Thanks in advance...
 
Upvote 0
I test this code to open a text file and it works okay.
B4X:
Expand Collapse Copy
Dim MyPath As String
If File.Exists("/mnt/sdcard/extStorages/UsbDriveB","Text.txt") Then
    Msgbox("File exist!","")
    Else
        Msgbox("Not found","")
End If
MyPath = "/mnt/sdcard/extStorages/UsbDriveB/Text.txt"
i.Initialize(i.ACTION_VIEW, MyPath)
i.SetType("text/plain")
StartActivity(i)

But this don't work..
B4X:
Expand Collapse Copy
Dim MyPath As String
If File.Exists("/mnt/sdcard/extStorages/UsbDriveB","MayMay.docx") Then
    Msgbox("File exist!","")
    Else
        Msgbox("Not found","")
End If
MyPath = "/mnt/sdcard/extStorages/UsbDriveB/MayMay.docx"
i.Initialize(i.ACTION_VIEW, MyPath)
i.SetType("application/vnd.ms-word")
StartActivity(i)
What am I missing?
Really need to make this work..please help. Thanks for your valuable time.
 
Upvote 0
Try:
B4X:
Expand Collapse Copy
Dim MyPath As String
If File.Exists("/mnt/sdcard/extStorages/UsbDriveB","MayMay.docx") Then
    Msgbox("File exist!","")
    Else
        Msgbox("Not found","")
End If
MyPath = "/mnt/sdcard/extStorages/UsbDriveB/MayMay.docx"
i.Initialize(i.ACTION_VIEW, MyPath)
i.SetType("application/msword")
StartActivity(i)
 
Upvote 0
@JonPM
I tried it but unfortunately did not work. It opened the application (WPS Office) but did not open the MayMay.docx. I have 2 applications installed Polaris and WPS Office and I just select WPS Office. When using Polaris I have this error "Not a supported document type"
Thank you for taking the time to help.
 
Upvote 0
Android work with intents. You need to create an intent with the path to the specified file and send it to the system.
Sorry if I don't really get all this but can you share a code how to do it or what I might be doing bad?
 
Upvote 0
@Erel
Thank you for the time. And my apology for the late reply...been busy with other things.
B4X:
Expand Collapse Copy
Dim in As Intent

in.Initialize(in.ACTION_VIEW, "file://" & File.Combine(File.DirRootExternal, "somefile.doc"))
in.SetType("application/msword")
StartActivity(in)

I was thinking the above code is simple :cool:...so I just edit on the part of file path to point where my actual file is located.
B4X:
Expand Collapse Copy
Dim MyPath As String
If File.Exists("/storage/usb3host/AOFFICEFiles/","FinalProject.docx") Then
    Msgbox("File exist!","")
    MyPath = "/storage/usb3host/AOFFICEFiles/FinalProject.docx"
    i.Initialize(i.ACTION_VIEW, MyPath)
    i.SetType("application/msword")
    StartActivity(i)
    Else
    Msgbox("Not found","")
End If
When executing the code it displays the message box "File exist!" but says "document type not supported".:confused: I'm not sure if this is related to the file path.
I have only Polaris Office installed. My target application is to list all files(docx,ppt,xls and pdf) from my usb storage device in a listview and by selecting the intended file it would open up the application that supports it(e.g Polaris Office).

Again thank you for the time.
 
Last edited:
Upvote 0
Back
Top