Closed
Description
E/MethodChannel#plugins.flutter.io/firebase_messaging(13851): Failed to handle method call
E/MethodChannel#plugins.flutter.io/firebase_messaging(13851): java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.Intent android.app.Activity.getIntent()' on a null object reference
E/MethodChannel#plugins.flutter.io/firebase_messaging(13851): at com.dexterous.flutterlocalnotifications.FlutterLocalNotificationsPlugin.setActivity(FlutterLocalNotificationsPlugin.java:780)
E/MethodChannel#plugins.flutter.io/firebase_messaging(13851): at com.dexterous.flutterlocalnotifications.FlutterLocalNotificationsPlugin.registerWith(FlutterLocalNotificationsPlugin.java:116)
E/MethodChannel#plugins.flutter.io/firebase_messaging(13851): at io.flutter.plugins.GeneratedPluginRegistrant.registerWith(GeneratedPluginRegistrant.java:43)
E/MethodChannel#plugins.flutter.io/firebase_messaging(13851): at mobihub.mobihub.Application.registerWith(Application.java:19)
E/MethodChannel#plugins.flutter.io/firebase_messaging(13851): at io.flutter.plugins.firebasemessaging.FlutterFirebaseMessagingService.startBackgroundIsolate(FlutterFirebaseMessagingService.java:164)
E/MethodChannel#plugins.flutter.io/firebase_messaging(13851): at io.flutter.plugins.firebasemessaging.FirebaseMessagingPlugin.onMethodCall(FirebaseMessagingPlugin.java:176)
E/MethodChannel#plugins.flutter.io/firebase_messaging(13851): at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:226)
E/MethodChannel#plugins.flutter.io/firebase_messaging(13851): at io.flutter.embedding.engine.dart.DartMessenger.handleMessageFromDart(DartMessenger.java:85)
E/MethodChannel#plugins.flutter.io/firebase_messaging(13851): at io.flutter.embedding.engine.FlutterJNI.handlePlatformMessage(FlutterJNI.java:631)
E/MethodChannel#plugins.flutter.io/firebase_messaging(13851): at android.os.MessageQueue.nativePollOnce(Native Method)
E/MethodChannel#plugins.flutter.io/firebase_messaging(13851): at android.os.MessageQueue.next(MessageQueue.java:326)
E/MethodChannel#plugins.flutter.io/firebase_messaging(13851): at android.os.Looper.loop(Looper.java:165)
E/MethodChannel#plugins.flutter.io/firebase_messaging(13851): at android.app.ActivityThread.main(ActivityThread.java:6861)
E/MethodChannel#plugins.flutter.io/firebase_messaging(13851): at java.lang.reflect.Method.invoke(Native Method)
E/MethodChannel#plugins.flutter.io/firebase_messaging(13851): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547)
E/MethodChannel#plugins.flutter.io/firebase_messaging(13851): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:873)
E/flutter (13851): [ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: PlatformException(error, Attempt to invoke virtual method 'android.content.Intent android.app.Activity.getIntent()' on a null object reference, null)
This is my Application.java Class
public class Application extends FlutterApplication implements PluginRegistrantCallback {
@Override
public void onCreate() {
super.onCreate();
FlutterFirebaseMessagingService.setPluginRegistrant(this);
}
@Override
public void registerWith(PluginRegistry registry) {
GeneratedPluginRegistrant.registerWith(registry);
}
}
This is manifest class
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="mobihub.mobihub">
<!-- io.flutter.app.FlutterApplication is an android.app.Application that
calls FlutterMain.startInitialization(this); in its onCreate method.
In most cases you can leave this as-is, but you if you want to provide
additional functionality it is fine to subclass or reimplement
FlutterApplication and put your custom class here. -->
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<application android:name=".Application"
android:label="mobihub"
android:icon="@mipmap/ic_launcher">
<meta-data
android:name="com.google.firebase.messaging.default_notification_channel_id"
android:value="@string/notification_channel_id"/>
<activity
android:name=".MainActivity"
android:launchMode="singleTop"
android:theme="@style/LaunchTheme"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
android:hardwareAccelerated="true"
android:windowSoftInputMode="adjustResize"
tools:ignore="Instantiatable">
<!-- This keeps the window background of the activity showing
until Flutter renders its first frame. It can be removed if
there is no splash screen (such as the default splash screen
defined in @style/LaunchTheme). -->
<meta-data
android:name="io.flutter.app.android.SplashScreenUntilFirstFrame"
android:value="true" />
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
<intent-filter>
<action android:name="FLUTTER_NOTIFICATION_CLICK" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<service android:name="com.google.firebase.components.ComponentDiscoveryService"
tools:ignore="MissingClass">
<meta-data
android:name="com.google.firebase.components:com.google.firebase.iid.Registrar"
android:value="com.google.firebase.components.ComponentRegistrar" />
</service>
<activity
android:name="com.yalantis.ucrop.UCropActivity"
android:screenOrientation="portrait"
android:theme="@style/Theme.AppCompat.Light.NoActionBar"/>
</application>
</manifest>
build.gradle
buildscript {
repositories {
google()
jcenter()
}
dependencies {
//noinspection GradleDependency
classpath 'com.android.tools.build:gradle:3.5.3'
// Add the google services classpath
// classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.google.gms:google-services:4.3.3'
}
}
allprojects {
repositories {
google()
jcenter()
}
}
rootProject.buildDir = '../build'
subprojects {
project.buildDir = "${rootProject.buildDir}/${project.name}"
}
subprojects {
project.evaluationDependsOn(':app')
}
task clean(type: Delete) {
delete rootProject.buildDir
}
MainClass
void fcmConfigure() {
_firebaseMessaging.configure(
onMessage: (Map<String, dynamic> message) async {
print('getting');
print("fcmConfigure _firebaseMessaging onMessage: $message");
print("fcmConfigure _firebaseMessaging onMessage: ${message['data']['url']}");
// _showItemDialog(message);
String title = message['data']['user_name'];
String body = message['data']['message'];
showNotification(title,body);
// Fluttertoast.showToast(msg: '$message', backgroundColor: Colors.red);
},
onBackgroundMessage: myBackgroundMessageHandler,
onLaunch: (Map<String, dynamic> message) async {
print("fcmConfigure _firebaseMessaging onLaunch: $message");
Fluttertoast.showToast(msg: '$message', backgroundColor: Colors.amber);
//_showNotificationWithDefaultSound();
// showNotification();
// _navigateToItemDetail(message);
},
onResume: (Map<String, dynamic> message) async {
print("fcmConfigure _firebaseMessaging onResume: $message");
Fluttertoast.showToast(msg: '$message', backgroundColor: Colors.green);
// _navigateToItemDetail(message);
},
);
permissions();
}
static Future<dynamic> myBackgroundMessageHandler(Map<String, dynamic> message) {
if (message.containsKey('data')) {
// Handle data message
final dynamic data = message['data'];
print('Background');
print(data);
_showNotification();
}
}