2014-12-05 63 views
1

我试了一下整合:Android的 - 是否有可能PhoneGap的应用程序与非PhoneGap的应用

我开发一个Android应用程序。在我的应用程序内部,我必须打开 - >向用户显示Microsoft Office文档(doc,docx,xl​​s,xlsx,ppt,pptx)内容。为此,我尝试了多种方式(apachi-poi,docx4j)。但我无法完成。

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

Android - docx4j build issue

所以我决定显示了使用我的应用程序内的第三部分文档的SDK文件。

Android - microsoft office viewer in my app

但是,这并没有帮助我。同时我有一些建议。通过使用phonegap,Fileopener插件,我们可以打开 - >向用户显示文档。

我需要什么:

我已经开发了一个非PhoneGap的应用程序。如果我使用phonegap来完成文档查看器,是否可以将phonegap应用程序集成到我的非phonegap应用程序中?

我是新来的phonegap。如果可能的话,请给出一些想法(或)步骤来做到这一点。

在您的非PhoneGap的应用

回答

1

,当用户想打开一个文件(如果你坚持使用PhoneGap的为)刚刚打开一个webView然后打开你的PhoneGap应用程序(网页)。

+0

感谢您的回复。你能告诉我,如何将phonegap与非phonegap应用程序集成? – SKK 2014-12-05 12:09:58

+0

phonegap应用程序是一些html/css/javascript文件。把这些文件放在资产文件夹中,然后打开一个'WebView'后,告诉你要加载你的'index.html'(phonegap的主文件),现在你已经完成了。 – 2014-12-05 12:18:36

+0

我在示例phonegap应用程序中看到了一些文件夹,如CordovaLib/cordova/platform_www /文件夹。我是否也需要添加这些文件夹? – SKK 2014-12-05 12:26:21

1

文件首战插件刚刚推出的意图和其他应用程序打开文件,而不是你的应用程序,所以你不需要为PhoneGap的,只是看到插件代码,做同样的在你的Android项目。

有几个插件。 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); 
} 

只是改变this.cordova.getActivity()你得到你在哪里调用代码的类活动的方式。

+0

感谢这个有用的答案。否则,我会花一些时间来实现这一点。因为我是新来的PhoneGap的:) – SKK 2014-12-05 12:48:05

+1

我添加了一个例子 – jcesarmobile 2014-12-05 12:48:53

+0

你对我的要求(在这个问题给出的)任何想法?我想在我的应用程序中显示Office文档(不打开其他意图)。 – SKK 2014-12-06 04:26:57

相关问题