Comments (12)
I simply did something but I cannot get it to work when the application is closed.
OneSignalPush.java file:
@Override
public void notificationReceived(OSNotification notification) {
try {
if (notification.payload.additionalData.getJSONObject("Caller") != null) {
JSONObject data = notification.payload.additionalData.getJSONObject("Caller");
System.out.println(data.getString("Username"));
System.out.println(data.getString("ConnectionId"));
CordovaCall.getInstance().notificationAccept(data.getString("Username"));
}
} catch (JSONException e) {
e.printStackTrace();
}
try {
CallbackHelper.callbackSuccess(jsNotificationReceivedCallBack, new JSONObject(notification.stringify()));
}
catch (Throwable t) {
t.printStackTrace();
}
}
CordovaCall.java file:
public void notificationAccept(String username) {
from = username;
permissionCounter = 2;
pendingAction = "receiveCall";
this.checkCallPermission();
}
from cordova-plugin-callkit.
You need to specify what to do after you receive the notification. In this case, you need to force the app to open upon receiving the notification. This is as far as I go. The rest is native implementation.
from cordova-plugin-callkit.
With the application closed, I was able to receive and process the notification. The problem is auto start.
firebase/quickstart-android#822 (comment)
I don't know much about Java, so I wrote a simple code. If I try to open the call acceptance screen with the code I wrote, I get this error.
2020-11-12 14:45:35.977 18947-19005/? E/AndroidRuntime: FATAL EXCEPTION: Firebase-MyFirebaseMessagingService
Process: com.blabla.blabla, PID: 18947
java.lang.NullPointerException: Attempt to invoke virtual method 'void com.dmarc.cordovacall.CordovaCall.notificationAccept()' on a null object reference
at com.gae.scaffolder.plugin.MyFirebaseMessagingService.onMessageReceived(MyFirebaseMessagingService.java:42)
at com.google.firebase.messaging.FirebaseMessagingService.zzc(com.google.firebase:firebase-messaging@@20.0.0:68)
at com.google.firebase.messaging.zze.run(com.google.firebase:firebase-messaging@@20.0.0:2)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at com.google.android.gms.common.util.concurrent.zza.run(Unknown Source:6)
at java.lang.Thread.run(Thread.java:764)
I don't fully understand the issue of starting the application.
from cordova-plugin-callkit.
Well, I went a little further. It doesn't crash anymore but I can't show any call acceptance screens either.
MyFirebaseMessagingService.java
public void onMessageReceived(RemoteMessage remoteMessage) {
// TODO(developer): Handle FCM messages here.
// If the application is in the foreground handle both data and notification messages here.
// Also if you intend on generating your own notifications as a result of a received FCM
// message, here is where that should be initiated. See sendNotification method below.
Log.d(TAG, "==> MyFirebaseMessagingService onMessageReceived");
String packageName = getApplicationContext().getPackageName();
String className = MyFirebaseMessagingService.class.getName();
ComponentName componentName = new ComponentName(packageName, className);
TelecomManager telecomManager = (TelecomManager)this.getSystemService(Context.TELECOM_SERVICE);
PhoneAccountHandle handle = new PhoneAccountHandle(componentName, "MyApp");
PhoneAccount phoneAccount;
if(android.os.Build.VERSION.SDK_INT >= 26) {
phoneAccount = new PhoneAccount.Builder(handle, "MyApp")
.setCapabilities(PhoneAccount.CAPABILITY_SELF_MANAGED)
.build();
telecomManager.registerPhoneAccount(phoneAccount);
}
if(android.os.Build.VERSION.SDK_INT >= 23) {
phoneAccount = new PhoneAccount.Builder(handle, "MyApp")
.setCapabilities(PhoneAccount.CAPABILITY_CALL_PROVIDER)
.build();
telecomManager.registerPhoneAccount(phoneAccount);
}
Bundle extras = new Bundle();
extras.putParcelable(TelecomManager.EXTRA_PHONE_ACCOUNT_HANDLE, handle);
extras.putInt(TelecomManager.EXTRA_START_CALL_WITH_VIDEO_STATE, VideoProfile.STATE_BIDIRECTIONAL);
telecomManager.addNewIncomingCall(handle, extras);
if(remoteMessage.getNotification() != null){
Log.d(TAG, "\tNotification Title: " + remoteMessage.getNotification().getTitle());
Log.d(TAG, "\tNotification Message: " + remoteMessage.getNotification().getBody());
}
Map<String, Object> data = new HashMap<String, Object>();
data.put("wasTapped", false);
if(remoteMessage.getNotification() != null){
data.put("title", remoteMessage.getNotification().getTitle());
data.put("body", remoteMessage.getNotification().getBody());
}
for (String key : remoteMessage.getData().keySet()) {
Object value = remoteMessage.getData().get(key);
Log.d(TAG, "\tKey: " + key + " Value: " + value);
data.put(key, value);
}
Log.d(TAG, "\tNotification Data: " + data.toString());
FCMPlugin.sendPushPayload(data);
}
AndroidManifest.xml
<service android:name="com.gae.scaffolder.plugin.MyFirebaseMessagingService" android:permission="android.permission.BIND_TELECOM_CONNECTION_SERVICE" android:stopWithTask="false">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
<intent-filter>
<action android:name="android.telecom.ConnectionService" />
</intent-filter>
</service>
Edit:
Console output after sending the notification.
2020-11-12 19:37:17.695 1423-1446/? I/Telecom: PhoneAccountRegistrar: Modify account: [ComponentInfo{com.blabla.blabla/com.gae.scaffolder.plugin.MyFirebaseMessagingService}, ***, UserHandle{0}]: TSI.rPA@LV0
2020-11-12 19:37:17.704 1423-4211/? I/Telecom: : Adding new incoming call with phoneAccountHandle ComponentInfo{com.blabla.blabla/com.gae.scaffolder.plugin.MyFirebaseMessagingService}, ***, UserHandle{0}: TSI.aNIC@LV4
2020-11-12 19:37:17.710 1423-4211/? I/Telecom: PhoneAccountRegistrar: SimCallManager queried, returning: null: TSI.aNIC@LV4
2020-11-12 19:37:17.710 1423-4211/? I/Telecom: Call: CallerInfo lookup returned null, skipping update: TSI.aNIC@LV4
2020-11-12 19:37:17.711 1423-4211/? I/Telecom: LogUtils: EventRecord added as Call: [TC@42, NEW, null, null, A, childs(0), has_parent(false), [Capabilities:], [Properties:]]: TSI.aNIC@LV4
2020-11-12 19:37:17.712 1423-4211/? I/Telecom: Event: RecordEntry TC@42: CREATED, null: TSI.aNIC@LV4
2020-11-12 19:37:17.717 1423-4211/? I/Telecom: PhoneAccountRegistrar: SimCallManager queried, returning: null: TSI.aNIC@LV4
2020-11-12 19:37:17.717 1423-4211/? I/Telecom: CreateConnectionProcessor: Trying attempt CallAttemptRecord(ComponentInfo{com.blabla.blabla/com.gae.scaffolder.plugin.MyFirebaseMessagingService}, ***, UserHandle{0},ComponentInfo{com.blabla.blabla/com.gae.scaffolder.plugin.MyFirebaseMessagingService}, ***, UserHandle{0}): TSI.aNIC@LV4
2020-11-12 19:37:17.718 1423-4211/? I/Telecom: Event: RecordEntry TC@42: START_CONNECTION, null: TSI.aNIC@LV4
from cordova-plugin-callkit.
I see that you are using OneSignal. You don't need to implement everything in native. Just use native code to force the app to open and handle it in Cordova. Pretty straightforward. The only downside is that you might need to adjust the styles so that it looks like it is opened transparently. Leverage the background notifications feature in OneSignal.
from cordova-plugin-callkit.
I see that you are using OneSignal. You don't need to implement everything in native. Just use native code to force the app to open and handle it in Cordova. Pretty straightforward. The only downside is that you might need to adjust the styles so that it looks like it is opened transparently. Leverage the background notifications feature in OneSignal.
It is said that this is a bad experience. I still can't find how to do it.
from cordova-plugin-callkit.
I managed to start the application. However, this does not seem like a nice method.
Intent intent = new Intent(this, MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
from cordova-plugin-callkit.
It is said that this is a bad experience. I still can't find how to do it.
Just a part of learning. You'll eventually find the solution. Imagine me going through this without any help or resource.
I managed to start the application. However, this does not seem like a nice method.
Intent intent = new Intent(this, MainActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(intent);
This is a complete legit solution by the way. Just tweak your styles a bit to fit your current criteria.
from cordova-plugin-callkit.
Thank you for your support. I just did not fully understand what you mean by this sentence.
Just tweak your styles a bit to fit your current criteria.
from cordova-plugin-callkit.
Thank you for your support. I just did not fully understand what you mean by this sentence.
Just tweak your styles a bit to fit your current criteria.
What I meant by styles here is Android style. You can change the appearance of your app by changing various options given in Android.
Did you notice that on startup, every Android app will start with a black screen? In my case, I modified it so that it will startup in the background once the notification is received. Otherwise, it will be very weird to see a black screen first then the call UI if the app is started up from closed state.
from cordova-plugin-callkit.
Got it, thank you again for everything. I am closing the subject because I solved my problem. I'll prepare a small document for android if I have time.
from cordova-plugin-callkit.
Got it, thank you again for everything. I am closing the subject because I solved my problem. I'll prepare a small document for android if I have time.
Glad it worked out for you.
from cordova-plugin-callkit.
Related Issues (15)
- init function is not called HOT 5
- An incoming call is instantly rejected HOT 1
- Can't cancel VoIP notification when application killed [iOS] HOT 8
- Ionic use HOT 5
- Not able to handle calls in webrtc/js HOT 13
- Answering phone crashes the app HOT 8
- Plugin still in use? We've updated the VoIP Call Code for our purposes / Video calls... HOT 3
- ReferenceError: Can't find variable: VoIPPushNotification
- Payload Data field not working? HOT 1
- App Does not seem to receive notifications when in background or killed HOT 38
- Does the application run when closed? HOT 2
- Callkit does not trigger HOT 2
- [Help wanted] Firebasex plugin integration HOT 3
- Custom UI onReceiveCall HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cordova-plugin-callkit.