[英]Flutter VoIP Push notification on Android
I am trying to implement kind of push notification for Video app.我正在尝试为视频应用实现某种推送通知。
On Flutter side I receive FCM Push notification and when this happens a function is call to handle code from native side.在 Flutter 端,我收到 FCM 推送通知,当发生这种情况时,会调用一个函数来处理来自本机端的代码。
onMessage: (Map<String, dynamic> message) async {
print('on resume $message');
await callFromAndroid();
And Future function which is being called is this:正在调用的 Future 函数是这样的:
Future<void> callFromAndroid() async
{
try {
await platform.invokeMethod('callFromAndroid');
} catch (e) {
print(e);
}
}
And on Android side this is MainActivity which should trigger VideoActivity handler...在 Android 方面,这是 MainActivity 应该触发 VideoActivity 处理程序...
public class MainActivity extends FlutterActivity {
private static final String CHANNEL = "my.test";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
GeneratedPluginRegistrant.registerWith(this);
new MethodChannel(getFlutterView(), CHANNEL).setMethodCallHandler(new MethodChannel.MethodCallHandler() {
@Override
public void onMethodCall(MethodCall methodCall, MethodChannel.Result result) {
if (methodCall.method.equals("callFromAndroid")) {
videoActivityHandler();
}
}
});
}
public void videoActivityHandler() {
Intent intent = new Intent(this, VideoCallActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
getApplicationContext().startActivity(intent);
Window window = getWindow();
window.addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
| WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON
| WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
// to release screen lock
KeyguardManager keyguardManager = (KeyguardManager) getApplicationContext().getSystemService(Context.KEYGUARD_SERVICE);
KeyguardManager.KeyguardLock keyguardLock = keyguardManager.newKeyguardLock("TAG");
keyguardLock.disableKeyguard();
}
}
However, when FCM notification arrives it arises empty activity.但是,当 FCM 通知到达时,它会出现空活动。 Also it is not working when app is in background or phone is locked.
当应用程序在后台或手机被锁定时,它也不起作用。
I am total beginner in mobile app development and have no experience in Android Native development.我完全是移动应用程序开发的初学者,没有 Android Native 开发经验。 All these code I found while doing research on this topic...
我在研究这个主题时发现的所有这些代码......
So any help is appreciated.因此,任何帮助表示赞赏。
I am too late, but...我来晚了,但是...
If you like to receive FCM push when app is on background/terminated or even in foreground you should send data
payload without notification
payload.如果您想在应用程序处于后台/终止或什至在前台时接收 FCM 推送,您应该发送没有
notification
负载的data
负载。 In this case you can handle notification in FCM's onBackgroundMessage
callback.在这种情况下,您可以在 FCM 的
onBackgroundMessage
回调中处理通知。
May be someone can find it useful.可能有人会发现它很有用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.