Skip to content

Commit eec7da7

Browse files
feat: add getActivityLaunchOptions() to the module
1 parent c818045 commit eec7da7

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
@@ -104,7 +104,7 @@ Add the following blocks to your app's `MainActivity`:
104104

105105
```java
106106

107-
import com.hoxfon.react.RNTwilioVoice.Constants;
107+
import com.hoxfon.react.RNTwilioVoice.TwilioModule;
108108
...
109109

110110
public class MainActivity extends ReactActivity {
@@ -118,30 +118,7 @@ public class MainActivity extends ReactActivity {
118118
}
119119
@Override
120120
protected Bundle getLaunchOptions() {
121-
Bundle initialProperties = new Bundle();
122-
Intent intent = this.getPlainActivity().getIntent();
123-
if (intent == null || intent.getAction() == null) {
124-
return initialProperties;
125-
}
126-
switch (intent.getAction()) {
127-
case Constants.ACTION_INCOMING_CALL_NOTIFICATION:
128-
Bundle callInviteBundle = new Bundle();
129-
callInviteBundle.putString(Constants.CALL_SID, intent.getStringExtra(Constants.CALL_SID));
130-
callInviteBundle.putString(Constants.CALL_FROM, intent.getStringExtra(Constants.CALL_FROM));
131-
callInviteBundle.putString(Constants.CALL_TO, intent.getStringExtra(Constants.CALL_TO));
132-
initialProperties.putBundle(Constants.CALL_INVITE_KEY, callInviteBundle);
133-
break;
134-
135-
case Constants.ACTION_ACCEPT:
136-
Bundle callBundle = new Bundle();
137-
callBundle.putString(Constants.CALL_SID, intent.getStringExtra(Constants.CALL_SID));
138-
callBundle.putString(Constants.CALL_FROM, intent.getStringExtra(Constants.CALL_FROM));
139-
callBundle.putString(Constants.CALL_TO, intent.getStringExtra(Constants.CALL_TO));
140-
callBundle.putString(Constants.CALL_STATE, Constants.CALL_STATE_CONNECTED);
141-
initialProperties.putBundle(Constants.CALL_KEY, callBundle);
142-
break;
143-
}
144-
return initialProperties;
121+
return TwilioModule.getActivityLaunchOption(this.getPlainActivity().getIntent());
145122
}
146123
};
147124
}

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)