ajith-ab / react-native-receive-sharing-intent

A React Native plugin that enables React Native apps to receive sharing photos, videos, text, urls or any other file types from another app
MIT License
305 stars 109 forks source link

Error: java.lang.NullPointerException in latest 2.0.0 virsion #81

Open ShridharMe-Kore opened 3 years ago

ShridharMe-Kore commented 3 years ago

[Error: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String android.content.Intent.getAction()' on a null object reference] share ext error

davidsalib commented 3 years ago

I've narrowed down that in the Java code, the Intent is coming through as null. Thus "getAction()" or "getType()" fail. I tried revising the AndroidManifest to make sure the intent if being passed through properly, but that didn't help. Also tried modifying the Java code with the PR above (#42), but that didn't work either.

The issue is in this code block:

@RequiresApi(api = Build.VERSION_CODES.KITKAT)
  @ReactMethod
  public void getFileNames(Promise promise){
    Activity mActivity = getCurrentActivity();
    if(mActivity == null) { return; }
    Intent intent = mActivity.getIntent();
    receiveSharingIntentHelper.sendFileNames(reactContext, intent, promise);
    mActivity.setIntent(null);
  }

Any ideas?

digitalbore commented 2 years ago

I have the same problem. Any solution?

Mohammad-DH commented 1 year ago

same

jtkDvlp commented 1 year ago

Same here, it seems for the initial call there is no intent object, so you can check if it´s not null.

  @RequiresApi(api = Build.VERSION_CODES.KITKAT)
  @ReactMethod
  public void getFileNames(Promise promise){
    Activity mActivity = getCurrentActivity();
    if(mActivity == null) { return; }
    Intent intent = mActivity.getIntent();
    if(intent == null) { return; }
    receiveSharingIntentHelper.sendFileNames(reactContext, intent, promise);
    mActivity.setIntent(null);
  }