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-plugin-local-notifications-mm" />
|
||||||
<plugin name="cordova-sqlite-storage" spec="2.0.4" />
|
<plugin name="cordova-sqlite-storage" spec="2.0.4" />
|
||||||
<plugin name="cordova-plugin-file-opener2" spec="~2.0.19" />
|
<plugin name="cordova-plugin-file-opener2" spec="~2.0.19" />
|
||||||
|
<plugin name="com-darryncampbell-cordova-plugin-intent" spec="~1.0.2" />
|
||||||
</widget>
|
</widget>
|
||||||
|
|
|
@ -210,6 +210,11 @@
|
||||||
"resolved": "https://registry.npmjs.org/@ionic-native/status-bar/-/status-bar-4.3.0.tgz",
|
"resolved": "https://registry.npmjs.org/@ionic-native/status-bar/-/status-bar-4.3.0.tgz",
|
||||||
"integrity": "sha512-gjS0U2uT6XYshysvzNu98Pf6b5SZ7SGSYkZW1mft19geFn6/MKunX1CJkjpXmiTn14nAD1+FBxF43Oi2OfoM4g=="
|
"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": {
|
"@ionic-native/zip": {
|
||||||
"version": "4.5.2",
|
"version": "4.5.2",
|
||||||
"resolved": "https://registry.npmjs.org/@ionic-native/zip/-/zip-4.5.2.tgz",
|
"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/splash-screen": "4.3.0",
|
||||||
"@ionic-native/sqlite": "^4.3.2",
|
"@ionic-native/sqlite": "^4.3.2",
|
||||||
"@ionic-native/status-bar": "4.3.0",
|
"@ionic-native/status-bar": "4.3.0",
|
||||||
|
"@ionic-native/web-intent": "^4.7.0",
|
||||||
"@ionic-native/zip": "^4.3.3",
|
"@ionic-native/zip": "^4.3.3",
|
||||||
"@ngx-translate/core": "^8.0.0",
|
"@ngx-translate/core": "^8.0.0",
|
||||||
"@ngx-translate/http-loader": "^2.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 { SplashScreen } from '@ionic-native/splash-screen';
|
||||||
import { StatusBar } from '@ionic-native/status-bar';
|
import { StatusBar } from '@ionic-native/status-bar';
|
||||||
import { SQLite } from '@ionic-native/sqlite';
|
import { SQLite } from '@ionic-native/sqlite';
|
||||||
|
import { WebIntent } from '@ionic-native/web-intent';
|
||||||
import { Zip } from '@ionic-native/zip';
|
import { Zip } from '@ionic-native/zip';
|
||||||
|
|
||||||
// Services that Mock Ionic Native in browser an desktop.
|
// Services that Mock Ionic Native in browser an desktop.
|
||||||
|
@ -190,6 +191,7 @@ export const IONIC_NATIVE_PROVIDERS = [
|
||||||
SplashScreen,
|
SplashScreen,
|
||||||
StatusBar,
|
StatusBar,
|
||||||
SQLite,
|
SQLite,
|
||||||
|
WebIntent,
|
||||||
{
|
{
|
||||||
provide: Zip,
|
provide: Zip,
|
||||||
deps: [CoreAppProvider, File, CoreTextUtilsProvider],
|
deps: [CoreAppProvider, File, CoreTextUtilsProvider],
|
||||||
|
|
|
@ -17,6 +17,7 @@ import { Platform } from 'ionic-angular';
|
||||||
import { InAppBrowser, InAppBrowserObject } from '@ionic-native/in-app-browser';
|
import { InAppBrowser, InAppBrowserObject } from '@ionic-native/in-app-browser';
|
||||||
import { Clipboard } from '@ionic-native/clipboard';
|
import { Clipboard } from '@ionic-native/clipboard';
|
||||||
import { FileOpener } from '@ionic-native/file-opener';
|
import { FileOpener } from '@ionic-native/file-opener';
|
||||||
|
import { WebIntent } from '@ionic-native/web-intent';
|
||||||
import { CoreAppProvider } from '../app';
|
import { CoreAppProvider } from '../app';
|
||||||
import { CoreDomUtilsProvider } from './dom';
|
import { CoreDomUtilsProvider } from './dom';
|
||||||
import { CoreMimetypeUtilsProvider } from './mimetype';
|
import { CoreMimetypeUtilsProvider } from './mimetype';
|
||||||
|
@ -62,7 +63,7 @@ export class CoreUtilsProvider {
|
||||||
constructor(private iab: InAppBrowser, private appProvider: CoreAppProvider, private clipboard: Clipboard,
|
constructor(private iab: InAppBrowser, private appProvider: CoreAppProvider, private clipboard: Clipboard,
|
||||||
private domUtils: CoreDomUtilsProvider, logger: CoreLoggerProvider, private translate: TranslateService,
|
private domUtils: CoreDomUtilsProvider, logger: CoreLoggerProvider, private translate: TranslateService,
|
||||||
private platform: Platform, private langProvider: CoreLangProvider, private eventsProvider: CoreEventsProvider,
|
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');
|
this.logger = logger.getInstance('CoreUtilsProvider');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -680,10 +681,6 @@ export class CoreUtilsProvider {
|
||||||
/**
|
/**
|
||||||
* Open a file using platform specific method.
|
* 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.
|
* @param {string} path The local path of the file to be open.
|
||||||
* @return {Promise<any>} Promise resolved when done.
|
* @return {Promise<any>} Promise resolved when done.
|
||||||
*/
|
*/
|
||||||
|
@ -778,19 +775,39 @@ export class CoreUtilsProvider {
|
||||||
* Open an online file using platform specific method.
|
* Open an online file using platform specific method.
|
||||||
* Specially useful for audio and video since they can be streamed.
|
* 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.
|
* @param {string} url The URL of the file.
|
||||||
* @return {Promise<void>} Promise resolved when opened.
|
* @return {Promise<void>} Promise resolved when opened.
|
||||||
*/
|
*/
|
||||||
openOnlineFile(url: string): Promise<void> {
|
openOnlineFile(url: string): Promise<void> {
|
||||||
return new Promise<void>((resolve, reject): void => {
|
if (this.platform.is('android')) {
|
||||||
// @todo
|
// In Android we need the mimetype to open it.
|
||||||
reject('TODO');
|
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