Open
Description
In Android, if there is no app available on the device for specific file extensions(docx, pptx, zip)
using function actionViewIntent(), can I get callback this case?
(intent.resolveActivity(pm) == null)
I want to alert message to user for installing executable application.
In this case of function actionViewIntent(), if there is no respond, just called then().
Thank you.
const android = RNFetchBlob.android
android.actionViewIntent(this.state.materialItem.fileList[fileItemIndex].localFilePath, mimeType)
.then((success) => {
console.log('success: ', success)
})
.catch((err) => {
console.log('err:', err)
})
@ReactMethod
public void actionViewIntent(String path, String mime, final Promise promise) {
try {
Uri uriForFile = FileProvider.getUriForFile(getCurrentActivity(),
this.getReactApplicationContext().getPackageName() + ".provider", new File(path));
if (Build.VERSION.SDK_INT >= 24) {
// Create the intent with data and type
Intent intent = new Intent(Intent.ACTION_VIEW)
.setDataAndType(uriForFile, mime);
// Set flag to give temporary permission to external app to use FileProvider
intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
// All the activity to be opened outside of an activity
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
// Validate that the device can open the file
PackageManager pm = getCurrentActivity().getPackageManager();
if (intent.resolveActivity(pm) != null) {
this.getReactApplicationContext().startActivity(intent);
}
} else {
Intent intent = new Intent(Intent.ACTION_VIEW)
.setDataAndType(Uri.parse("file://" + path), mime).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
this.getReactApplicationContext().startActivity(intent);
}
ActionViewVisible = true;
final LifecycleEventListener listener = new LifecycleEventListener() {
@Override
public void onHostResume() {
if(ActionViewVisible)
promise.resolve(null);
RCTContext.removeLifecycleEventListener(this);
}
@Override
public void onHostPause() {
}
@Override
public void onHostDestroy() {
}
};
RCTContext.addLifecycleEventListener(listener);
} catch(Exception ex) {
promise.reject("EUNSPECIFIED", ex.getLocalizedMessage());
}
}
Metadata
Metadata
Assignees
Labels
No labels