嗨,我想为我的应用程序添加云消息。我已经完成了将Firebase与我的应用程序集成的所有必要步骤。然后,我按照youtube视频上的步骤让firebase云消息为我的应用程序工作,然后这些错误就出现了。在添加所有firebase相关代码之前,该应用程序运行良好。现在我只得到一个白色屏幕。这是我的主要。飞奔
import 'package:flutter/material.dart';
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
import 'package:get/get_navigation/src/root/get_material_app.dart';
import 'splashScreen.dart';
import 'package:firebase_core/firebase_core.dart';
import 'package:firebase_messaging/firebase_messaging.dart';
const AndroidNotificationChannel channel = AndroidNotificationChannel('high_importance_channel',
'High Importance Notifications',
importance: Importance.high,
playSound: true);
final FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin =
FlutterLocalNotificationsPlugin();
Future<void> _firebaseMessagingBackgroundHandler(RemoteMessage message) async{
await Firebase.initializeApp();
print('A bg message just showed up: ${message.messageId}');
}
Future<void> main() async{
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp();
FirebaseMessaging.onBackgroundMessage(_firebaseMessagingBackgroundHandler);
await flutterLocalNotificationsPlugin
.resolvePlatformSpecificImplementation<AndroidFlutterLocalNotificationsPlugin>()
?.createNotificationChannel(channel);
await FirebaseMessaging.instance.setForegroundNotificationPresentationOptions(
alert: true,
badge: true,
sound: true,
);
runApp(MyApp());
}
class MyApp extends StatefulWidget {
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
@override
void initState(){
super.initState();
FirebaseMessaging.onMessage.listen((RemoteMessage message){
RemoteNotification? notification = message.notification;
AndroidNotification? android = message.notification?.android;
if(notification!=null && android!=null){
flutterLocalNotificationsPlugin.show(
notification.hashCode,
notification.title,
notification.body,
NotificationDetails(
android: AndroidNotificationDetails(
channel.id,
channel.name,
color: Colors.blue,
playSound: true,
icon: '@ipmap/ic_launcher',
)
)
);
}
});
FirebaseMessaging.onMessageOpenedApp.listen((RemoteMessage message) {
print('A new onMessageOpenedApp event was published');
RemoteNotification? notification = message.notification;
AndroidNotification? android = message.notification?.android;
if(notification!=null && android!=null){
showDialog
(context: context,
builder: (_){
return AlertDialog(
title: Text(notification.title??''),
content: SingleChildScrollView(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(notification.body??'')
],
),
),
);
});
}
}
);
}
@override
Widget build(BuildContext context) {
return GetMaterialApp(
home: SplashScreen(),
);
}
}
在此之前,我遇到了另一个错误,但在我更改依赖项后得到了解决,因此这不是问题。这就是我得到的错误
E/flutter ( 3318): [ERROR:flutter/lib/ui/ui_dart_state.cc(198)] Unhandled Exception: PlatformException(channel-error, Unable to establish connection on channel., null, null)
E/flutter ( 3318): #0 FirebaseCoreHostApi.initializeCore (package:firebase_core_platform_interface/src/pigeon/messages.pigeon.dart:205:7)
E/flutter ( 3318): <asynchronous suspension>
E/flutter ( 3318): #1 MethodChannelFirebase._initializeCore (package:firebase_core_platform_interface/src/method_channel/method_channel_firebase.dart:29:44)
E/flutter ( 3318): <asynchronous suspension>
E/flutter ( 3318): #2 MethodChannelFirebase.initializeApp (package:firebase_core_platform_interface/src/method_channel/method_channel_firebase.dart:73:7)
E/flutter ( 3318): <asynchronous suspension>
E/flutter ( 3318): #3 Firebase.initializeApp (package:firebase_core/src/firebase.dart:40:31)
E/flutter ( 3318): <asynchronous suspension>
E/flutter ( 3318): #4 main (package:activepeers_app_internship/main.dart:23:3)
E/flutter ( 3318): <asynchronous suspension>
E/flutter ( 3318):
I/TRuntime.CctTransportBackend( 3318): Making request to: https://firebaselogging.googleapis.com/v0cc/log/batch?format=json_proto3
D/NetworkSecurityConfig( 3318): No Network Security Config specified, using platform default
I/TRuntime.CctTransportBackend( 3318): Status Code: 200
我能够通过更新所有firebase依赖项来修复此问题。以下命令对我有效。
flutter pub outdated
flutter pub upgrade
错误:任务“:app:ProcessDebugResources”执行失败。 com.android.ide.common.Process.processException:org.gradle.Process.internal.exeception:Process“command”c:\users\mohamed sallam\appdata\local\android\sdk\build-to
我可能已经阅读了所有其他与此相关的SO线程,但我找不到答案,而且在Android监视器中也没有日志跟踪。有人对此有提示吗?
我一直试图实现启动屏幕到我的应用程序的帮助下,许多代码可以在网站上使用,但没有一个为我工作。每次应用程序崩溃后显示启动屏幕3秒。我不知道哪里出错了,请更正我的代码,以正确显示闪屏!谢谢! //这是我的主要活动
我在项目中使用Firebase身份验证。今天我决定将FCM集成到我的项目中。但是我无法从我的Firebase控制台收到任何通知。我还尝试重新下载. json文件,但没有成功。你们知道我的问题吗? Android清单.xml FirebaseMessageService.java FirebaseIDService.java 我认为这个问题不是由我的MainActiviy.java决定的,但以防万一
这是我的activity_main.xml文件 这是我的build.gradle(模块:app)文件
我的日志猫: 2022-07-29 21:42:03.128 24303-24303/com.example。newcadviewerapp E/AndroidRuntime:致命异常:主进程:com.example。newcadviewerapp,PID:24303 java.lang.RuntimeException:无法启动活动组件信息{com.example.newcadviewerapp