@@ -87,15 +87,17 @@ public void onReceive(Context context, Intent intent) {
8787 }
8888 };
8989
90+ Log .d (TAG , "Registering broadcast receiver" );
9091 ContextCompat .registerReceiver (this , receiver ,
9192 new IntentFilter (DownloadManager .ACTION_DOWNLOAD_COMPLETE ),
92- ContextCompat .RECEIVER_NOT_EXPORTED );
93+ ContextCompat .RECEIVER_EXPORTED );
9394
9495 }
9596
9697 private void receiveBroadcast (Intent intent ) {
9798
9899 String action = intent .getAction ();
100+ Log .d (TAG , "Broadcast received: " + action );
99101 if (!DownloadManager .ACTION_DOWNLOAD_COMPLETE .equals (action )) {
100102 return ;
101103 }
@@ -115,15 +117,24 @@ private void receiveBroadcast(Intent intent) {
115117 try (Cursor cursor = downloadManager .query (query )) {
116118 if (cursor .moveToFirst ()) {
117119 int statusColumnIndex = cursor .getColumnIndex (DownloadManager .COLUMN_STATUS );
118- if (DownloadManager .STATUS_SUCCESSFUL == cursor .getInt (statusColumnIndex )) {
120+ int status = cursor .getInt (statusColumnIndex );
121+ Log .d (TAG , "Download status: " + status );
122+ if (DownloadManager .STATUS_SUCCESSFUL == status ) {
119123 int localUriColumnIndex = cursor .getColumnIndex (DownloadManager .COLUMN_LOCAL_URI );
120124 if (localUriColumnIndex >= 0 ) {
121125 String uriString = cursor .getString (localUriColumnIndex );
122126 Uri uri = Uri .parse (uriString );
127+ Log .d (TAG , "Download successful, URI: " + uriString );
123128 getViewModel ().setProgressReport (getString (R .string .database_update_extract_start ));
124129 startExtractTask (uri );
125130 }
131+ } else if (DownloadManager .STATUS_FAILED == status ) {
132+ int reasonColumnIndex = cursor .getColumnIndex (DownloadManager .COLUMN_REASON );
133+ int reason = cursor .getInt (reasonColumnIndex );
134+ Log .e (TAG , "Download failed, reason: " + reason );
126135 }
136+ } else {
137+ Log .w (TAG , "Download cursor empty for ID: " + activeDownloadId );
127138 }
128139 } catch (Exception e ) {
129140 Log .e (TAG , e .getMessage (), e );
@@ -306,8 +317,10 @@ public void checkLocalFilesCallback(Long localDate, Long localSize) {
306317
307318 public void doDownload (View view ) {
308319
320+ Log .d (TAG , "doDownload called" );
309321 String externalStorageState = Environment .getExternalStorageState ();
310322 if (!Environment .MEDIA_MOUNTED .equals (externalStorageState )) {
323+ Log .e (TAG , "External storage not mounted: " + externalStorageState );
311324 return ;
312325 }
313326
@@ -332,13 +345,10 @@ public void doDownload(View view) {
332345 }
333346 }
334347
335- File externalFilesDir = getExternalFilesDir (Environment .DIRECTORY_DOWNLOADS );
336- File downloadFile = new File (externalFilesDir , INDEX_FILE );
337- Uri uri = Uri .fromFile (downloadFile );
338-
339348 Request request = new Request (Uri .parse (INDEX_URL ));
340- request .setDestinationUri ( uri );
349+ request .setDestinationInExternalFilesDir ( this , Environment . DIRECTORY_DOWNLOADS , INDEX_FILE );
341350 long queueId = downloadManager .enqueue (request );
351+ Log .d (TAG , "Download enqueued, ID: " + queueId );
342352 model .setActiveDownloadId (queueId );
343353
344354 AppCompatImageView icon = findViewById (R .id .database_block_progress_icon );
0 commit comments