1212import com .facebook .react .bridge .ReactMethod ;
1313import com .facebook .react .bridge .Callback ;
1414import com .facebook .react .bridge .Promise ;
15+ import com .facebook .react .bridge .WritableMap ;
1516
1617public class IncomingCallModule extends ReactContextBaseJavaModule {
1718
1819 public static ReactApplicationContext reactContext ;
1920 public static Activity mainActivity ;
2021
2122 private static final String TAG = "RNIC:IncomingCallModule" ;
23+ private WritableMap headlessExtras ;
2224
2325 public IncomingCallModule (ReactApplicationContext context ) {
2426 super (context );
@@ -57,11 +59,6 @@ public void display(String uuid, String name, String avatar, String info) {
5759 public void dismiss () {
5860 final Activity activity = reactContext .getCurrentActivity ();
5961
60- // if (MainActivity.active) {
61- // Intent i = new Intent(reactContext, MainActivity.class);
62- // i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
63- // reactContext.getApplicationContext().startActivity(i);
64- // }
6562 assert activity != null ;
6663 }
6764
@@ -85,22 +82,40 @@ public void backToForeground() {
8582 }
8683
8784 @ ReactMethod
88- public void getLaunchParameters (final Promise promise ) {
89- final Activity activity = getCurrentActivity ();
90- final Intent intent = activity .getIntent ();
91- Bundle b = intent .getExtras ();
92- String value = "" ;
93- if (b != null ) {
94- value = b .getString ("uuid" , "" );
85+ public void openAppFromHeadlessMode (String uuid ) {
86+ Context context = getAppContext ();
87+ String packageName = context .getApplicationContext ().getPackageName ();
88+ Intent focusIntent = context .getPackageManager ().getLaunchIntentForPackage (packageName ).cloneFilter ();
89+ Activity activity = getCurrentActivity ();
90+ boolean isOpened = activity != null ;
91+
92+ if (!isOpened ) {
93+ focusIntent .addFlags (Intent .FLAG_ACTIVITY_NEW_TASK |
94+ WindowManager .LayoutParams .FLAG_KEEP_SCREEN_ON |
95+ WindowManager .LayoutParams .FLAG_SHOW_WHEN_LOCKED |
96+ WindowManager .LayoutParams .FLAG_DISMISS_KEYGUARD |
97+ WindowManager .LayoutParams .FLAG_TURN_SCREEN_ON );
98+
99+ final WritableMap response = new WritableNativeMap ();
100+ response .putBoolean ("isHeadless" , true );
101+ response .putString ("uuid" , uuid );
102+
103+ this .headlessExtras = response ;
104+
105+ getReactApplicationContext ().startActivity (focusIntent );
95106 }
96- promise .resolve (value );
97107 }
98108
99109 @ ReactMethod
100- public void clearLaunchParameters () {
101- final Activity activity = getCurrentActivity ();
102- final Intent intent = activity .getIntent ();
103- Bundle b = new Bundle ();
104- intent .putExtras (b );
110+ public void getExtrasFromHeadlessMode (Promise promise ) {
111+ if (this .headlessExtras != null ) {
112+ promise .resolve (this .headlessExtras );
113+
114+ this .headlessExtras = null ;
115+
116+ return ;
117+ }
118+
119+ promise .resolve (null );
105120 }
106121}
0 commit comments