Skip to content
This repository has been archived by the owner on Mar 16, 2019. It is now read-only.

Commit

Permalink
Change Download Manager complete handler #75
Browse files Browse the repository at this point in the history
  • Loading branch information
wkh237 committed Aug 11, 2016
1 parent 161c86c commit 130d9f3
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 17 deletions.
37 changes: 21 additions & 16 deletions src/android/src/main/java/com/RNFetchBlob/RNFetchBlobReq.java
Original file line number Diff line number Diff line change
Expand Up @@ -558,33 +558,38 @@ public void onReceive(Context context, Intent intent) {
DownloadManager dm = (DownloadManager) appCtx.getSystemService(Context.DOWNLOAD_SERVICE);
dm.query(query);
Cursor c = dm.query(query);
String filePath = null;
// the file exists in media content database
if (c.moveToFirst()) {
String contentUri = c.getString(c.getColumnIndex(DownloadManager.COLUMN_LOCAL_URI));
Uri uri = Uri.parse(contentUri);
Cursor cursor = appCtx.getContentResolver().query(uri, new String[]{android.provider.MediaStore.Images.ImageColumns.DATA}, null, null, null);
// use default destination of DownloadManager
if (cursor != null) {
cursor.moveToFirst();
String filePath = cursor.getString(0);
filePath = cursor.getString(0);
cursor.close();
this.callback.invoke(null, RNFetchBlobConst.RNFB_RESPONSE_PATH, filePath);
}
// custom destination
else {
if(options.addAndroidDownloads.hasKey("path")) {
try {
String customDest = options.addAndroidDownloads.getString("path");
boolean exists = new File(customDest).exists();
if(!exists)
throw new Exception("Download manager download failed, the file does not downloaded to destination.");
callback.invoke(null, RNFetchBlobConst.RNFB_RESPONSE_PATH, customDest);

} catch(Exception ex) {
this.callback.invoke(ex.getLocalizedMessage(), null, null);
}
if(filePath != null) {
this.callback.invoke(null, RNFetchBlobConst.RNFB_RESPONSE_PATH, filePath);
return;
}
}
}
// When the file is not found in media content database, check if custom path exists
if (options.addAndroidDownloads.hasKey("path")) {
try {
String customDest = options.addAndroidDownloads.getString("path");
boolean exists = new File(customDest).exists();
if(!exists)
throw new Exception("Download manager download failed, the file does not downloaded to destination.");
callback.invoke(null, RNFetchBlobConst.RNFB_RESPONSE_PATH, customDest);

} catch(Exception ex) {
this.callback.invoke(ex.getLocalizedMessage(), null, null);
}
}
else
this.callback.invoke(null, RNFetchBlobConst.RNFB_RESPONSE_PATH, filePath);
}
}
}
Expand Down
1 change: 0 additions & 1 deletion src/ios/RNFetchBlobFS.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@

// file stream
- (void) openWithDestination;
- (void) openWithId;
- (NSString *)openWithPath:(NSString *)destPath encode:(nullable NSString *)encode appendData:(BOOL)append;
- (void) startAssetReadStream:(NSData *)assetUrl;

Expand Down

0 comments on commit 130d9f3

Please sign in to comment.