Android Question open file pdf in folder DirAssets

Discussion in 'Android Questions' started by Roberto P., Jul 1, 2015.

  1. Roberto P.

    Roberto P. Well-Known Member Licensed User

    I can not open a pdf file in the folder File.DirAssets & "/products/product.pdf, there is an error or you can not open a file in that folder?

    Code:
    Dim In As Intent
           
       
                
    In.Initialize(In.ACTION_VIEW, "file://" & aFile)
                
    In.SetType("application/pdf")
                
    In.SetComponent("android/com.android.internal.app.ResolverActivity")
               
                
    StartActivity(In)
     
  2. walterf25

    walterf25 Well-Known Member Licensed User

    I don't think you can open a file from the File.DirAssets folder, you may want to copy the file to either the internal folder or your package name folder.

    Cheers,
    Walter
     
    NJDude likes this.
  3. NJDude

    NJDude Expert Licensed User

    That's correct.
     
  4. Erel

    Erel Administrator Staff Member Licensed User

    It must be copied to the "external storage" (File.DirRootExternal or DirDefaultExternal). Other apps cannot access internal folders or the assets folder.
     
  5. Roberto P.

    Roberto P. Well-Known Member Licensed User

    copying the files in other directories can read the pdf file. I do not understand why can read images, html files but not read pdf file ?!
    thanks
     
  6. DonManfred

    DonManfred Expert Licensed User

    That´s the point. YOU (your app) can read the files from your assets. No matter what type of files.

    But with the intent you start ANOTHER app which should show the file. This app do need access to your Assets or Internal files to read the file but it hasnt this permission.
    So; if you relay on an external app the files should be copied to a place where the external app has access to this file. No matter if it is an Image, Textfile, PDF or whatever.
     
  7. Roberto P.

    Roberto P. Well-Known Member Licensed User

    thanks DonManfred
    clear.
    So if I wanted to open the pdf file without an intent I would have no problems? As I read the html file with File object.
     
  8. DonManfred

    DonManfred Expert Licensed User

    YOUR app must read and show the pdf then.
     
  9. Roberto P.

    Roberto P. Well-Known Member Licensed User

    clear. I did not know. thanks

    I prefer to open the pdf file with Intent because the available objects do not seem very efficient.
     
  10. DonManfred

    DonManfred Expert Licensed User

    Copy the file to external dir before using the intent then :)
     
  11. Roberto P.

    Roberto P. Well-Known Member Licensed User

    I did just that and it works
    thanks
     
Loading...