Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-25277] get the exact PDF url from Titanium WebView API

GitHub Issuen/a
TypeStory
PriorityHigh
StatusClosed
ResolutionFixed
Resolution Date2018-10-24T00:40:37.000+0000
Affected Version/sn/a
Fix Version/sRelease 7.5.0
ComponentsAndroid
Labelsn/a
ReporterVictor Vazquez Montero
AssigneeGary Mathews
Created2017-09-13T17:42:08.000+0000
Updated2018-10-24T22:03:13.000+0000

Description

description

Costumer is attempting to load a pdf for android using intents with webview. in the mobile app they are using webview control for displaying the remote web site by binding a URL. The web pages in the web site contains few pdf links. On click of normal hyperlinks, respective web page is being shown in the web view. Whereas, on tapping a pdf links, a blank window is getting opened in Android devices. In iOS it’s working fine and a PDF is showing. Per Jira WebView cannot disply PDF documents on Android. So they are using intents as a workaround to open the PDF link. The issue is that on click of the pdf link in the web view, they are unable to get the exact PDF url with any of Titanium WebView API methods or events The customer was able to do it natively and open the PDF's with intents.

Request

The customer wants to know how to get the exact PDF link using the webview API or if there is a workaround they could use.

additional information

attached are two apps. One is a titanium app and one is an android native application. [titanium app](https://axwaysoftware-my.sharepoint.com/personal/vvazquezmontero_axway_com/_layouts/15/guestaccess.aspx?guestaccesstoken=rsxSxfm51VH5t8MRm7YpDX1bHDfJfDfaycmtpKrlAEE%3d&docid=2_11a957eab95234b6ab84003e12f7b0b41&rev=1)

Attachments

FileDateSize
app.js2017-10-25T21:58:15.000+0000826
app (1).js2017-10-03T20:42:04.000+0000826
MyApplication_Android.zip2017-09-13T17:39:42.000+0000947392

Comments

  1. Gary Mathews 2017-09-20

    master: https://github.com/appcelerator/titanium_mobile/pull/9459
  2. Victor Vazquez Montero 2017-09-20

    hello [~gmathews] is there any workaround we can share with the customer at the moment there is a delivery they are trying to meet?
  3. Gary Mathews 2017-09-20

    [~vvazquezmontero] A workaround would be to use the blacklisturl event to listen for PDF files.
       var window = Ti.UI.createWindow(),
           webView = Ti.UI.createWebView({
       	    url: 'https://india.gov.in/website-ministry-commerce-and-industry',
           });
       
       webView.onCreateWindow = function(e) {
           var newWebView = Ti.UI.createWebView({
                   blacklistedURLs: ['.pdf']
               }),
               newWin = Ti.UI.createWindow();
           newWebView.addEventListener('blacklisturl', function(e) {
               newWin.close();
               alert('PDF: ' + e.url);
               // create intent here
           });
           newWin.add(newWebView);
           newWin.open();
           return newWebView;
       };
       
       window.add(webView);
       window.open();
       
  4. Victor Vazquez Montero 2017-09-20

    [~gmathews] Thank you. I will share with customer and update the ticket.
  5. Victor Vazquez Montero 2017-10-03

    [~gmathews] They are still not able to see the PDF with the current work arround

    steps to reproduce :

    1. copy and replace the content of app.js with the attached app.js file content. 2. Run the application in android device. 3. click on “Routine Vaccines” link. 4. Try to open any PDF links in that page. Note: we are using 6.1.2.GA Ti SDK [^app (1).js]
  6. Victor Vazquez Montero 2017-10-03

    Will this fix be included in SDK 6.3.0?
  7. Gary Mathews 2017-10-05

    [~vvazquezmontero] Try this?
       var window = Ti.UI.createWindow(),
           webView = Ti.UI.createWebView({
               url : 'https://india.gov.in/website-ministry-commerce-and-industry'
           }),
           mainActivity = Ti.Android.currentActivity;
       
       webView.onCreateWindow = function(e) {
           var newWebView = Ti.UI.createWebView({
               blacklistedURLs: ['.pdf']
           }),
           newWin = Ti.UI.createWindow();
       
           newWebView.addEventListener('blacklisturl', function(e) {
               newWin.close();
               mainActivity.startActivity(Ti.Android.createIntent({
                   action : Ti.Android.ACTION_VIEW,
                   type : 'application/pdf',
                   data : e.url
               }));
           });
       
           newWin.add(newWebView);
           newWin.open();
       
           return newWebView;
       };
       
       window.add(webView);
       window.open();
       
  8. Victor Vazquez Montero 2017-10-25

    [~gmathews] I just wanted to know if this was still going to be included in SDK 6.3.0 and if we had a new date for its release
  9. Victor Vazquez Montero 2017-10-25

    [~gmathews] The second workaround didn't work for the customer either.
  10. Gary Mathews 2017-10-25

    [~vvazquezmontero] Could you provide details regarding what happens when using the workaround?
  11. Victor Vazquez Montero 2017-10-25

    With new workaround they are unable to load links. Specifically with this URL URL : "http://wwwnc.cdc.gov/travel/destinations/traveler/children.chronic.cruise_ship.extended_student.immune_compromised.pregnant.mission_disaster.vfr/india?s_cid=ncezid-dgmq-travel-leftnav-traveler" with previous work around they are able to access PDF links but there are some scenarios where some links open in another tab which contains PDF links in such cases they are not able to open PDF pages. Note : Please use the given url to reproduce the issue. steps to reproduce the scenario 1. copy and replace the content of app.js with the attached app.js file content. 2. Run the application in android device. 3. click on “Routine Vaccines” link. 4. Try to open any PDF links in that page. [^app.js] Using 6.1.2.GA Ti SDK
  12. Gary Mathews 2017-10-31

    [~vvazquezmontero] This should work:
        var window = Ti.UI.createWindow(),
            webView = Ti.UI.createWebView({
                url : 'http://wwwnc.cdc.gov/travel/destinations/traveler/children.chronic.cruise_ship.extended_student.immune_compromised.pregnant.mission_disaster.vfr/india?s_cid=ncezid-dgmq-travel-leftnav-traveler'
            }),
            mainActivity = Ti.Android.currentActivity;
         
        webView.onCreateWindow = function(e) {
            var newWebView = Ti.UI.createWebView({
                blacklistedURLs: ['.pdf']
            }),
            newWin = Ti.UI.createWindow();
        
            newWebView.onCreateWindow = webView.onCreateWindow;
         
            newWebView.addEventListener('blacklisturl', function(e) {
                newWin.close();
                mainActivity.startActivity(Ti.Android.createIntent({
                    action : Ti.Android.ACTION_VIEW,
                    type : 'application/pdf',
                    data : e.url
                }));
            });
         
            newWin.add(newWebView);
            newWin.open();
         
            return newWebView;
        };
         
        window.add(webView);
        window.open();
        
  13. Gary Mathews 2018-02-15

    7_1_X: https://github.com/appcelerator/titanium_mobile/pull/9828
  14. Eric Merriman 2018-03-14

    [~hknoechel] [~amukherjee] [~kiguchi] We need a parity ticket for iOS and Win
  15. Gary Mathews 2018-03-14

    [~hknoechel] It's not an event it's a callback like onload onerror onsendstream etc... -we could make it an event, which would probably be better. Maybe link ?- Update: Just rejogged my memory and realised we can't make this an event. This must be a callback.
  16. Lokesh Choudhary 2018-05-16

    FR Passed. Waiting for CR to pass.
  17. Christopher Williams 2018-05-23

    Bumping to 7.4.0 to coordinate iOS and Windows implementations: - TIMOB-26063 - TIMOB-25868
  18. Lokesh Choudhary 2018-10-24

    PR Merged.
  19. Keerthi Mahalingam 2018-10-24

    Verified the fix on 7.5.0.v20181024102947.Works fine.Closing
          Name                        = Mac OS X
          Version                     = 10.13.6
          Architecture                = 64bit
          # CPUs                      = 8
          Memory                      = 17179869184
        Node.js
          Node.js Version             = 8.12.0
          npm Version                 = 6.4.1
        Titanium CLI
          CLI Version                 = 5.1.1
        Titanium SDK
          SDK Version                 = 7.5.0.v20181024102947
        Studio Version               =5.1.2.201810080801
        Device                          =Samsung s5 android 6
        EMulator                      =pixel android 9
        

JSON Source