Android Question Android 5.1 this code fails!

aidymp

Well-Known Member
Licensed User
Longtime User
Hi after a bit of a mental block believing my app was broken i realised I was using an API 22 Image on my emulator, Android 5.1

after reverting back to an API 17 Image the App now works, but as more TV boxes are coming to 5.1 im a little concerned as to why this code fails?

B4X:
Sub hc_ResponseSuccess (Response As OkHttpResponse, TaskId As Int)
    ' ********** Modified code *************
    Dim cs As CountingOutputStream
   
      'THE NEXT LINE FAILS ON ANDROID 5.1 WITH A DIRECTORY NOT FOUND ERROR!
      ' Temp folder is set to TempFolder = File.DirInternalCache

    cs.Initialize(File.OpenOutput(TempFolder, TaskId, False))
    Dim j As HttpJob = TaskIdToJob.Get(TaskId)
   
    If j.Tag <> Null And j.Tag Is JobTag Then

    Dim jt As JobTag = j.Tag

    jt.CountingStream = cs
    jt.Total = Response.ContentLength
    If jt.Data.url = "" Then
        Log("Job cancelled before downloaded started")
        cs.Close
    End If
    Response.GetAsynchronously("response", cs , _
        True, TaskId)
    '**************************************
    Else
    ' ************* TEST CODE
     Dim job As HttpJob = TaskIdToJob.Get(TaskId)
   job.Tag = Response.StatusCode
   Response.GetAsynchronously("response", File.OpenOutput(TempFolder, TaskId, False), _
     True, TaskId)
    End If
 
End Sub

Any Ideas as to why? could i just change the Tempfolder to something else?
 

aidymp

Well-Known Member
Licensed User
Longtime User
Which error do you get?

This is my error log

httputils2service_hc_responsesuccess (java line: 166)
java.io.FileNotFoundException: /data/data/com.aidymp.aidymatic/cache/4: open failed: ENOENT (No such file or directory)
at libcore.io.IoBridge.open(IoBridge.java:456)
at java.io.FileOutputStream.<init>(FileOutputStream.java:87)
at anywheresoftware.b4a.objects.streams.File.OpenOutput(File.java:370)
at com.aidymp.aidymatic.httputils2service._hc_responsesuccess(httputils2service.java:166)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:187)
at anywheresoftware.b4a.BA$3.run(BA.java:334)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
Caused by: android.system.ErrnoException: open failed: ENOENT (No such file or directory)
at libcore.io.Posix.open(Native Method)
at libcore.io.BlockGuardOs.open(BlockGuardOs.java:186)
at libcore.io.IoBridge.open(IoBridge.java:442)
... 15 more
java.lang.RuntimeException: java.io.FileNotFoundException: /data/data/com.aidymp.aidymatic/cache/4: open failed: ENOENT (No such file or directory)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:213)
at anywheresoftware.b4a.BA$3.run(BA.java:334)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
Caused by: java.io.FileNotFoundException: /data/data/com.aidymp.aidymatic/cache/4: open failed: ENOENT (No such file or directory)
at libcore.io.IoBridge.open(IoBridge.java:456)
at java.io.FileOutputStream.<init>(FileOutputStream.java:87)
at anywheresoftware.b4a.objects.streams.File.OpenOutput(File.java:370)
at com.aidymp.aidymatic.httputils2service._hc_responsesuccess(httputils2service.java:166)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:187)
 
Upvote 0

aidymp

Well-Known Member
Licensed User
Longtime User
Why don't you use file.dirdefaultexternal instead?

Thanks that worked, But i'm intrigued to know why "TempFolder = File.DirInternalCache" is not found? it is on all previous versions of Android.
 
Upvote 0
Top