私はIonic 3で作業しています。私はionicで初心者でしたので、使用したデバイスからドキュメントをアップロードしようとしましたが、ストレージアクセスのアンドロイドの許可がありましたが、 SDカードからファイルにアクセスしたいIonic 3でsdcardファイルにアクセスする方法
import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams } from 'ionic-angular';
import { FileChooser } from '@ionic-native/file-chooser';
import { FilePath } from '@ionic-native/file-path';
import { File } from '@ionic-native/file';
import {Platform} from "ionic-angular";
@IonicPage()
@Component({
selector: 'page-document',
templateUrl: 'document.html',
})
export class DocumentPage {
fileChooser: FileChooser;
filePath: FilePath;
nativepath: any;
file: File;
constructor(public navCtrl: NavController, public navParams: NavParams) {
this.fileChooser= new FileChooser();
this.filePath= new FilePath();
this.file=new File();
}
ionViewDidLoad() {
console.log('ionViewDidLoad DocumentPage');
}
openFile(){
this.fileChooser.open()
.then(uri => this.convertFilePath(uri))
.catch(e => alert(e));
}
convertFilePath(filePathUri: string){
this.filePath.resolveNativePath(filePathUri)
.then(filePath =>{
this.nativepath= filePath;
//Here in nativepath we get filepath
})
.catch(err => alert("filePath "+err));
}
}
上記のコード: ここでは以下の私のコードは、私がユーザーから、私は、ファイルにアクセスする場合について許可を付与ところ、上記のコードがある
import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams } from 'ionic-angular';
import { RemoteServiceProvider} from "../../providers/remote-service/remote-service";
import { AndroidPermissions } from '@ionic-native/android-permissions';
@IonicPage()
@Component({
selector: 'page-home',
templateUrl: 'home.html',
})
export class HomePage {
android: AndroidPermissions;
constructor(public remoteServiceProvider: RemoteServiceProvider, public
navParams: NavParams, public nvCtr: NavController) {
//this.getStates();
this.android= new AndroidPermissions();
this.android.requestPermissions([this.android.PERMISSION.READ_EXTERNAL_STORAGE,this.android.PERMISSION.WRITE_EXTERNAL_STORAGE])
}
getStates(){
this.remoteServiceProvider.getResult().subscribe(data => {
alert(data._body);
},error => {
alert(error);
});
}
ionViewDidLoad() {
console.log('ionViewDidLoad HomePage');
}
}
です私はどこからファイルにアクセスするのかをユーザとその下のユーザに許可します:
openFile(){
this.fileChooser.open()
.then(uri => this.convertFilePath(uri))
.catch(e => alert(e));
}
convertFilePath(filePathUri: string){
this.filePath.resolveNativePath(filePathUri)
.then(filePath =>{
this.nativepath= filePath;
//Here in navtivepath i get the file path
})
.catch(err => alert("filePath "+err));
}
コンソールにエラーがありますか? – Sampath
エラーはありません。 –