react-native-mail icon indicating copy to clipboard operation
react-native-mail copied to clipboard

Error : not_available in Android 13 with several emailing app

Open Ezzine-Smichi opened this issue 1 year ago • 2 comments

When I launch email opening from my react native application, this package returns the following message "not_available". Faced with this problem, I put this portion of code as a comment if (list == null || list.size() == 0) { callback.invoke("not_available"); return; } and everything works fine again. Does this solution work for you? If not, is there another solution for this problem?

Ezzine-Smichi avatar Jul 08 '23 14:07 Ezzine-Smichi

Inside RNMailModule.java I commented out

    /*if (list == null || list.size() == 0) {
      callback.invoke("not_available");
      return;
    }
    }*/

and now it works. This requires patching the node_modules itself.

joshua-revolutions avatar Jul 11 '23 04:07 joshua-revolutions

this solution with device have only the gmail app doesn't return anything, so the problem of this package is to get access to the gmail app. inside RNMailModule.java, I replace this code:

if (list == null || list.size() == 0) { callback.invoke("not_available"); return; } }

with this code:

` if (list == null || list.size() == 0) { Intent intent = manager.getLaunchIntentForPackage("com.google.android.gm"); if (intent != null) { String chooserTitle = "Send Mail";

    if (options.hasKey("customChooserTitle") && !options.isNull("customChooserTitle")) {
      chooserTitle = options.getString("customChooserTitle");
    }

    Intent chooser = Intent.createChooser(i, chooserTitle);
    chooser.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

    try {
      reactContext.startActivity(chooser);
    } catch (Exception ex) {
      callback.invoke("error");
    }
  } else {
    callback.invoke("not_available");
    return;
  }
}`   
                                                                                                                                                                                       

The idea is to force checkout the gmail app with this line if the list is empty : Intent intent = manager.getLaunchIntentForPackage("com.google.android.gm");

Ezzine-Smichi avatar Jul 11 '23 15:07 Ezzine-Smichi