MOBILE-2403 core: Install webintent and implement openOnlineFile
parent
35d854f93e
commit
43be0b3d0a
|
@ -117,4 +117,5 @@
|
|||
<plugin name="cordova-plugin-local-notifications-mm" />
|
||||
<plugin name="cordova-sqlite-storage" spec="2.0.4" />
|
||||
<plugin name="cordova-plugin-file-opener2" spec="~2.0.19" />
|
||||
<plugin name="com-darryncampbell-cordova-plugin-intent" spec="~1.0.2" />
|
||||
</widget>
|
||||
|
|
|
@ -210,6 +210,11 @@
|
|||
"resolved": "https://registry.npmjs.org/@ionic-native/status-bar/-/status-bar-4.3.0.tgz",
|
||||
"integrity": "sha512-gjS0U2uT6XYshysvzNu98Pf6b5SZ7SGSYkZW1mft19geFn6/MKunX1CJkjpXmiTn14nAD1+FBxF43Oi2OfoM4g=="
|
||||
},
|
||||
"@ionic-native/web-intent": {
|
||||
"version": "4.7.0",
|
||||
"resolved": "https://registry.npmjs.org/@ionic-native/web-intent/-/web-intent-4.7.0.tgz",
|
||||
"integrity": "sha512-G8fcZA7W6gp1GO4HmcpQm9G8QfJiLsl6SYG5OmeYaqn8au6Ggif7Aqv2RWX7o/17BEYRnyCXh5MYMfJFbOWLQw=="
|
||||
},
|
||||
"@ionic-native/zip": {
|
||||
"version": "4.5.2",
|
||||
"resolved": "https://registry.npmjs.org/@ionic-native/zip/-/zip-4.5.2.tgz",
|
||||
|
|
|
@ -57,6 +57,7 @@
|
|||
"@ionic-native/splash-screen": "4.3.0",
|
||||
"@ionic-native/sqlite": "^4.3.2",
|
||||
"@ionic-native/status-bar": "4.3.0",
|
||||
"@ionic-native/web-intent": "^4.7.0",
|
||||
"@ionic-native/zip": "^4.3.3",
|
||||
"@ngx-translate/core": "^8.0.0",
|
||||
"@ngx-translate/http-loader": "^2.0.0",
|
||||
|
|
|
@ -33,6 +33,7 @@ import { Push } from '@ionic-native/push';
|
|||
import { SplashScreen } from '@ionic-native/splash-screen';
|
||||
import { StatusBar } from '@ionic-native/status-bar';
|
||||
import { SQLite } from '@ionic-native/sqlite';
|
||||
import { WebIntent } from '@ionic-native/web-intent';
|
||||
import { Zip } from '@ionic-native/zip';
|
||||
|
||||
// Services that Mock Ionic Native in browser an desktop.
|
||||
|
@ -190,6 +191,7 @@ export const IONIC_NATIVE_PROVIDERS = [
|
|||
SplashScreen,
|
||||
StatusBar,
|
||||
SQLite,
|
||||
WebIntent,
|
||||
{
|
||||
provide: Zip,
|
||||
deps: [CoreAppProvider, File, CoreTextUtilsProvider],
|
||||
|
|
|
@ -17,6 +17,7 @@ import { Platform } from 'ionic-angular';
|
|||
import { InAppBrowser, InAppBrowserObject } from '@ionic-native/in-app-browser';
|
||||
import { Clipboard } from '@ionic-native/clipboard';
|
||||
import { FileOpener } from '@ionic-native/file-opener';
|
||||
import { WebIntent } from '@ionic-native/web-intent';
|
||||
import { CoreAppProvider } from '../app';
|
||||
import { CoreDomUtilsProvider } from './dom';
|
||||
import { CoreMimetypeUtilsProvider } from './mimetype';
|
||||
|
@ -62,7 +63,7 @@ export class CoreUtilsProvider {
|
|||
constructor(private iab: InAppBrowser, private appProvider: CoreAppProvider, private clipboard: Clipboard,
|
||||
private domUtils: CoreDomUtilsProvider, logger: CoreLoggerProvider, private translate: TranslateService,
|
||||
private platform: Platform, private langProvider: CoreLangProvider, private eventsProvider: CoreEventsProvider,
|
||||
private fileOpener: FileOpener, private mimetypeUtils: CoreMimetypeUtilsProvider) {
|
||||
private fileOpener: FileOpener, private mimetypeUtils: CoreMimetypeUtilsProvider, private webIntent: WebIntent) {
|
||||
this.logger = logger.getInstance('CoreUtilsProvider');
|
||||
}
|
||||
|
||||
|
@ -680,10 +681,6 @@ export class CoreUtilsProvider {
|
|||
/**
|
||||
* Open a file using platform specific method.
|
||||
*
|
||||
* node-webkit: Using the default application configured.
|
||||
* Android: Using the WebIntent plugin.
|
||||
* iOs: Using handleDocumentWithURL.
|
||||
*
|
||||
* @param {string} path The local path of the file to be open.
|
||||
* @return {Promise<any>} Promise resolved when done.
|
||||
*/
|
||||
|
@ -778,19 +775,39 @@ export class CoreUtilsProvider {
|
|||
* Open an online file using platform specific method.
|
||||
* Specially useful for audio and video since they can be streamed.
|
||||
*
|
||||
* node-webkit: Using the default application configured.
|
||||
* Android: Using the WebIntent plugin.
|
||||
* iOS: Using the window.open method (InAppBrowser)
|
||||
* We don't use iOS quickview framework because it doesn't support streaming.
|
||||
*
|
||||
* @param {string} url The URL of the file.
|
||||
* @return {Promise<void>} Promise resolved when opened.
|
||||
*/
|
||||
openOnlineFile(url: string): Promise<void> {
|
||||
return new Promise<void>((resolve, reject): void => {
|
||||
// @todo
|
||||
reject('TODO');
|
||||
});
|
||||
if (this.platform.is('android')) {
|
||||
// In Android we need the mimetype to open it.
|
||||
return this.mimetypeUtils.getMimeTypeFromUrl(url).catch(() => {
|
||||
// Error getting mimetype, return undefined.
|
||||
}).then((mimetype) => {
|
||||
if (!mimetype) {
|
||||
// Couldn't retrieve mimetype. Return error.
|
||||
return Promise.reject(this.translate.instant('core.erroropenfilenoextension'));
|
||||
}
|
||||
|
||||
const options = {
|
||||
action: this.webIntent.ACTION_VIEW,
|
||||
url: url,
|
||||
type: mimetype
|
||||
};
|
||||
|
||||
return this.webIntent.startActivity(options).catch((error) => {
|
||||
this.logger.error('Error opening online file ' + url + ' with mimetype ' + mimetype);
|
||||
this.logger.error('Error: ', JSON.stringify(error));
|
||||
|
||||
return Promise.reject(this.translate.instant('core.erroropenfilenoapp'));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// In the rest of platforms we need to open them in InAppBrowser.
|
||||
window.open(url, '_blank');
|
||||
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue