0

I am trying to display multiple file formats on both android and iOS devices, this includes PDF, Excel, Word, Power Point, and .txt files.

I can get all of these different file formats to display in iOS devices using data uri

for instance if I wanted to display a pdf file, I'd call the following:

window.open('data:application/pdf;base64,' + base64pdfdatastring, '_blank');

however none of the file formats worked except for text, which is formatted in exactly the same way:

window.open('data:text/plain;base64,' + base64textdatastring, '_blank');

These files could potentially contain sensitive information, so google doc is not a valid solution.

How do I get android to display data uri correctly?

Thanks

George
  • 1,552
  • 1
  • 17
  • 26

1 Answers1

0

Create an ACTION_VIEW intent.

    Intent intent = new Intent(android.content.Intent.ACTION_VIEW);
        Uri data = Uri.parse(path);
        intent.setDataAndType(data, YOUR_MIME_TYPE); 
        startActivity(intent);

Also, you might want to use Package Manager to make sure something can handle the intent before launching it

PackageManager packageManager = activity.getPackageManager();
        List<ResolveInfo> list = packageManager.queryIntentActivities(intent,
                PackageManager.MATCH_DEFAULT_ONLY);
        if (list.size() > 0) 
                                      //Do Something

http://developer.android.com/reference/android/content/Intent.html

Submersed
  • 8,810
  • 2
  • 30
  • 38
  • I am using phonegap/cordova, I won't have access to this from javascript, unless this is meant to go into a phonegap/cordova plugin? – George Dec 17 '13 at 13:46
  • Ah gotcha, this wasn't mentioned originally, so I just assumed you were using the SDK. I'm not familiar with phonegap/cordova, but I think this trend asked as similar question and has an accepted answer http://stackoverflow.com/questions/10685220/android-and-phonegap-intent-to-launch-an-other-application – Submersed Dec 17 '13 at 14:57
  • the mentioned childbrowser plugin is deprecated and all functionality has been moved to the inappbrowser plugin. if you look at line 142 of [this file](https://github.com/apache/cordova-plugin-inappbrowser/blob/master/src/android/InAppBrowser.java), as well as the [InAppBrowser documentation](https://github.com/apache/cordova-plugin-inappbrowser/blob/master/docs/window.open.md) you will be able to see that it does the same thing. However if I were to call the function with the argument of '_system' instead of '_blank' nothing happens. – George Dec 17 '13 at 19:05