No application

akaliptos69

Member
Licensed User
Longtime User
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:

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:

akaliptos69

Member
Licensed User
Longtime User
Try to comment out or remove this line:
B4X:
i.WrapAsIntentChooser("Choose PDF Viewer")
Best regards.

Hi Klaus, thank you for the response.

I did comment the line but the outcome is still the same.

If I don't use "file://" in front of the File.Combine Statement the app returns "No applications can perform this action".
If I use it, it seems to try to open, but it says wrong folder, even though I find it in the correct place.
 
Upvote 0

akaliptos69

Member
Licensed User
Longtime User
Unfortunately Klaus no change on the outcome. I used "file://" for the path and the DirRootExternal and the Viewer still says "invalid path", eventhough each time I delete the file and I downloaded again. The new pdf file goes everytime in the same place as the previous and if I go from the file explorer I have the pdf opens ASAP.

Any other useful ideas?

Update:

[SOLVED]

All the steps up to the moment worked on the way to the solution. Thank you Klaus. There were 2 problems, the Folder was one and the name from my routine was altering the name of the pdf (due to the url's filename). I changed it to smthing universal (like "myPDF.pdf") and it worked.

Thank you again Klaus.
 
Last edited:
Upvote 0

akaliptos69

Member
Licensed User
Longtime User
To show the differences I post the code again:

Code 1 changed to:
B4X:
        Dim p As PhoneIntents
If Url.EndsWith(".pdf") Then
                ToastMessageShow("Download Started. Please Wait...",True)
                DownloadURL = Url
                DownloadFN = "MyDocumentPDF.pdf"
                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
Code 2 changed to:
B4X:
Sub JobDone (Job As HttpJob)
    If Job.Success = True Then
        ToastMessageShow("Download Complete.",True)
        Dim out As OutputStream
        out = File.OpenOutput(File.DirRootExternal,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
And Finally Code 3 changed to:
B4X:
Sub OpenPDF(FileName As String)
    Dim i As Intent
    i.Initialize(i.ACTION_VIEW, "file://" & File.Combine(File.DirRootExternal,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://" & File.Combine(File.DirRootExternal,FileName), False)
    End Try
End Sub

Now the app downloads the pdf and opens the pdf with a pdf viewer (if there is only one) or displays a Dialog Box that asks the user to choose from a list of available pdf viewers installed at the device.
 
Upvote 0
Top