Android - Is it possible to integrate phonegap app with non-phonegap app

663 Views Asked by At

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.

2

There are 2 best solutions below

5
On BEST ANSWER

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.

6
On

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.