2014-10-23 3 views
0

내 영어를 사용하십시오 ... 처음에는 안드로이드 플랫폼 용 크로스 플랫폼 웹 응용 프로그램을 작성하려고합니다. 필자는 모바일의 파일 시스템에 파일을 쓰고 읽어야합니다. 이미 패키지 rikulo_gap이 기본적으로 파일 시스템 API를 지원하지 않는 것을 보았습니다. Rikulo에서 사용하는 Fileystem API는 that one이며 모바일 플랫폼에서는 작동하지 않습니다.Rikulo에서 Cordova/Phonegap Filesystem API를 사용하는 방법은 무엇입니까?

그래서 Rikulo의 Js-Package는 내 Cordova.js-File (v4.0.0)과 다트 코드를 상호 운용 할 수 있어야합니다.이 파일에는 전역 함수 requestFileSystem (persistence, size, success-funct, fail -funct).

import 'package:rikulo_gap/device.dart'; 
import 'dart:js' as js; 

void main() { 
Device.init().then((device) => onDeviceReady(device)). 
catchError((ex) => print("AN ERROR OCCURED: " + ex.toString())); 
} 

void onDeviceReady(device) { 
var persistent = js.context['PERSISTENT']; 
print("Should be Constant PERSISTENT of LFS: " + persistent.toString()); 
var fsName = js.context.callMethod('requestFileSystem',[persistent,0,dofs,fail]); 
} 

void dofs(fs) { 
print("Success"); 
var myFs = js.context[fs]; 
print("The Return of RequestFileSystem is a: " + myFs.toString()); 
} 

로그 캣은 말한다 :

여기

내 다트 - 코드의 ... 난 점점 오류를 해요 - 지금은 내 코드가 작동을 만들기 위해 노력했습니다,하지만 난 다시 파일 시스템을하지 않습니다 날 귀찮게 무엇
10-23 18:08:32.589: D/CordovaLog(951): file:///android_asset/www/adam.dart.js: Line 12111 : Should be Constant PERSISTENT of LFS: 1 
10-23 18:08:32.624: D/CordovaLog(951): file:///android_asset/www/adam.dart.js: Line 12111 : Success 
10-23 18:08:32.649: D/CordovaLog(951): file:///android_asset/www/cordova.js: Line 1060 : processMessage failed: Stack: Error 
10-23 18:08:32.649: D/CordovaLog(951):  at dart.wrapException (file:///android_asset/www/adam.dart.js:2520:15) 
10-23 18:08:32.649: D/CordovaLog(951):  at JsObject.$index (file:///android_asset/www/adam.dart.js:11549:17) 
10-23 18:08:32.649: D/CordovaLog(951):  at dart.J.$index$asx (file:///android_asset/www/adam.dart.js:19278:41) 
10-23 18:08:32.649: D/CordovaLog(951):  at dofs (file:///android_asset/www/adam.dart.js:4185:7) 
10-23 18:08:32.649: D/CordovaLog(951):  at dart.Primitives_applyFunction (file:///android_asset/www/adam.dart.js:2489:23) 
10-23 18:08:32.649: D/CordovaLog(951):  at _callDartFunction (file:///android_asset/www/adam.dart.js:11464:29) 
10-23 18:08:32.649: D/CordovaLog(951):  at file:///android_asset/www/adam.dart.js:11671:18 
10-23 18:08:32.649: D/CordovaLog(951):  at file:///android_asset/www/plugins/org.apache.cordova.file/www/requestFileSystem.js:52:25 
10-23 18:08:32.649: D/CordovaLog(951):  at success (file:///android_asset/www/plugins/org.apache.cordova.file/www/fileSystems-roots.js:40:13) 
10-23 18:08:32.649: D/CordovaLog(951):  at Object.cordova.callbackFromNative (file:///android_asset/www/cordova.js:293:54) 
10-23 18:08:32.649: D/CordovaLog(951): file:///android_asset/www/cordova.js: Line 1061 : processMessage failed: Message: S01 File1158866550 [{"fullPath":"\/","filesystemName":"temporary","isDirectory":true,"nativeURL":"file:\/\/\/storage\/emulated\/0\/Android\/data\/de.htwg.myAndroid\/cache\/","filesystem":0,"isFile":false,"name":""},{"fullPath":"\/","filesystemName":"persistent","isDirectory":true,"nativeURL":"file:\/\/\/storage\/emulated\/0\/","filesystem":1,"isFile":false,"name":""},{"fullPath":"\/","filesystemName":"content","isDirectory":true,"nativeURL":"cdvfile:\/\/localhost\/content\/","filesystem":1,"isFile":false,"name":""},{"fullPath":"\/","filesystemName":"files","isDirectory":true,"nativeURL":"file:\/\/\/data\/data\/de.htwg.myAndroid\/files\/","filesystem":1,"isFile":false,"name":""},{"fullPath":"\/","filesystemName":"files-external","isDirectory":true,"nativeURL":"file:\/\/\/storage\/emulated\/0\/Android\/data\/de.htwg.myAndroid\/files\/","filesystem":1,"isFile":false,"name":""},{"fullPath":"\/","filesystemName":"documents","isDirectory":true,"nativeURL":"file:\/\/\/data\/data\/de.htwg.myAndroid\/files\/Documents\/","filesystem":1,"isFile":false,"name":""},{"fullPath":"\/","filesystemName":"sdcard","isDirectory":true,"nativeURL":"file:\/\/\/storage\/emulated\/0\/","filesystem":1,"isFile":false,"name":""},{"fullPath":"\/","filesystemName":"cache","isDirectory":true,"nativeURL":"file:\/\/\/data\/data\/de.htwg.myAndroid\/cache\/","filesystem":1,"isFile":false,"name":""},{"fullPath":"\/","filesystemName":"cache-external","isDirectory":true,"nativeURL":"file:\/\/\/storage\/emulated\/0\/Android\/data\/de.htwg.myAndroid\/cache\/","filesystem":1,"isFile":false,"name":""},{"fullPath":"\/","filesystemName":"root","isDirectory":true,"nativeURL":"file:\/\/\/","filesystem":1,"isFile":false,"name":""}]  

는 스택의 첫 번째 예외가 dart.wrapException이다,이다, 그래서는 일반 다트 <> JS 상호 운용성 문제 같아요.

안드로이드로 빌드하기위한 공식 코드바 지침을 따랐으며 현재는 cordova run android으로 Windows CommandLine으로 빌드하고 있습니다. (그리고 그래 내가 명령 행을 통해 플러그인 (파일, FileUtil, 장치를 설치 한 그들은이 프로젝트에 추가됩니다)

그래서 아무도 말해 수 있습니다. 내가 생각처럼

  1. 그것을되고있다 Rikulo/다트와 코르도바 - 파일 시스템 API를 사용하지 않는 일반적인 방법?
  2. 1에 해당하는 경우 해결 방법? 누구는 아이디어,이 날 도울 수있는 다른 느슨한 노트 데르 아무것도?

답변

2
  1. R ikulo는 아직 Cordova 파일 시스템 API를 지원하지 않습니다. 하나를 기부하거나 window.requestFileSystem을 대신 사용해보십시오.

  2. dofs로 반환 된 객체는 JsObject 인스턴스이므로 js.context을 사용하여 변환 할 필요가 없습니다. 즉,

    var myFs = js.context[fs]; 
    

    바로 포인트 2에서 그렇게되었습니다 OMG
    var myFs = fs; 
    
1

... 잃어버린 내 인생의 이일에 개정되어야한다 : O (포인트 1 수 없습니다 dart : html 패키지에서 window.requestFileSystem 함수가 webKitRequestFileSystem을 호출하기 때문에 크롬 브라우저에서 작동하며 LogCat은 "기능 webKitRequestFileSystem을 지원하지 않습니다."와 같이 알려줍니다.

나는 fs .toString 그냥 [개체 개체] 반환 그래서 그냥 빈 개체 및 dofs (fs) (형식) 않고 내 IDE/Dart API 함수를 서명했기 때문에 내게 'callMethod 같은 제안을주지 않았다() 'JsObject에 대한 ...지금은 그런 식으로 변경 :

void main() { 
Device.init().then((device) => onDeviceReady(device)).catchError((ex) => print("AN ERROR OCCURED: " + ex.toString())); 
} 
void onDeviceReady(device) { 
var persistent = context['PERSISTENT']; 
print("Should be Constant PERSISTENT of LFS: " + persistent.toString()); 
context.callMethod('requestFileSystem',[persistent,0,dofs,fail]); 
} 
void dofs(JsObject fs) { 
print("Success"); 
var fsroot = fs['root']; 
createFile(fsroot); 
} 
void createFile(JsObject fsroot) { 
var cNe = new JsObject.jsify({'create': true, 'exclusive': false}); 
fsroot.callMethod('getFile', ["DartCreatedFile.txt",cNe,gotFileEntry,fail]); 
} 
void gotFileEntry(JsObject fileEntry) { 
print(fileEntry['fullPath']); 
} 

을 그리고 로그 캣이 성공적으로 나에게 말한다 :

10-24 14:17:03.945: D/CordovaLog(6685): file:///android_asset/www/fileSystemApi.js: Line 8 : Device is Ready!!! 
10-24 14:17:04.055: D/CordovaLog(6685): file:///android_asset/www/adam.dart.js: Line 12294 : Should be Constant PERSISTENT of LFS: 1 
10-24 14:17:04.085: D/CordovaLog(6685): file:///android_asset/www/adam.dart.js: Line 12294 : Success 
10-24 14:17:04.105: D/CordovaLog(6685): file:///android_asset/www/adam.dart.js: Line 12294 : //DartCreatedFile.txt