1

What I tried:

I am developing an android application. Inside my app, I have to open -> show the microsoft office documents (doc, docx, xls, xlsx, ppt, pptx)content to the user. For this I have tried multiple ways(apachi-poi, docx4j). But I couldn't get it done.

Android - convert doc, docx pages and xls, xlsx sheets to html using apache POI

Android - docx4j build issue

So I have decided to show the documents using third part document SDKs inside my app.

Android - microsoft office viewer in my app

But this was not helped to me. Meanwhile I got some suggestions. By Using phonegap, Fileopener plugin we can open -> show the documents to the user.

What I need:

I have already developed a non-phonegap application. If I do the document viewer using phonegap, is it possible to integrate the phonegap app to my non-phonegap app?

I am new to the phonegap. If possible please give some ideas (or) steps to do that.

Community
  • 1
  • 1
SKK
  • 1,705
  • 3
  • 28
  • 50

2 Answers2

1

in your non-phoneGap application, when user wants to open a document (if you insist to use phoneGap for that) just open a webView and then open your phoneGap application (web pages) in that.

Mohammad Rahchamani
  • 5,002
  • 1
  • 26
  • 36
  • Thanks for the response. Can you tell me, how can I integrate the phonegap with non-phonegap application? – SKK Dec 05 '14 at 12:09
  • a phonegap application is some html/css/javascript files. put that files in your assets folder, and then after opening a `WebView` , tell that to load your `index.html` (phonegap's main file) and now you are done. – Mohammad Rahchamani Dec 05 '14 at 12:18
  • I have seen some folders like CordovaLib/cordova/platform_www/ folders inside my sample phonegap application. Do I need to add these folders also? – SKK Dec 05 '14 at 12:26
  • 1
    all you have to add is your own html/css/javascript files + phonegap libraries like cordova.js, etc – Mohammad Rahchamani Dec 05 '14 at 12:41
  • 2
    Thank you so much Mohammad Rahchamani. This method will not helpful for me. I mean the Fileopener and phonegap. Because I want to show the microsoft docs inside my app. This Fileopener will launch the other intent to show the microsoft documents. – SKK Dec 05 '14 at 12:52
1

The file opener plugin just launch an intent and other app opens the file, not your app, so you don't need phonegap for that, just look into the plugin code and do the same in your android project.

There are a few plugins. https://github.com/markeeftb/FileOpener

private void openFile(String url) throws IOException {
    // Create URI
    Uri uri = Uri.parse(url);
    Intent intent = null;
    // Check what kind of file you are trying to open, by comparing the url with extensions.
    // When the if condition is matched, plugin sets the correct intent (mime) type,
    // so Android knew what application to use to open the file
    if (url.contains(".doc") || url.contains(".docx")) {
        // Word document
        intent = new Intent(Intent.ACTION_VIEW);
        intent.setDataAndType(uri, "application/msword");
    } else if(url.contains(".pdf")) {
        // PDF file
        intent = new Intent(Intent.ACTION_VIEW);
        intent.setDataAndType(uri, "application/pdf");
    } else if(url.contains(".ppt") || url.contains(".pptx")) {
        // Powerpoint file
        intent = new Intent(Intent.ACTION_VIEW);
        intent.setDataAndType(uri, "application/vnd.ms-powerpoint");
    } else if(url.contains(".xls") || url.contains(".xlsx")) {
        // Excel file
        intent = new Intent(Intent.ACTION_VIEW);
        intent.setDataAndType(uri, "application/vnd.ms-excel");
    } else if(url.contains(".rtf")) {
        // RTF file
        intent = new Intent(Intent.ACTION_VIEW);
        intent.setDataAndType(uri, "application/rtf");
    } else if(url.contains(".wav")) {
        // WAV audio file
        intent = new Intent(Intent.ACTION_VIEW);
        intent.setDataAndType(uri, "audio/x-wav");
    } else if(url.contains(".gif")) {
        // GIF file
        intent = new Intent(Intent.ACTION_VIEW);
        intent.setDataAndType(uri, "image/gif");
    } else if(url.contains(".jpg") || url.contains(".jpeg")) {
        // JPG file
        intent = new Intent(Intent.ACTION_VIEW);
        intent.setDataAndType(uri, "image/jpeg");
    } else if(url.contains(".png")) {
        // PNG file
        intent = new Intent(Intent.ACTION_VIEW);
        intent.setDataAndType(uri, "image/png");
    } else if(url.contains(".txt")) {
        // Text file
        intent = new Intent(Intent.ACTION_VIEW);
        intent.setDataAndType(uri, "text/plain");
    } else if(url.contains(".mpg") || url.contains(".mpeg") || url.contains(".mpe") || url.contains(".mp4") || url.contains(".avi")) {
        // Video files
        intent = new Intent(Intent.ACTION_VIEW);
        intent.setDataAndType(uri, "video/*");
    }
    //if you want you can also define the intent type for any other file
    //additionally use else clause below, to manage other unknown extensions
    //in this case, Android will show all applications installed on the device
    //so you can choose which application to use
    else { intent = new Intent(Intent.ACTION_VIEW);
        intent.setDataAndType(uri, "*/*");
    }
    this.cordova.getActivity().startActivity(intent);
}

just change the this.cordova.getActivity() for the way you get the activity on the class where you call the code.

jcesarmobile
  • 51,328
  • 11
  • 132
  • 176
  • Thanks for this helpful answer. Otherwise I will spend some time to implement this. Because I am new to the phonegap :) – SKK Dec 05 '14 at 12:48
  • 1
    I have added an example – jcesarmobile Dec 05 '14 at 12:48
  • Do you have any idea about my requirement(given in the question)? I want to show the office docs inside my app(not to open the other intent). – SKK Dec 06 '14 at 04:26
  • If the files you want to show are on internet, you can use a webview and load the file using a google docs url (http://docs.google.com/gview?embedded=true&url=http://server.com/yourfile.doc). If they are inside the app, the you should keep trying the solutions you mention on your question. – jcesarmobile Dec 06 '14 at 07:17
  • No. I want to show the doc in offline mode. That is the doc must be selected from SDCard by the user. – SKK Dec 06 '14 at 07:41
  • So, keep trying with the sdks you posted, there is no other way – jcesarmobile Dec 07 '14 at 08:51