Skip to content

Commit

Permalink
Merge pull request #16 from linhvovan29546/fix/missing-unregister-bro…
Browse files Browse the repository at this point in the history
…adcast

Update missing code unregister broadcast, fix missing openedInComing
  • Loading branch information
linhvovan29546 authored Nov 13, 2022
2 parents 29fdc57 + 8b9d6b1 commit 332cd00
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 4 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ import RNNotificationCall from "react-native-full-screen-notification-incoming-c
#### answer event
```js
RNNotificationCall.addEventListener("answer", (payload) => {
RNNotificationCall.backToApp()
const {callUUID}=payload
console.log('press answer',callUUID)
})
Expand All @@ -175,6 +176,10 @@ import RNNotificationCall from "react-native-full-screen-notification-incoming-c
RNNotificationCall.removeEventListener("endCall")

```
#### open app from quit state
```js
RNNotificationCall.backToApp()
```

## Contributing

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,29 @@ private Context getAppContext() {
return reactContext.getApplicationContext();
}

public Activity getCurrentReactActivity() {
return this.reactContext.getCurrentActivity();
}

@ReactMethod
public void backToApp() {
Context context = getAppContext();
if (context == null) {
return;
}
String packageName = context.getApplicationContext().getPackageName();
Intent focusIntent = context.getPackageManager().getLaunchIntentForPackage(packageName).cloneFilter();
Activity activity = getCurrentReactActivity();
boolean isOpened = activity != null;
if (!isOpened) {
focusIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK +
WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED +
WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD +
WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
getReactApplicationContext().startActivity(focusIntent);
}
}

@ReactMethod
public void addListener(String eventName) {
// Keep: Required for RN built in Event Emitter Calls.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ private void acceptDialing() {
params.putString("callUUID", uuid);
FullScreenNotificationIncomingCallModule.sendEventToJs(Constants.RNNotificationAnswerAction, params);
stopService(new Intent(this, IncomingCallService.class));

if (Build.VERSION.SDK_INT >= 21) {
finishAndRemoveTask();
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ private PendingIntent onButtonNotificationClick(int id, String action,String eve
if(action == Constants.ACTION_PRESS_DECLINE_CALL){
Intent buttonIntent= new Intent();
buttonIntent.setAction(action);
return PendingIntent.getBroadcast(this,id , buttonIntent, PendingIntent.FLAG_IMMUTABLE);
return PendingIntent.getBroadcast(this,id , buttonIntent,PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE);
}
Intent emptyScreenIntent = new Intent(this, NotificationReceiverActivity.class);
emptyScreenIntent.setAction(action);
Expand Down Expand Up @@ -166,6 +166,7 @@ public void onDestroy() {
Log.d(TAG, "onDestroy service");
cancelTimer();
stopForeground(true);
unregisterBroadcastPressEvent();
}

public void registerBroadcastPressEvent() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ private static void handleNotificationIntent(Context context, Intent intent) {
switch (action) {
case Constants.onPressNotification:
if(!openedInComing) return;
canClick=false;
openedInComing=false;
handleNotificationPressIntent(context, intent);
break;
case Constants.ACTION_PRESS_ANSWER_CALL:
Expand Down
3 changes: 2 additions & 1 deletion example/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export default function App() {

RNNotificationCall.addEventListener("answer", (payload) => {
console.log('press answer', payload.callUUID)
RNNotificationCall.backToApp()
})
RNNotificationCall.addEventListener("endCall", (payload) => {
console.log('press endCall', payload.callUUID)
Expand Down Expand Up @@ -48,7 +49,7 @@ export default function App() {
)
// Cancel the timeout if necessary
BackgroundTimer.clearTimeout(timeoutId);
}, 1000);
}, 3000);

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

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-native-full-screen-notification-incoming-call",
"version": "0.1.5",
"version": "0.1.6",
"description": "Android full screen notification incoming call for React Native",
"main": "lib/commonjs/index",
"module": "lib/module/index",
Expand Down
6 changes: 6 additions & 0 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ class RNNotificationCall {
RNNotificationIncomingCall.hideNotification()
}

//function only work when open app from quit state
backToApp = () => {
if (!isAndroid) return
RNNotificationIncomingCall.backToApp()
}

addEventListener = (type: any, handler: any) => {
if (!isAndroid) return
let listener;
Expand Down

0 comments on commit 332cd00

Please sign in to comment.