diff --git a/config.xml b/config.xml
index a89e51c60..49ab9744e 100644
--- a/config.xml
+++ b/config.xml
@@ -117,4 +117,5 @@
+
diff --git a/package-lock.json b/package-lock.json
index c394eda7a..e74f74fee 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -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",
diff --git a/package.json b/package.json
index f8b294a40..bf0690d09 100644
--- a/package.json
+++ b/package.json
@@ -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",
diff --git a/src/core/emulator/emulator.module.ts b/src/core/emulator/emulator.module.ts
index 3bdc51088..93a7fdb5e 100644
--- a/src/core/emulator/emulator.module.ts
+++ b/src/core/emulator/emulator.module.ts
@@ -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],
diff --git a/src/providers/utils/utils.ts b/src/providers/utils/utils.ts
index 73a4b825f..e135f4465 100644
--- a/src/providers/utils/utils.ts
+++ b/src/providers/utils/utils.ts
@@ -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} 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} Promise resolved when opened.
*/
openOnlineFile(url: string): Promise {
- return new Promise((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();
}
/**