2014-12-05 60 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

相關問題