8
8
import android .os .Build ;
9
9
import androidx .core .content .FileProvider ;
10
10
import android .util .SparseArray ;
11
+ import android .content .ActivityNotFoundException ;
11
12
12
13
import com .facebook .react .bridge .ActivityEventListener ;
13
14
import com .facebook .react .bridge .Callback ;
@@ -116,15 +117,14 @@ public void actionViewIntent(String path, String mime, @Nullable String chooserT
116
117
Intent intent = new Intent (Intent .ACTION_VIEW );
117
118
if (Build .VERSION .SDK_INT >= 24 ) {
118
119
// Create the intent with data and type
119
- Intent intent = new Intent (Intent .ACTION_VIEW )
120
- .setDataAndType (uriForFile , mime );
120
+ intent .setDataAndType (uriForFile , mime );
121
121
if (chooserTitle != null ) {
122
122
intent = Intent .createChooser (intent , chooserTitle );
123
123
}
124
124
125
125
// Set flag to give temporary permission to external app to use FileProvider
126
126
intent .setFlags (Intent .FLAG_GRANT_READ_URI_PERMISSION );
127
- // All the activity to be opened outside of an activity
127
+ // All the activity to be opened outside of an activity
128
128
intent .addFlags (Intent .FLAG_ACTIVITY_NEW_TASK );
129
129
130
130
// Validate that the device can open the file
@@ -134,20 +134,22 @@ public void actionViewIntent(String path, String mime, @Nullable String chooserT
134
134
}
135
135
136
136
} else {
137
- Intent intent = new Intent (Intent .ACTION_VIEW )
138
- .setDataAndType (Uri .parse ("file://" + path ), mime ).setFlags (Intent .FLAG_ACTIVITY_NEW_TASK );
137
+ intent .setDataAndType (Uri .parse ("file://" + path ), mime ).setFlags (Intent .FLAG_ACTIVITY_NEW_TASK );
139
138
if (chooserTitle != null ) {
139
+ intent = Intent .createChooser (intent , chooserTitle );
140
+ }
140
141
141
- PackageManager pm = getCurrentActivity (). getPackageManager ();
142
- if ( intent . resolveActivity ( pm ) != null ) {
143
- this . getReactApplicationContext (). startActivity ( intent );
144
- promise . resolve ( true );
145
- } else {
146
- promise . reject ( "ENOAPP" , "No app installed for " + mime );
142
+ try {
143
+ this . getReactApplicationContext (). startActivity ( intent );
144
+ promise . resolve ( true );
145
+ } catch ( ActivityNotFoundException ex ) {
146
+ promise . reject ( "ENOAPP" , "No app installed for " + mime );
147
+ }
147
148
}
148
149
ActionViewVisible = true ;
149
150
150
151
final LifecycleEventListener listener = new LifecycleEventListener () {
152
+
151
153
@ Override
152
154
public void onHostResume () {
153
155
if (ActionViewVisible )
0 commit comments