Skip to content

Commit d054c8c

Browse files
Ron RadtkeRon Radtke
authored andcommitted
promise resolve 7 Reject for opening the actionview indent
# Conflicts: # android/src/main/java/com/RNFetchBlob/RNFetchBlob.java # android/src/main/java/com/RNFetchBlob/RNFetchBlobReq.java
2 parents 48e4b2b + 9a168bf commit d054c8c

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

README.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -588,14 +588,22 @@ RNFetchBlob.config({
588588
})
589589
.fetch('GET', `http://www.example.com/awesome.apk`)
590590
.then((res) => {
591-
android.actionViewIntent(res.path(), 'application/vnd.android.package-archive')
591+
android.actionViewIntent(res.path(), 'application/vnd.android.package-archive').then(() => {
592+
console.log('File opened')
593+
}).catch(e => {
594+
console.warn('Unable to open file', e);
595+
})
592596
})
593597
```
594598

595599
Or show an image in image viewer
596600

597601
```js
598-
android.actionViewIntent(PATH_OF_IMG, 'image/png')
602+
android.actionViewIntent(PATH_OF_IMG, 'image/png').then(() => {
603+
console.log('File opened')
604+
}).catch(e => {
605+
console.warn('Unable to open file', e);
606+
})
599607
```
600608

601609
## File System

android/src/main/java/com/RNFetchBlob/RNFetchBlob.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ public void actionViewIntent(String path, String mime, @Nullable String chooserT
113113
Uri uriForFile = FileProvider.getUriForFile(this.getReactApplicationContext(),
114114
this.getReactApplicationContext().getPackageName() + ".provider", new File(path));
115115

116+
Intent intent = new Intent(Intent.ACTION_VIEW);
116117
if (Build.VERSION.SDK_INT >= 24) {
117118
// Create the intent with data and type
118119
Intent intent = new Intent(Intent.ACTION_VIEW)
@@ -128,18 +129,17 @@ public void actionViewIntent(String path, String mime, @Nullable String chooserT
128129

129130
// Validate that the device can open the file
130131
PackageManager pm = getCurrentActivity().getPackageManager();
131-
if (intent.resolveActivity(pm) != null) {
132-
this.getReactApplicationContext().startActivity(intent);
133-
}
134-
135132
} else {
136133
Intent intent = new Intent(Intent.ACTION_VIEW)
137134
.setDataAndType(Uri.parse("file://" + path), mime).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
138135
if (chooserTitle != null) {
139-
intent = Intent.createChooser(intent, chooserTitle);
140-
}
141136

137+
PackageManager pm = getCurrentActivity().getPackageManager();
138+
if (intent.resolveActivity(pm) != null) {
142139
this.getReactApplicationContext().startActivity(intent);
140+
promise.resolve(true);
141+
} else {
142+
promise.reject("ENOAPP", "No app installed for " + mime);
143143
}
144144
ActionViewVisible = true;
145145

0 commit comments

Comments
 (0)