Open A File Within The App Folder With Fileopener Ionic2
this is my code : import { Component } from '@angular/core'; import { NavController } from 'ionic-angular'; import { FileOpener } from 'ionic-native'; @Component({ selector: 'pa
Solution 1:
Well I did it by making the app get downloaded from a server to a local folder I created in the phone and install it immediately/automatically,
Here is the code in case someone else needed it one day :
import { Component } from'@angular/core';
import { Platform, LoadingController } from'ionic-angular';
import { StatusBar, Splashscreen } from'ionic-native';
import { FileOpener } from'ionic-native';
import { File } from'ionic-native';
import { Transfer } from'ionic-native';
import { HomePage } from'../pages/home/home';
declare varcordova: any;
@Component({
template: `<ion-nav [root]="rootPage"></ion-nav>`
})
exportclassMyApp {
rootPage = HomePage;
constructor(platform: Platform, public loadingCtrl: LoadingController) {
let me = this;
platform.ready().then(() => {
let loading = me.loadingCtrl.create({
content: 'Preparing The App ...'
});
loading.present();
File.createDir(cordova.file.externalDataDirectory, "appFolder", true).then(function(link){
const fileTransfer = newTransfer();
let url = 'http://yourserverhere.com/app.apk';
fileTransfer.download(url, cordova.file.externalDataDirectory +"appFolder/app.apk").then((entry) => {
loading.dismiss();
FileOpener.open(entry.toURL(), "application/vnd.android.package-archive").then(
function(){
console.log("success");
},function(err){
console.log("status : "+err.status);
console.log("error : "+err.message);
});
}, (error) => {
console.log(error);
});
},function(error){
console.log(error);
});
StatusBar.styleDefault();
Splashscreen.hide();
});
}
}
Any explanation just ask me.
Solution 2:
Well since you want the user to download the .apk file, you could use (in your html)
<a href="assets/app.apk" download>Download apk</a>
But the user will have to manually open his downloads (or tap the popup) to install your app.
I do not know if there is a plugin which is capable of installing these apk files. (Googling for ionic 2 install external apk didn't return any results).
Post a Comment for "Open A File Within The App Folder With Fileopener Ionic2"