@@ -73,6 +73,7 @@ public class RNCallKeepModule extends ReactContextBaseJavaModule {
7373 public static final String ACTION_HOLD_CALL = "ACTION_HOLD_CALL" ;
7474 public static final String ACTION_UNHOLD_CALL = "ACTION_UNHOLD_CALL" ;
7575 public static final String ACTION_ONGOING_CALL = "ACTION_ONGOING_CALL" ;
76+ public static final String ACTION_AUDIO_SESSION = "ACTION_AUDIO_SESSION" ;
7677
7778 private static final String E_ACTIVITY_DOES_NOT_EXIST = "E_ACTIVITY_DOES_NOT_EXIST" ;
7879 private static final String REACT_NATIVE_MODULE_NAME = "RNCallKeep" ;
@@ -128,6 +129,21 @@ public void displayIncomingCall(String number, String callerName) {
128129 telecomManager .addNewIncomingCall (this .pah , extras );
129130 }
130131
132+ @ ReactMethod
133+ public void startCall (String number , String callerName ) {
134+ if (!this .hasPhoneAccount ()) {
135+ return ;
136+ }
137+
138+ Bundle extras = new Bundle ();
139+ Uri uri = Uri .fromParts (PhoneAccount .SCHEME_TEL , number , null );
140+
141+ extras .putParcelable (TelecomManager .EXTRA_PHONE_ACCOUNT_HANDLE , this .pah );
142+ extras .putString (EXTRA_CALLER_NAME , callerName );
143+
144+ telecomManager .placeCall (uri , extras );
145+ }
146+
131147 @ ReactMethod
132148 public void endCall () {
133149 if (!hasPhoneAccount ()) {
@@ -156,7 +172,8 @@ public void checkPhoneAccountPermission(Promise promise) {
156172 }
157173
158174 hasPhoneAccountPromise = promise ;
159- if (!this .checkPermission (Manifest .permission .READ_PHONE_STATE , REQUEST_READ_PHONE_STATE )) {
175+ String [] permissions = { Manifest .permission .READ_PHONE_STATE , Manifest .permission .CALL_PHONE };
176+ if (!this .checkPermissions (permissions , REQUEST_READ_PHONE_STATE )) {
160177 return ;
161178 }
162179
@@ -227,16 +244,22 @@ private String getApplicationName(Context appContext) {
227244 return stringId == 0 ? applicationInfo .nonLocalizedLabel .toString () : appContext .getString (stringId );
228245 }
229246
230- private Boolean checkPermission (String name , int id ) {
247+ private Boolean checkPermissions (String [] permissions , int id ) {
231248 Activity currentActivity = this .getCurrentActivity ();
232- int permissionCheck = ContextCompat .checkSelfPermission (currentActivity , name );
233249
234- if (permissionCheck != PackageManager .PERMISSION_GRANTED ) {
235- ActivityCompat .requestPermissions (currentActivity , new String []{name }, id );
236- return false ;
250+ boolean hasPermissions = true ;
251+ for (String permission : permissions ) {
252+ int permissionCheck = ContextCompat .checkSelfPermission (currentActivity , permission );
253+ if (permissionCheck != PackageManager .PERMISSION_GRANTED ) {
254+ hasPermissions = false ;
255+ }
256+ }
257+
258+ if (!hasPermissions ) {
259+ ActivityCompat .requestPermissions (currentActivity , permissions , id );
237260 }
238261
239- return true ;
262+ return hasPermissions ;
240263 }
241264
242265 private static boolean hasPhoneAccount () {
@@ -266,6 +289,7 @@ private void registerReceiver() {
266289 intentFilter .addAction (ACTION_UNHOLD_CALL );
267290 intentFilter .addAction (ACTION_HOLD_CALL );
268291 intentFilter .addAction (ACTION_ONGOING_CALL );
292+ intentFilter .addAction (ACTION_AUDIO_SESSION );
269293 LocalBroadcastManager .getInstance (this .reactContext ).registerReceiver (voiceBroadcastReceiver , intentFilter );
270294 isReceiverRegistered = true ;
271295 }
@@ -313,6 +337,9 @@ public void onReceive(Context context, Intent intent) {
313337
314338 sendEventToJS ("RNCallKeepDidReceiveStartCallAction" , args );
315339 break ;
340+ case ACTION_AUDIO_SESSION :
341+ sendEventToJS ("RNCallKeepDidActivateAudioSession" , null );
342+ break ;
316343 }
317344 }
318345 }
0 commit comments