Skip to content

Commit 332cd00

Browse files
Merge pull request #16 from linhvovan29546/fix/missing-unregister-broadcast
Update missing code unregister broadcast, fix missing openedInComing
2 parents 29fdc57 + 8b9d6b1 commit 332cd00

File tree

8 files changed

+41
-4
lines changed

8 files changed

+41
-4
lines changed

README.md

+5
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ import RNNotificationCall from "react-native-full-screen-notification-incoming-c
156156
#### answer event
157157
```js
158158
RNNotificationCall.addEventListener("answer", (payload) => {
159+
RNNotificationCall.backToApp()
159160
const {callUUID}=payload
160161
console.log('press answer',callUUID)
161162
})
@@ -175,6 +176,10 @@ import RNNotificationCall from "react-native-full-screen-notification-incoming-c
175176
RNNotificationCall.removeEventListener("endCall")
176177

177178
```
179+
#### open app from quit state
180+
```js
181+
RNNotificationCall.backToApp()
182+
```
178183

179184
## Contributing
180185

android/src/main/java/com/reactnativefullscreennotificationincomingcall/FullScreenNotificationIncomingCallModule.java

+23
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,29 @@ private Context getAppContext() {
7878
return reactContext.getApplicationContext();
7979
}
8080

81+
public Activity getCurrentReactActivity() {
82+
return this.reactContext.getCurrentActivity();
83+
}
84+
85+
@ReactMethod
86+
public void backToApp() {
87+
Context context = getAppContext();
88+
if (context == null) {
89+
return;
90+
}
91+
String packageName = context.getApplicationContext().getPackageName();
92+
Intent focusIntent = context.getPackageManager().getLaunchIntentForPackage(packageName).cloneFilter();
93+
Activity activity = getCurrentReactActivity();
94+
boolean isOpened = activity != null;
95+
if (!isOpened) {
96+
focusIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK +
97+
WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED +
98+
WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD +
99+
WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
100+
getReactApplicationContext().startActivity(focusIntent);
101+
}
102+
}
103+
81104
@ReactMethod
82105
public void addListener(String eventName) {
83106
// Keep: Required for RN built in Event Emitter Calls.

android/src/main/java/com/reactnativefullscreennotificationincomingcall/IncomingCallActivity.java

+1
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ private void acceptDialing() {
161161
params.putString("callUUID", uuid);
162162
FullScreenNotificationIncomingCallModule.sendEventToJs(Constants.RNNotificationAnswerAction, params);
163163
stopService(new Intent(this, IncomingCallService.class));
164+
164165
if (Build.VERSION.SDK_INT >= 21) {
165166
finishAndRemoveTask();
166167
} else {

android/src/main/java/com/reactnativefullscreennotificationincomingcall/IncomingCallService.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ private PendingIntent onButtonNotificationClick(int id, String action,String eve
8080
if(action == Constants.ACTION_PRESS_DECLINE_CALL){
8181
Intent buttonIntent= new Intent();
8282
buttonIntent.setAction(action);
83-
return PendingIntent.getBroadcast(this,id , buttonIntent, PendingIntent.FLAG_IMMUTABLE);
83+
return PendingIntent.getBroadcast(this,id , buttonIntent,PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE);
8484
}
8585
Intent emptyScreenIntent = new Intent(this, NotificationReceiverActivity.class);
8686
emptyScreenIntent.setAction(action);
@@ -166,6 +166,7 @@ public void onDestroy() {
166166
Log.d(TAG, "onDestroy service");
167167
cancelTimer();
168168
stopForeground(true);
169+
unregisterBroadcastPressEvent();
169170
}
170171

171172
public void registerBroadcastPressEvent() {

android/src/main/java/com/reactnativefullscreennotificationincomingcall/NotificationReceiverHandler.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ private static void handleNotificationIntent(Context context, Intent intent) {
3737
switch (action) {
3838
case Constants.onPressNotification:
3939
if(!openedInComing) return;
40-
canClick=false;
40+
openedInComing=false;
4141
handleNotificationPressIntent(context, intent);
4242
break;
4343
case Constants.ACTION_PRESS_ANSWER_CALL:

example/src/App.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export default function App() {
99

1010
RNNotificationCall.addEventListener("answer", (payload) => {
1111
console.log('press answer', payload.callUUID)
12+
RNNotificationCall.backToApp()
1213
})
1314
RNNotificationCall.addEventListener("endCall", (payload) => {
1415
console.log('press endCall', payload.callUUID)
@@ -48,7 +49,7 @@ export default function App() {
4849
)
4950
// Cancel the timeout if necessary
5051
BackgroundTimer.clearTimeout(timeoutId);
51-
}, 1000);
52+
}, 3000);
5253

5354
//rest of code will be performing for iOS on background too
5455

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-native-full-screen-notification-incoming-call",
3-
"version": "0.1.5",
3+
"version": "0.1.6",
44
"description": "Android full screen notification incoming call for React Native",
55
"main": "lib/commonjs/index",
66
"module": "lib/module/index",

src/index.tsx

+6
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@ class RNNotificationCall {
3636
RNNotificationIncomingCall.hideNotification()
3737
}
3838

39+
//function only work when open app from quit state
40+
backToApp = () => {
41+
if (!isAndroid) return
42+
RNNotificationIncomingCall.backToApp()
43+
}
44+
3945
addEventListener = (type: any, handler: any) => {
4046
if (!isAndroid) return
4147
let listener;

0 commit comments

Comments
 (0)