I have run into an issue with images stored in the assets directory & manipulating them with the CamUtils module. Specifically, if I load an image that's in the assets directory & then pass it to CreateScaledBitmap I get the following error:
java.io.FileNotFoundException: AssetsDir/pet2.png (No such file or directory)
This happens on a Nexus 5X running the current N beta, but doesn't happen on previous (non-N) Android versions. Target SDK in the manifest is 21. It seems like perhaps a permissions issue, but I can load & display the bitmap fine as long as I don't try to call the CreateScaledBitmap function in CamUtils.
Additionally, I can load & manipulate (with CamUtils) images that are stored in Files.DirInternal without any problems.
UPDATE: I tried a workaround where I copy the image to the Files.DirInternal directory, then call the exifdata1.Initialize on it from there & it works fine - so it seems to be something that the jpegutils library (or the underlying API) doesn't like about the assets directory in Android N.
I don't think that is related to Android N. Based on this error message the library doesn't support the debugger virtual assets feature. You can disable it with: #DebuggerForceStandardAssets: True
I don't think that is related to Android N. Based on this error message the library doesn't support the debugger virtual assets feature. You can disable it with: #DebuggerForceStandardAssets: True
Thanks for the suggestion Erel - I tried it but still the same issue. As I said in my original post, I don't have this issue on any device that's not running N. Here is the full error trace:
Error occurred on line: 75 (CamUtils)
java.io.FileNotFoundException: AssetsDir/pet2.png (No such file or directory)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(FileInputStream.java:146)
at java.io.FileInputStream.<init>(FileInputStream.java:99)
at android.media.ExifInterface.<init>(ExifInterface.java:1105)
at anywheresoftware.b4a.agraham.jpegutils.ExifUtils.Initialize(ExifUtils.java:63)
at com.airlinemates.mypets.camutils._calculateaspectratio(camutils.java:47)
at com.airlinemates.mypets.main._load_pets(main.java:1251)
at com.airlinemates.mypets.main._activity_resume(main.java:766)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:703)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:340)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:247)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:134)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:153)
at com.airlinemates.mypets.main.afterFirstLayout(main.java:108)
at com.airlinemates.mypets.main.access$000(main.java:17)
at com.airlinemates.mypets.main$WaitForLayout.run(main.java:80)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6077)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
& here is the code that the error originates from:
B4X:
Public Sub calculateAspectRatio(dir As String, fileName As String, srcWidth As Int, srcHeight As Int, maxWidth As Int, maxHeight As Int) As Int()
Private exifdata1 As ExifData
exifdata1.Initialize(dir, fileName)
Private fRatio As Float = Min(maxWidth / srcWidth, maxHeight / srcHeight)
Private iDims(2) As Int
iDims(0) = srcWidth * fRatio
iDims(1) = srcHeight * fRatio
Return iDims
End Sub
I have a workaround where I copy the file into the File.DirInternal directory & this works, but I'd sure like to get to the bottom of why this issue has suddenly popped up on the device I have running N. The app was working fine on the same device when it was running Marshmallow - it was only after I upgraded to N that I started having this issue.
I don't think that this issue is related to Android N. For further discussion please start a new thread and upload a small example that demonstrates it.