Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
187 views
in Technique[技术] by (71.8m points)

android - Loading PDFs via PDF.js with API 30

API 30 introduced changes related to file access within a WebView:

/**                                                                                            
 * Enables or disables file access within WebView.                                             
 * Note that this enables or disables file system access only. Assets and resources            
 * are still accessible using file:///android_asset and file:///android_res.                   
 * <p class="note">                                                                            
 * <b>Note:</b> Apps should not open {@code file://} URLs from any external source in          
 * WebView, don't enable this if your app accepts arbitrary URLs from external sources.        
 * It's recommended to always use                                                              
 * <a href="{@docRoot}reference/androidx/webkit/WebViewAssetLoader">                           
 * androidx.webkit.WebViewAssetLoader</a> to access files including assets and resources over  
 * {@code http(s)://} schemes, instead of {@code file://} URLs. To prevent possible security   
 * issues targeting {@link android.os.Build.VERSION_CODES#Q} and earlier, you should explicitly
 * set this value to {@code false}.                                                            
 * <p>                                                                                         
 * The default value is {@code true} for apps targeting                                        
 * {@link android.os.Build.VERSION_CODES#Q} and below, and {@code false} when targeting        
 * {@link android.os.Build.VERSION_CODES#R} and above.                                         
 */                                                                                            
public abstract void setAllowFileAccess(boolean allow);                                        

An application utilizing PDF.js by first downloading a PDF and then displaying it via "file:///android_asset/pdfjs/web/viewer.html?file=${path/to/file}" will no longer work. Forcing setAllowFileAccess to true is possible but discouraged.

WebViewAssetLoader is suggested as an alternative, however it appears to be geared toward use cases focused on loading local files from the /assets directory or /res directory.

Questions:

  1. How can PDF.js be used to load a local PDF file considering the restrictions added in API 30?
  2. Is there a way to use WebViewAssetLoader to load a file saved in the application's local storage?
question from:https://stackoverflow.com/questions/65852455/loading-pdfs-via-pdf-js-with-api-30

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...