Goodmorning everyone.
I have created an application which is up and running. I update it quite often. I am trying to make something happen but there is a problem I stumbled on. The post is long so bare with me.
Case Description:
I have a webview which shows some data from an sqllite db. The data contains multiple html code one of which is some hrefs. I manage those URLs using overrideurl. The URLs are divided in two major categories: Website's URL or PDF's Download Link. I manage the intent with this code:
I use HttpUtils2 to download the file. I use the following code to check for the job done.
Up to this point everything works like a charm. After all the above, I use this code to open the downloaded pdf:
Problem Description:
No matter what folder I use the application returns 2 answers (depending on whether I use "file://" or not in front of the Combine statement). Either it says "No application can perform this action." or it opens the pdf view program I have installed but says that the path is wrong.
Notes:
1. I have tried the app in both Emulator and an HTC HD2 running ICS 4.0.3 I have, the result is the same.
2. I have installed Adobe Reader in HTC and PDF Viewer in Emulator.
3. The file is downloaded successfully, I know that because if I go to the location, there is the appropriate pdf file and if I press it everything works like a charm in both Emulator and HTC.
Any Ideas?
I have created an application which is up and running. I update it quite often. I am trying to make something happen but there is a problem I stumbled on. The post is long so bare with me.
Case Description:
I have a webview which shows some data from an sqllite db. The data contains multiple html code one of which is some hrefs. I manage those URLs using overrideurl. The URLs are divided in two major categories: Website's URL or PDF's Download Link. I manage the intent with this code:
B4X:
Dim p As PhoneIntents
If Url.EndsWith(".pdf") Then
ToastMessageShow("Download Started. Please Wait...",True)
DownloadURL = Url
Dim lcRecords() As String
Dim DNFileNameLeng As Int
lcRecords = Regex.Split("/",DownloadURL)
DNFileNameLeng = lcRecords(lcRecords.Length-1).Length
DownloadFN = lcRecords(lcRecords.Length-1)
If DNFileNameLeng > 10 then
DownloadFN = lcRecords(lcRecords.Length-1).SubString(DNFileNameLeng-10)
end if
Dim Download_job As HttpJob
Download_job.Initialize("Download_job", Me)
Download_job.Download(DownloadURL)
Return True
Else
StartActivity(p.OpenBrowser(Url))
Return True
End If
I use HttpUtils2 to download the file. I use the following code to check for the job done.
B4X:
Sub JobDone (Job As HttpJob)
If Job.Success = True Then
ToastMessageShow("Download Complete.",True)
Dim out As OutputStream
out = File.OpenOutput(File.DirDefaultExternal,DownloadFN,False)
'out = File.OpenOutput("/sdcard/",DownloadFN,False )
File.Copy2(Job.GetInputStream, out)
out.Close
OpenPDF(DownloadFN)
Else
Log("Error: " & Job.ErrorMessage)
ToastMessageShow("Error: " & Job.ErrorMessage, True)
End If
Job.Release
End Sub
Up to this point everything works like a charm. After all the above, I use this code to open the downloaded pdf:
B4X:
Sub OpenPDF(FileName As String)
Dim i As Intent
i.Initialize(i.ACTION_VIEW, File.Combine(File.DirDefaultExternal,FileName))
i.SetComponent("android/com.android.internal.app.ResolverActivity")
i.SetType("application/pdf")
i.WrapAsIntentChooser("Choose PDF Viewer")
Try
StartActivity(i)
Catch
ToastMessageShow("Cannot start file." & CRLF & _
File.Combine(File.DirDefaultExternal,FileName), False)
End Try
End Sub
Problem Description:
No matter what folder I use the application returns 2 answers (depending on whether I use "file://" or not in front of the Combine statement). Either it says "No application can perform this action." or it opens the pdf view program I have installed but says that the path is wrong.
Notes:
1. I have tried the app in both Emulator and an HTC HD2 running ICS 4.0.3 I have, the result is the same.
2. I have installed Adobe Reader in HTC and PDF Viewer in Emulator.
3. The file is downloaded successfully, I know that because if I go to the location, there is the appropriate pdf file and if I press it everything works like a charm in both Emulator and HTC.
Any Ideas?
Last edited: