I'm building a react native module, from my module I send a PendingIntent like this.
Intent postAuthorizationIntent = new Intent("com.example.HANDLE_AUTHORIZATION_RESPONSE");
PendingIntent pendingIntent = PendingIntent.getActivity(reactContext.getApplicationContext(), request.hashCode(), postAuthorizationIntent, 0);
If I modify the MainActivity then I can receive data inside onNewIntent() method. The class looks like this...
public class MainActivity extends ReactActivity {
/**
* Returns the name of the main component registered from JavaScript.
* This is used to schedule rendering of the component.
*/
@Override
protected String getMainComponentName() {
return "example";
}
@Override
public void onNewIntent(Intent intent) {
checkIntent(intent);
}
@Override
protected void onStart() {
super.onStart();
checkIntent(getIntent());
}
private void checkIntent(@Nullable Intent intent) {
if (intent != null) {
String action = intent.getAction();
switch (action) {
case "com.example.HANDLE_AUTHORIZATION_RESPONSE":
...
break;
default:
// do nothing
}
}
}
}
Then when I try to move this logic to my Module, nothing happens, it does not work.
public class ExampleModule extends ReactContextBaseJavaModule implements ActivityEventListener{
private ReactApplicationContext reactContext;
private String action = "";
public ExampleModule(ReactApplicationContext reactContext) {
super(reactContext);
this.reactContext = reactContext;
this.action = "com.example.HANDLE_AUTHORIZATION_RESPONSE";
reactContext.addActivityEventListener(this);
}
@Override
public String getName() {
return "ExampleModule";
}
@Override
public void onActivityResult(Activity activity, int requestCode, int resultCode, Intent data) {
}
@Override
public void onNewIntent(Intent intent) {
checkIntent(intent);
}
private void checkIntent(@Nullable Intent intent) {
if (intent != null) {
String action = intent.getAction();
switch (action) {
case "com.example.HANDLE_AUTHORIZATION_RESPONSE":
...
break;
default:
// do nothing
}
}
}
}