使用cordova writeFile进行20MB blob崩溃(Android)

时间:2016-12-01 15:50:07

标签: android cordova blob ngcordova

我正在尝试在Android设备上写一个20MB的blob文件。这段代码适用于4-5MB左右,但是对于较大的文件会崩溃。

tp = cordova.file.dataDirectory; // for Android $cordovaFile.writeFile(tp, "temp-file.gif", blob,true);

有没有办法处理更大的斑点?谢谢。我已经在清单中有android:largeHeap="true"

logcat错误:

E/JavaBinder(  809): !!! FAILED BINDER TRANSACTION !!!
I/art     (  809): Background sticky concurrent mark sweep GC freed 62202(4MB) AllocSpace objects, 96(3MB) LOS objects, 20% free, 25MB/31MB, paused 20.488ms total 176.243ms
E/JavaBinder(  809): !!! FAILED BINDER TRANSACTION !!!
W/ActivityManager(  809): Exception thrown during pause
W/ActivityManager(  809): android.os.TransactionTooLargeException
W/ActivityManager(  809):   at android.os.BinderProxy.transactNative(Native Method)
W/ActivityManager(  809):   at android.os.BinderProxy.transact(Binder.java:496)
W/ActivityManager(  809):   at android.app.ApplicationThreadProxy.schedulePauseActivity(ApplicationThreadNative.java:711)
W/ActivityManager(  809):   at com.android.server.am.ActivityStack.startPausingLocked(ActivityStack.java:829)
W/ActivityManager(  809):   at com.android.server.am.ActivityStack.finishActivityLocked(ActivityStack.java:2749)
W/ActivityManager(  809):   at com.android.server.am.ActivityStack.finishTopRunningActivityLocked(ActivityStack.java:2606)
W/ActivityManager(  809):   at com.android.server.am.ActivityStackSupervisor.finishTopRunningActivityLocked(ActivityStackSupervisor.java:2544)
W/ActivityManager(  809):   at com.android.server.am.ActivityManagerService.handleAppCrashLocked(ActivityManagerService.java:11721)
W/ActivityManager(  809):   at com.android.server.am.ActivityManagerService.makeAppCrashingLocked(ActivityManagerService.java:11618)
W/ActivityManager(  809):   at com.android.server.am.ActivityManagerService.crashApplication(ActivityManagerService.java:12330)
W/ActivityManager(  809):   at com.android.server.am.ActivityManagerService.handleApplicationCrashInner(ActivityManagerService.java:11819)
W/ActivityManager(  809):   at com.android.server.am.NativeCrashListener$NativeCrashReporter.run(NativeCrashListener.java:86)

2 个答案:

答案 0 :(得分:1)

解决方案,在实验之后是将写入分解成块 - 这似乎适用于我迄今为止测试过的20-30MB文件。

Step 2

信用:@Andre Werlang在这里帮助我:https://stackoverflow.com/a/40935231/1361529

答案 1 :(得分:0)

这是我使用的,我没有限制或没有达到它

function writeFile(__filename, __data){
        window.resolveLocalFileSystemURL(cordova.file.dataDirectory, function(dir){
            dir.getFile(__filename, {create:true}, function(file){            
                file.createWriter(function(fileWriter){
                    var blob = new Blob([__data], {type:'text/plain'});
                    fileWriter.write(blob);

                });                     
            });
        });   
    };