Android app crashes when trying to open jpg file (Android 16) FileNotFoundException


I have an app (for personal use) that crashes immediately after installation. The app has run successfully for many years on a succession of old devices, but crashes when I install it on a phone with Android 16.

At first sight it appears that the problem is that my app has not been granted the permission that it needs to access external storage. However, it has been suggested in the following Stack Overflow thread that I should open this fresh Stack Overflow question, showing my now-current manifest, the complete stack trace associated with the crash, and the code that triggers that crash.
https://stackoverflow.com/questions/79949377/requesting-storage-permission-in-my-own-app-for-my-own-personal-use

I would welcome any suggestions as to where I may be going wrong

AndroidManifest.xml


<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    android:versionCode="1"
      android:versionName="1.0">
    <uses-permission
        android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission
        android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission
        android:name="android.permission.MANAGE_EXTERNAL_STORAGE" />
    <uses-permission
        android:name="android.permission.ACCESS_NETWORK_STATE" />

    <application
        android:label="@string/app_name"
        android:allowBackup="false"
        android:requestLegacyExternalStorage="true">

        <activity android:name=".MyMap"
                  android:label="@string/app_name"
                  android:configChanges ="orientation"
            android:exported="true">

            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
            <intent-filter>
                <action android:name="com.prepbgg.mymap.action.latlong"/>
                <category android:name="android.intent.category.DEFAULT" />
                <data android:scheme="latlong"/>
            </intent-filter>
        </activity>

        <activity android:name=".PickFromList">
        </activity>
        <activity android:name=".TextList">
        </activity>
        <activity android:name=".DisplayText"
            android:configChanges="orientation">
        </activity>
        <activity android:name=".DisplayJpg"
            android:configChanges="orientation">
        </activity>

        <provider
            android:name="androidx.core.content.FileProvider"
            android:authorities="com.prepbgg.fileprovider"
            android:exported="false"
            android:grantUriPermissions="true">
            <meta-data
                android:name="android.support.FILE_PROVIDER_PATHS"
                android:resource="@xml/file_paths" />
        </provider>


    </application>
</manifest> 

Logcat from the point where the app's main activity calls onCreate() is as follows:

2026-06-01 11:04:33.113 32186-32186 Hi                      com.prepbgg.mymap                    I  Starting onCreate
2026-06-01 11:04:33.127 32186-32186 CompatChangeReporter    com.prepbgg.mymap                    D  Compat change id reported: 279646685; UID 10350; state: ENABLED
2026-06-01 11:04:33.144 32186-32186 MapView                 com.prepbgg.mymap                    I  com.prepbgg.mymap.MyMap@849c3f5
2026-06-01 11:04:33.155 32186-32186 Model                   com.prepbgg.mymap                    I  SM-A176B
2026-06-01 11:04:33.156 32186-32186 Info                    com.prepbgg.mymap                    I  recycling bitmap
2026-06-01 11:04:33.168 32186-32186 m.prepbgg.mymap         com.prepbgg.mymap                    I  Explicit concurrent mark compact GC freed 1461KB AllocSpace bytes, 0(0B) LOS objects, 73% free, 2194KB/8338KB, paused 410us,1.121ms total 12.052ms
2026-06-01 11:04:33.197 32186-32186 Pixels per cell         com.prepbgg.mymap                    I  600
2026-06-01 11:04:33.197 32186-32186 Model                   com.prepbgg.mymap                    I  not known
2026-06-01 11:04:33.197 32186-32186 Pixels per cell         com.prepbgg.mymap                    I  600
2026-06-01 11:04:33.279 32186-32186 BitmapFactory           com.prepbgg.mymap                    E  Unable to decode file: java.io.FileNotFoundException: /storage/emulated/0/maps/LR/0450E0090N/LR05100150.jpg: open failed: EACCES (Permission denied)
2026-06-01 11:04:33.283 32186-32186 TransactionExecutor     com.prepbgg.mymap                    E  Failed to execute the transaction: tId:1599214240 ClientTransaction{
                                                                                                    tId:1599214240   transactionItems=[
                                                                                                    tId:1599214240     LaunchActivityItem{activityToken=android.os.BinderProxy@914ef85,intent=Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 xflg=0x4 cmp=com.prepbgg.mymap/.MyMap },ident=134182143,info=ActivityInfo{7de2bcf com.prepbgg.mymap.MyMap},curConfig={1.15 234mcc20mnc [en_GB] ldltr sw384dp w384dp h832dp 450dpi nrml long port finger -keyb/v/h -nav/h winConfig={ mBounds=Rect(0, 0 - 1080, 2340) mAppBounds=Rect(0, 0 - 1080, 2340) mMaxBounds=Rect(0, 0 - 1080, 2340) mDisplayRotation=ROTATION_0 mWindowingMode=fullscreen mActivityType=undefined mAlwaysOnTop=undefined mRotation=ROTATION_0 mStageConfig=undefined mPopOver=off mOverlappingWithCutout=false} s.2023 fontWeightAdjustment=0 ff=0 bf=-1 bts=0 cst=1.0 nightDim=0 themeSeq=0},overrideConfig={1.15 234mcc20mnc [en_GB] ldltr sw384dp w384dp h832dp 450dpi nrml long port finger -keyb/v/h -nav/h winConfig={ mBounds=Rect(0, 0 - 1080, 2340) mAppBounds=Rect(0, 0 - 1080, 2340) mMaxBounds=Rect(0, 0 - 1080, 2340) mDisplayRotation=ROTATION_0 mWindowingMode=fullscreen mActivityType=standard mAlwaysOnTop=undefined mRotation=ROTATION_0 mStageConfig=undefined mPopOver=off mOverlappingWithCutout=false} s.2 fontWeightAdjustment=0 ff=0 bf=-1 bts=0 cst=1.0 nightDim=0 themeSeq=0},deviceId=0,referrer=com.android.shell,procState=2,state=null,persistentState=null,pendingResults=null,pendingNewIntents=null,sceneTransitionInfo=null,profilerInfo=null,assistToken=android.os.BinderProxy@5935a30,shareableActivityToken=android.os.BinderProxy@65836a9,activityWindowInfo=ActivityWindowInfo{isEmbedded=false, taskBounds=Rect(0, 0 - 1080, 2340), taskFragmentBounds=Rect(0, 0 - 1080, 2340)}}
                                                                                                    tId:1599214240     ResumeActivityItem{mActivityToken=android.os.BinderProxy@914ef85,procState=-1,isForward=true,shouldSendCompatFakeFocus=false}
                                                                                                    tId:1599214240     Target activity: com.prepbgg.mymap.MyMap
                                                                                                    tId:1599214240   ]
                                                                                                    tId:1599214240 }
2026-06-01 11:04:33.283 32186-32186 AndroidRuntime          com.prepbgg.mymap                    D  Shutting down VM
2026-06-01 11:04:33.287 32186-32186 AndroidRuntime          com.prepbgg.mymap                    E  FATAL EXCEPTION: main
                                                                                                    Process: com.prepbgg.mymap, PID: 32186
                                                                                                    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.prepbgg.mymap/com.prepbgg.mymap.MyMap}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.graphics.Bitmap.recycle()' on a null object reference
                                                                                                    	at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:4710)
                                                                                                    	at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:4941)
                                                                                                    	at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:222)
                                                                                                    	at android.app.servertransaction.TransactionExecutor.executeNonLifecycleItem(TransactionExecutor.java:133)
                                                                                                    	at android.app.servertransaction.TransactionExecutor.executeTransactionItems(TransactionExecutor.java:103)
                                                                                                    	at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:80)
                                                                                                    	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:3150)
                                                                                                    	at android.os.Handler.dispatchMessage(Handler.java:110)
                                                                                                    	at android.os.Looper.loopOnce(Looper.java:273)
                                                                                                    	at android.os.Looper.loop(Looper.java:363)
                                                                                                    	at android.app.ActivityThread.main(ActivityThread.java:10060)
                                                                                                    	at java.lang.reflect.Method.invoke(Native Method)
                                                                                                    	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:632)
                                                                                                    	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:975)
                                                                                                    Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.graphics.Bitmap.recycle()' on a null object reference
                                                                                                    	at com.prepbgg.mymap.MapView.drawTile(MapView.java:495)
                                                                                                    	at com.prepbgg.mymap.MapView.showTiles(MapView.java:407)
                                                                                                    	at com.prepbgg.mymap.MapView.doDrawing(MapView.java:281)
                                                                                                    	at com.prepbgg.mymap.MapView.redrawBuffer(MapView.java:241)
                                                                                                    	at com.prepbgg.mymap.MyMap.setupMapLayout(MyMap.java:540)
                                                                                                    	at com.prepbgg.mymap.MyMap.onCreate(MyMap.java:182)
                                                                                                    	at android.app.Activity.performCreate(Activity.java:9519)
                                                                                                    	at android.app.Activity.performCreate(Activity.java:9488)
                                                                                                    	at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1524)
                                                                                                    	at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:4692)
                                                                                                    	... 13 more
2026-06-01 11:04:33.306 32186-32186 Process                 com.prepbgg.mymap                    I  Sending signal. PID: 32186 SIG: 9
2026-06-01 11:05:25.087 32633-32633 nativeloader            com.prepbgg.mymap                    D  Load libframework-connectivity-tiramisu-jni.so using APEX ns com_android_tethering for caller /apex/com.android.tethering/javalib/framework-connectivity-t.jar: ok
2026-06-01 11:05:25.091 32633-32633 ActivityThread          com.prepbgg.mymap                    D  setConscryptValidator
2026-06-01 11:05:25.092 32633-32633 ActivityThread          com.prepbgg.mymap                    D  setConscryptValidator - put
---------------------------- PROCESS STARTED (32633) for package com.prepbgg.mymap ----------------------------
2026-06-01 11:05:25.144 32633-32633 nativeloader            com.prepbgg.mymap                    D  Configuring clns-9 for other apk /data/app/~~M8gbulRwXA9n-355k7ejBg==/com.prepbgg.mymap-fVWWYzNT8l4gNkOC3qcLUw==/base.apk. target_sdk_version=35, uses_libraries=, library_path=/data/app/~~M8gbulRwXA9n-355k7ejBg==/com.prepbgg.mymap-fVWWYzNT8l4gNkOC3qcLUw==/lib/arm64, permitted_path=/data:/mnt/expand:/data/user/0/com.prepbgg.mymap
2026-06-01 11:05:25.146 32633-32633 CompatChangeReporter    com.prepbgg.mymap                    D  Compat change id reported: 202956589; UID 10350; state: ENABLED
2026-06-01 11:05:25.157 32633-32633 GraphicsEnvironment     com.prepbgg.mymap                    V  Currently set values for:
2026-06-01 11:05:25.158 32633-32633 GraphicsEnvironment     com.prepbgg.mymap                    V    angle_gl_driver_selection_pkgs=[]
2026-06-01 11:05:25.158 32633-32633 GraphicsEnvironment     com.prepbgg.mymap                    V    angle_gl_driver_selection_values=[]
2026-06-01 11:05:25.158 32633-32633 GraphicsEnvironment     com.prepbgg.mymap                    V  com.prepbgg.mymap is not listed in per-application setting
2026-06-01 11:05:25.158 32633-32633 GraphicsEnvironment     com.prepbgg.mymap                    V  ANGLE allowlist from config: 
2026-06-01 11:05:25.158 32633-32633 GraphicsEnvironment     com.prepbgg.mymap                    V  com.prepbgg.mymap is not listed in ANGLE allowlist or settings, returning default
2026-06-01 11:05:25.158 32633-32633 GraphicsEnvironment     com.prepbgg.mymap                    V  Neither updatable production driver nor prerelease driver is supported.
2026-06-01 11:05:25.208 32633-32633 CompatChangeReporter    com.prepbgg.mymap                    D  Compat change id reported: 312399441; UID 10350; state: ENABLED
---------------------------- PROCESS ENDED (32633) for package com.prepbgg.mymap ----------------------------

The code for the drawFile() method in which the crash happens is as follows.

Line 495 (referred to in Logcat) is the first of the two that read tile1.recycle();


    private void drawTile(String strFilename, Rect rect, Canvas bufferCanvas, Paint paint){
    	File f = new File(strFilename);

    	if ( f.exists() && f!=null)
    	{
    		Bitmap tile1 = BitmapFactory.decodeFile(strFilename);
        	if (tile1!=null) {
                bufferCanvas.drawBitmap(tile1, null, rect, paint);
            }
        	tile1.recycle();
    	}
    	else {
			Log.i("Hi","Using blue");
    		Bitmap tile1 = BitmapFactory.decodeFile(Environment.getExternalStorageDirectory().getPath() + "/maps/blue.gif");
    		bufferCanvas.drawBitmap(tile1, null, rect, paint);
    		tile1.recycle();
    	}
    }
1
Jun 1 at 3:08 PM
User Avatarprepbgg
#android#filenotfoundexception#permission-denied

No answer found for this question yet.