Will This Code Open a PDF?

Fixx42

Member
Licensed User
Longtime User
Hello all,

As a newbie android programmer, I am in the somewhat difficult position of attempting to code an android app without owning android device, and would thus very much appreciate your help with what I fear may be a silly question.

If I put the PDF file GoldLineFeb2012.pdf into the "files" tab of my program in Basic4Android, will the following code open that PDF (in an external viewer, I assume)? When I attempt to run it in the emulator, it tells me "no applications can perform this action". I'm not sure if that's because the emulator lacks a PDF viewer, or because of a problem with my code. And without an android device of my own I am unable to test it first-hand.

Dim intent1 As Intent
intent1.Initialize(intent1.ACTION_VIEW, "GoldLineFeb2012.pdf")
intent1.SetType("application/pdf")
intent1.WrapAsIntentChooser("Choose PDF Viewer")
StartActivity(intent1)

Thanks a lot for the help!

Steve
 
give this a try,
it worked for me :)

Code: Copy
Intent1.Initialize(intent1.ACTION_VIEW, "file://" & File.Combine(directory & "/", Value))   intent1.SetComponent("android/com.android.internal.app.ResolverActivity")
intent1.SetType("application/pdf")
StartActivity(intent1)
 
Upvote 0
It is the first time for me. Where should I put the code intent ? I've a pdf files on my sdcard, thanks!
 
Upvote 0
You can place that code on a Button for example:
Code: Copy
Sub Button1_Click

    Dim Intent1 As Intent

    Intent1.Initialize(intent1.ACTION_VIEW, "file://" & File.Combine(directory & "/", Value))
    intent1.SetComponent("android/com.android.internal.app.ResolverActivity")
    intent1.SetType("application/pdf")

    StartActivity(intent1)

End Sub
 
Upvote 0
It works in my device, but it opens the pdf with google docs in the browser and not with Adobe Reader or RepliGo Reader even if I set them to default application.
It doesn't work in the emulator even if I install Adobe Reader ("No application can perform this action").
 
Upvote 0
You can place that code on a Button for example:
Code: Copy
Sub Button1_Click

    Dim Intent1 As Intent

    Intent1.Initialize(intent1.ACTION_VIEW, "file://" & File.Combine(directory & "/", Value))
    intent1.SetComponent("android/com.android.internal.app.ResolverActivity")
    intent1.SetType("application/pdf")

    StartActivity(intent1)

End Sub
This works in my app also! THX !!!
 
Upvote 0
The AAA.pdf file is in my app files folder .
Only your app is allowed to read this folder. To let another app open it you need to copy the file to another dir.
 
Upvote 0
Back
Top