Android 시스템에서 Cordova의 파일 작업 포인트
따라서 대상 플랫폼에서 파일을 새로 만드는 방법이 문제입니다.응,
가난하기 때문에,
맥을 살 수 없어서 애플 기기에서 개발 및 테스트를 할 수가 없어요. 지금은 안드로이드만 생각하고 있어요.
구체적인 단계:
1. Cordova의 파일 시스템 운영 플러그인 추가
cordova plugin add cordova-plugin-file`
2. 세부 코드
import { Component, OnInit } from '@angular/core';
import { NavController } from 'ionic-angular';
declare let cordova: any;
declare let window: any;
@Component({
selector: 'page-home',
templateUrl: 'home.html'
})
export class HomePage implements OnInit {
ngOnInit() {
document.addEventListener('deviceready', () => {
window.resolveLocalFileSystemURL(cordova.file.applicationStorageDirectory, root => {
alert(JSON.stringify(root));
root.getFile('demo.txt', { create: true }, fileEntry => {
alert(JSON.stringify(fileEntry));
}, error => {
alert(JSON.stringify(error))
});
}, error => {
alert(JSON.stringify(error))
});
});
}
}
여기 인터넷에 구덩이가 하나 있는데
cordova.file.applicationStorageDirectory
이 물건은 인용부호를 붙일 수 없다.이 필드의 구체적인 의미는 다음과 같다.Android File System Layout: (From https://www.npmjs.com/package/cordova-plugin-file#android-file-system-layout)
Device Path
cordova.file.*
AndroidExtraFileSystems
r/w?
persistent?
OS clears
private
file:///android_asset/
applicationDirectory
assets
r
N/A
N/A
Yes
/data/data//
applicationStorageDirectory
-
r/w
N/A
N/A
Yes
cache
cacheDirectory
cache
r/w
Yes
Yes*
Yes
files
dataDirectory
files
r/w
Yes
No
Yes
Documents
documents
r/w
Yes
No
Yes
/
externalRootDirectory
sdcard
r/w
Yes
No
No
Android/data//
externalApplicationStorageDirectory
-
r/w
Yes
No
No
cache
externalCacheDirectory
cache-external
r/w
Yes
No**
No
files
externalDataDirectory
files-external
r/w
Yes
No
No
* The OS may periodically clear this directory, but do not rely on this behavior. Clear the contents of this directory as appropriate for your application. Should a user purge the cache manually, the contents of this directory are removed. ** The OS does not clear this directory automatically; you are responsible for managing the contents yourself. Should the user purge the cache manually, the contents of the directory are removed. Note: If external storage can't be mounted, the cordova.file.external* properties are null.
주의 사항
...
...
...
...
declare let cordova: any;
declare let window: any;
이상, 에서 상당히 그다지 좋지 않은 설명이 있다.참조 자료:
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
다양한 언어의 JSONJSON은 Javascript 표기법을 사용하여 데이터 구조를 레이아웃하는 데이터 형식입니다. 그러나 Javascript가 코드에서 이러한 구조를 나타낼 수 있는 유일한 언어는 아닙니다. 저는 일반적으로 '객체'{}...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.