Skip to content

Commit c24062e

Browse files
feat: add getActivityLaunchOptions() to the module
1 parent 9259bf7 commit c24062e

File tree

2 files changed

+29
-25
lines changed

2 files changed

+29
-25
lines changed

README.md

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ Add the following blocks to your app's `MainActivity`:
103103
104104
```java
105105
106-
import com.hoxfon.react.RNTwilioVoice.Constants;
106+
import com.hoxfon.react.RNTwilioVoice.TwilioModule;
107107
...
108108
109109
public class MainActivity extends ReactActivity {
@@ -117,30 +117,7 @@ public class MainActivity extends ReactActivity {
117117
}
118118
@Override
119119
protected Bundle getLaunchOptions() {
120-
Bundle initialProperties = new Bundle();
121-
Intent intent = this.getPlainActivity().getIntent();
122-
if (intent == null || intent.getAction() == null) {
123-
return initialProperties;
124-
}
125-
switch (intent.getAction()) {
126-
case Constants.ACTION_INCOMING_CALL_NOTIFICATION:
127-
Bundle callInviteBundle = new Bundle();
128-
callInviteBundle.putString(Constants.CALL_SID, intent.getStringExtra(Constants.CALL_SID));
129-
callInviteBundle.putString(Constants.CALL_FROM, intent.getStringExtra(Constants.CALL_FROM));
130-
callInviteBundle.putString(Constants.CALL_TO, intent.getStringExtra(Constants.CALL_TO));
131-
initialProperties.putBundle(Constants.CALL_INVITE_KEY, callInviteBundle);
132-
break;
133-
134-
case Constants.ACTION_ACCEPT:
135-
Bundle callBundle = new Bundle();
136-
callBundle.putString(Constants.CALL_SID, intent.getStringExtra(Constants.CALL_SID));
137-
callBundle.putString(Constants.CALL_FROM, intent.getStringExtra(Constants.CALL_FROM));
138-
callBundle.putString(Constants.CALL_TO, intent.getStringExtra(Constants.CALL_TO));
139-
callBundle.putString(Constants.CALL_STATE, Constants.CALL_STATE_CONNECTED);
140-
initialProperties.putBundle(Constants.CALL_KEY, callBundle);
141-
break;
142-
}
143-
return initialProperties;
120+
return TwilioModule.getActivityLaunchOption(this.getPlainActivity().getIntent());
144121
}
145122
};
146123
}

android/src/main/java/com/hoxfon/react/RNTwilioVoice/TwilioVoiceModule.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
import androidx.core.app.ActivityCompat;
1919
import androidx.core.content.ContextCompat;
2020
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
21+
22+
import android.os.Bundle;
2123
import android.util.Log;
2224
import android.view.Window;
2325
import android.view.WindowManager;
@@ -858,4 +860,29 @@ private void requestPermissionForMicrophone() {
858860
ActivityCompat.requestPermissions(getCurrentActivity(), new String[]{Manifest.permission.RECORD_AUDIO}, MIC_PERMISSION_REQUEST_CODE);
859861
}
860862
}
863+
864+
public static Bundle getActivityLaunchOption(Intent intent) {
865+
Bundle initialProperties = new Bundle();
866+
if (intent == null || intent.getAction() == null) {
867+
return initialProperties;
868+
}
869+
Bundle callBundle = new Bundle();
870+
switch (intent.getAction()) {
871+
case Constants.ACTION_INCOMING_CALL_NOTIFICATION:
872+
callBundle.putString(Constants.CALL_SID, intent.getStringExtra(Constants.CALL_SID));
873+
callBundle.putString(Constants.CALL_FROM, intent.getStringExtra(Constants.CALL_FROM));
874+
callBundle.putString(Constants.CALL_TO, intent.getStringExtra(Constants.CALL_TO));
875+
initialProperties.putBundle(Constants.CALL_INVITE_KEY, callBundle);
876+
break;
877+
878+
case Constants.ACTION_ACCEPT:
879+
callBundle.putString(Constants.CALL_SID, intent.getStringExtra(Constants.CALL_SID));
880+
callBundle.putString(Constants.CALL_FROM, intent.getStringExtra(Constants.CALL_FROM));
881+
callBundle.putString(Constants.CALL_TO, intent.getStringExtra(Constants.CALL_TO));
882+
callBundle.putString(Constants.CALL_STATE, Constants.CALL_STATE_CONNECTED);
883+
initialProperties.putBundle(Constants.CALL_KEY, callBundle);
884+
break;
885+
}
886+
return initialProperties;
887+
}
861888
}

0 commit comments

Comments
 (0)