diff --git a/android/src/main/java/com/reactnativereceivesharingintent/ReceiveSharingIntentHelper.java b/android/src/main/java/com/reactnativereceivesharingintent/ReceiveSharingIntentHelper.java index 69126eb9..4cb1b973 100644 --- a/android/src/main/java/com/reactnativereceivesharingintent/ReceiveSharingIntentHelper.java +++ b/android/src/main/java/com/reactnativereceivesharingintent/ReceiveSharingIntentHelper.java @@ -28,6 +28,9 @@ public ReceiveSharingIntentHelper(Application context){ @RequiresApi(api = Build.VERSION_CODES.KITKAT) public void sendFileNames(Context context, Intent intent, Promise promise){ + if (intent == null) { + promise.reject("error","Null intent."); + } try { String action = intent.getAction(); String type = intent.getType(); @@ -165,6 +168,7 @@ private String getMediaType(String url){ public void clearFileNames(Intent intent){ + if(intent == null) return; String type = intent.getType(); if(type == null) return; if (type.startsWith("text")) { diff --git a/android/src/main/java/com/reactnativereceivesharingintent/ReceiveSharingIntentModule.java b/android/src/main/java/com/reactnativereceivesharingintent/ReceiveSharingIntentModule.java index f7521441..5b4a9c50 100644 --- a/android/src/main/java/com/reactnativereceivesharingintent/ReceiveSharingIntentModule.java +++ b/android/src/main/java/com/reactnativereceivesharingintent/ReceiveSharingIntentModule.java @@ -40,7 +40,6 @@ public void getFileNames(Promise promise){ if(mActivity == null) { return; } Intent intent = mActivity.getIntent(); receiveSharingIntentHelper.sendFileNames(reactContext, intent, promise); - mActivity.setIntent(null); } @ReactMethod @@ -48,7 +47,9 @@ public void clearFileNames(){ Activity mActivity = getCurrentActivity(); if(mActivity == null) { return; } Intent intent = mActivity.getIntent(); - receiveSharingIntentHelper.clearFileNames(intent); + if (intent != null) { + receiveSharingIntentHelper.clearFileNames(intent); + } } diff --git a/src/ReceiveSharingIntent.interfaces.ts b/src/ReceiveSharingIntent.interfaces.ts index 241ba466..cddf048b 100644 --- a/src/ReceiveSharingIntent.interfaces.ts +++ b/src/ReceiveSharingIntent.interfaces.ts @@ -1,6 +1,7 @@ export interface IReceiveSharingIntent{ getReceivedFiles(handler: Function , errorHandler: Function, protocol: string ): void, + clearFileNames() :void, } export interface IUtils{ @@ -15,4 +16,4 @@ export interface IReturnData{ contentUri?: any | string, fileName?: any | string, extension?: any | string, -} \ No newline at end of file +} diff --git a/src/ReceiveSharingIntent.ts b/src/ReceiveSharingIntent.ts index 735c1916..d1dc92e6 100644 --- a/src/ReceiveSharingIntent.ts +++ b/src/ReceiveSharingIntent.ts @@ -36,6 +36,9 @@ class ReceiveSharingIntentModule implements IReceiveSharingIntent { this.isClear = true; } + clearFileNames() { + ReceiveSharingIntent.clearFileNames(); + } protected getFileNames(handler: Function, errorHandler: Function, url: string){ if(this.isIos){ @@ -54,4 +57,4 @@ class ReceiveSharingIntentModule implements IReceiveSharingIntent { } -export default ReceiveSharingIntentModule; \ No newline at end of file +export default ReceiveSharingIntentModule;