cancel
Showing results for 
Search instead for 
Did you mean: 

Opening a Local PDF in Android (Agentry)

0 Kudos

Hi , Is it possible to display a local PDF in the HTML control of Agentry or does the the same local access rules apply as the standard browser. Is there a work around.

Thanks

Rikardt

Accepted Solutions (1)

Accepted Solutions (1)

0 Kudos

Does the standard providing this function to dispaly PDF or is it necessary to implement this fueature ?

mark_pe
Active Contributor
0 Kudos

The built in HTML control should read it. There was an old bug that prevented it from being read but it was fixed in the later version. I have seen production companies use it.

0 Kudos

Hi Mark

I have loaded the new client and error still occurs.

Files on device

Internet on device is turned ON. This of course works if document is online but its not. Its using http://docs.google.com to render.

Turn off Internet. Now you can see what its actually trying to do.

Found the following

How to Guide - Enabling Push Attachments and Factsheets in CRM Sales Manager 2.5.pdf - Page 22

Note:

IOS:The tap onAttachments opens after the push is successful.

Android: Open the Downloads on the device to view attachments

So it seems the user might need to manually open the document from the android device.

We will log a support call.

mark_pe
Active Contributor
0 Kudos

Rikardt,

I reached out to my colleague who worked with a lot of documents attachment. I asked him (emailed him tonight) the question about Android+PDF and pointed him to this thread.  Hopefully he picks up or respond to this thread based on his experience on the field with customers. I want to get from him if there is some special technique they used for other customers who used Android. If I see him tomorrow, I'll quickly ask him.

As a side, I'll see if I can find any issues with Android and PDF. I'll get back to this thread.

0 Kudos

Thanks Mark . I really appreciate the help.

mark_pe
Active Contributor
0 Kudos

I read the design code notes from the bug database for Android.  It is by design.

The HTMLView control uses the google doc capabilities to present the PDF in WebView form due to this is an HTML view control.

So if you turn the website off then it will be not available as a third party viewer to help present it in the HTML control.

So I guess your solution or work around above is gold for now.

You may have 2 options (buttons) to open the file when you have online connection and when offline. You may have a message where your pdf rending when offline is slower than when using the 1st option.

Just an idea on how you can help your customer/product cope.

0 Kudos

Hi Mark , thanks a lot for your research and help. Will post the details on what we end up doing. Thanks!!!

mark_pe
Active Contributor
0 Kudos

Bug number Android-2321 - for tracking purposes.

If it needs to be improved the bug fix listed will need to be revisted.

bill_froelich
Product and Topic Expert
Product and Topic Expert
0 Kudos

I have also tried viewing attached PDF documents on Android without success.  From my research, the Android html webviewer does not support direct rendering of PDFs.  From within other applicatoins, when I try to view PDF files it always prompts me to choose how to open the file using some other view on my device (Polaris Office in my case).

I have also not had any success opening Excel, Word or Powerpoint docs on Android either.  I think the ultimate solution will need to be for the Android client to trigger the OS to prompt for how to open the file under the assumption that the files were configured to be downloaded to an accessible locatoin (like Downloads, DCIM or External Storage).

On the other hand, graphics files (JPG, PNG) and text files open correctly within the Agentry HTML control.

Ali_Chalhoub
Advisor
Advisor
0 Kudos

Hi Bill,

Does this work for you?

Found this online:

Uri file= Uri.parse("file:///android_asset/app.pdf");
  String mimeType =  MimeTypeMap.getSingleton().getMimeTypeFromExtension(MimeTypeMap.getFileExtensionFromUrl(file.toString()));

try{
     Intent i;
     i = new Intent(Intent.ACTION_VIEW);
     i.setDataAndType(file,mimeType);
     startActivity(i);

}catch (ActivityNotFoundException e) {
                    Toast.makeText(this,
                        "No Application Available to fiew this file type",
                        Toast.LENGTH_SHORT).show();
                }

Thx

0 Kudos

Hi Mark

Did some more testing it seems that the online version when the file is on the device itself will not work as its passing the local file path to the DOC API. The API won't have access to the local file system.

mark_pe
Active Contributor
0 Kudos

Rikardt,

We will get our development (Core Agentry - Android team) to take a look at this thread in detail to see if we can get a local urlAction to work offline (currently in progress).

I'll update this thread as soon as I get more information.

mark_pe
Active Contributor
0 Kudos
  • AGS-1110 - For tracking purpose on the statement above
mark_pe
Active Contributor
0 Kudos

Rikardt,

After discussions internally here are the options presented:

In Agentry there is another feature called the "OpenURL" Action.

Example test internally that works using the Open URL Action steps:

Set up a test app and able to open PDF files just fine using the OpenURL action step.  This will work for them as long as they have the required viewers installed on the device and they specify the path to the files correctly in their application.  The OpenURL step lets the URL be defined by rule.  They need to use "file://<absolute path to the file>".  For example, on the internal Android device we have files downloaded to /storage/sdcard0/Download and the URL would be "file:///storage/sdcard0/Download/file.pdf"

You may try this out.

0 Kudos

Hi Mark

I did try this before and I got a Action canceled error from agentry. I haven't tried this on 6.036 yet so will do so now.

0 Kudos

Hi Mark

This only seems to work for http://. file:// errors - application not found. This error occurs on any file local PDF or HTML. I have tested the same file:// path in the browser on the android device and it works and popups up the acrobat pdf viewer option.

I also created a rule a rule that concatenates file:// and the filename and path stored in the file object and that doesn't work either.

When I add a   online PDF url it works and it will ask me in which browser  I would like to open it in once the browser opens I can choose the pdfviewer. So my guess is it only works with http.

Can you confirm that this has been tested by SAP and that it should work? Is there something I am missing?

Update: You get ACTION FAILED - No Error returned on a IPAD

mark_pe
Active Contributor
0 Kudos

Rikardt,

As discussed above, the data I gave you above is tested internally.

The file is located in an SD card (locally).

"file:///storage/sdcard0/Download/file.pdf"

The rule is that your Android device needs a software that can read the PDF.

"This will work for them as long as they have the required viewers installed on the device"

Android test.

0 Kudos

Hi Mark , Good news it works. Just not on my device. I believe I need to upgrade. Thanks for all your help!!!

Update: Got it working on my device too. Seems that something went wrong on my device with all the viewers I had installed.

How I fixed it . Uninstall all viewers and disable standard office viewer. When you now double click on a file it will say there is nothing to open it with. Then install the viewer you want.  It should then open from Agentry

jason_latko
Advisor
Advisor
0 Kudos

Rikardt,

Glad my idea worked for you!  Jon Wilson had e-mailed me directly looking for a solution and I added using "Open URL" as a comment on the open ticket created by Mark Pe.  Mark followed that up and got the Agentry Platform team to verify that this should work on Android with the example they provided for you.  Excellent team-work all around, and a testament to the power of these community forums.

Jason Latko - Senior Product Developer at SAP

Answers (3)

Answers (3)

bill_froelich
Product and Topic Expert
Product and Topic Expert
0 Kudos

Unfortunately the answer didn't work for me on my device (Samsung Galaxy S4).  When I use the OpenURL action step with the file:///path/to/my/file/filename.pdf the screen flashes but doesn't open the pdf for viewing.

My solution was to create a helper application with a custom URI scheme that I can call from Agentry and have it launch the appropriate intent which in turn prompts the user which application to use to open the attachment.

I was able to successfully view PDF, MS Word, Excel, Powerpoint, Text, MP3 (audio), Graphic files (JPG, GIF, PNG) with each prompting what application to use to open the file.

For me I am using essentially the same OpenURL aciton step but with my custom scheme name.  I'll have to writup a blog post so I can attach teh app in case anyone is interested.

--Bill

0 Kudos

Hi Bill. Sounds Great. I would definitely use it.  Thanks!

jason_latko
Advisor
Advisor
0 Kudos

Bill,

Is this something that could be packaged along with the Agentry Android Client?  Sounds really cool.  At the minimum you should share the app and provide examples on how to install and use with Agentry as you suggested.  Good work!

Jason Latko - Senior Product Developer at SAP

agentry_src
Active Contributor
0 Kudos

Yes please write it up.  If you would, put a link in the Agentry landing page http://scn.sap.com/docs/DOC-47882 or send the link to me and I will do it.  Preferably try it yourself to make sure you have that functionality.  Let me know either way.

Thanks, Mike

SAP Rapid Innovation Group - RIG

0 Kudos

Content providers can also be used as the following:

examples (Openurl Action):

PDF:

content://com.adobe.reader.fileprovider/storage/sdcard0/Download/a.pdf?application/pdf

HTML:

content://com.android.htmlfileprovider/storage/sdcard0/Download/index.html?text/html

bill_froelich
Product and Topic Expert
Product and Topic Expert
0 Kudos

I created a blog post with more details that contains  alink to download the .apk if you are interested.

http://scn.sap.com/blogs/goingMobile/2013/11/20/viewing-pdfs-in-agentry-on-android

mark_pe
Active Contributor
0 Kudos

Bill. Thanks.

mark_pe
Active Contributor
0 Kudos

There was some bug fixes in Agentry on 6.0.36 version that improved opening of PDF files as external data files (This fix was released just on November 2013). The reasoning for this is after the file is download and the Agentry client was used to open the file, the client deletes the file. If your version of Agentry is timestamped earlier than November 2013 and the version is higher than 6.0.26.1 then you may be experiencing an issue with External Data files downloaded to the Agentry client where the files were removed when you try opening it or the issue where the directory was modified to add an additional application support directory (AGS-933 or AG-25815 or AG-25805).  These bugs symptoms are when you try opening the PDF file the HTML control cannot open the file.  Good news is that it was confirmed fix in Agentry 6.0.36 version (Released early November 2013). If you are using 6.1.0.X version that was released earlier than November 2013, you may be experiencing this bug until the later 6.1.0.X version gets released. 

Based on the comments above, it works in IPAD. If you have an Agentry version that is at least 6.0.36 and you are using Android and have the issue then the fix in 6.0.36 was not applied in Android yet.  Confirm in this message your Android Agentry client.

0 Kudos

Hi Mark

Thanks for your response. I did take a look at the note and we did have the issue but couldn't find the 6.0.36  download we are on 6.0.32.2 (SM 2.5.1).  I set the file object to never delete so I could check if this is the problem it fixed the issue on IOS and I could get the PDF to display.

On the Android this did not work as it would say the file is not found. I manually located the file on the device so they were not deleted.The UI looked very familiar so I set the device to flight mode and it got a URL not found error and saw that it was actually trying to pass the path of the local pdf to the GOOGLE DOC API as a parameter which would not work anyway as the file local.

It also doens't work if you manually attach a file locally and ask the HTML container to open it.

Can you confirm that a android can open a local pdf offline embedded in the HTML container on your device?

Where can I download 6.0.36? Thank for the help.

jon_wilson01
Employee
Employee
0 Kudos

Hi Rikardt,

The 6.0.36 clients are able to be downloaded from the SAP Software Download Center in the SAP Service Marketplace.  The path is SAP Mobile Solutions -> SAP Mobile Solutions" -> AGENTRY -> AGENTRY 6.0 -> Installation -> Agentry 6.0.36 Clients

Cheers,

Jon

mark_pe
Active Contributor
0 Kudos

See picture..

for IPAD check the appstore..

0 Kudos

Hi Jon

Thanks for the response. Its the path I have looked at before as well as searching as Mark described below. I have gotten a basis consultant and another developer to look for this as well and none are able to see the Agentry link. We are able to see all the other Agentry downloads. I am wondering if this might be a access/rights problem.

0 Kudos

Is this link maybe just available for Internal SAP employees?

0 Kudos

Hi Mark

Below is what I find when Searching for Agentry under downloads there is no Agentry link. Is this a Sap Employee only link?

mark_pe
Active Contributor
0 Kudos

Customers who paid for it may see it.

I see it because I am employee.

0 Kudos

It seems android in the case of Sales Manager does download the PDF's to the local device but cannot open them in the browser as it tries to use the google doc api and passes it the the local file location. Might be a bug. Works fine on a IPAD on and offline so my guess is the google api is not used.

The only way I have gotten pdf's passed from SAP to open on the Android Device offline  is using the pdf.js javascript library.

I did the following to achieve this hope it heps if anyone has the same issue:

1. Encode binary as base64 String do not use encoding currently used by SAP as it adds line breaks so rather use ( org.apache.commons.codec.binary.Base64).

2. Encode Base64 String to  Url Encoding (java.net.URLEncoder)

3. Pass this string  to Agentry  and store as STRING not EXTERNAL DATA.

4. Pass this string to your own created Index page located on device "if offline" based on PDF.js. example of url file:///mnt/sdcard/pdfview/index.html#(encoded string) .

5. Take string encode it back from url encoded to base64 to binary and pass to PDF.js to render.

Example:

    function base64ToUint8Array(base64) {
        var raw = atob(base64); //This is a native function that decodes a base64-encoded string.
        var uint8Array = new Uint8Array(new ArrayBuffer(raw.length));
        for (var i = 0; i < raw.length; i++) {
            uint8Array[i] = raw.charCodeAt(i);
        }

        return uint8Array;
    }

var pdfData = base64ToUint8Array(decodeURIComponent(window.location.hash.substring(1))) ;

// Render PDF
pdf = PDFJS.getDocument(pdfData);

pdf.then(renderPdf);

This method is slow and I am sure uses a lot of memory and would like to use a more standard way of opening pdf's.

Is this a known issue on Android and is there a fix coming ?