I want to start some native code in Android when I receive a firebase message (FCM), but I get this error:
<code>E/flutter (16352): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: MissingPluginException(No implementation found for method wakeUpApp on channel com.diesetelecom.smartdiese.androidChannel)
E/flutter (16352): #0 MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:332:7)
E/flutter (16352): <asynchronous suspension>
</code>
<code>E/flutter (16352): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: MissingPluginException(No implementation found for method wakeUpApp on channel com.diesetelecom.smartdiese.androidChannel)
E/flutter (16352): #0 MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:332:7)
E/flutter (16352): <asynchronous suspension>
</code>
E/flutter (16352): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: MissingPluginException(No implementation found for method wakeUpApp on channel com.diesetelecom.smartdiese.androidChannel)
E/flutter (16352): #0 MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:332:7)
E/flutter (16352): <asynchronous suspension>
I already try to uninstall the app -> flutter clean -> flutter pub get -> flutter run
but unsuccessfully
Here is my code in flutter in my main.dart, I tried to remove “com.diesetelecom.smartdiese” to keep “androidChannel” but i’m still having the error.
<code>@pragma('vm:entry-point')
Future<void> firebaseMessagingBackgroundHandler(RemoteMessage message) async {
...
const MethodChannel androidChannel = MethodChannel('com.diesetelecom.smartdiese.androidChannel');
androidChannel.invokeMethod("wakeUpApp");
}
Future<void> main() async {
...
FirebaseMessaging.onBackgroundMessage(firebaseMessagingBackgroundHandler);
...
await AssetsManager.initAssets();
await dotenv.load();
runApp(const App());
}
</code>
<code>@pragma('vm:entry-point')
Future<void> firebaseMessagingBackgroundHandler(RemoteMessage message) async {
...
const MethodChannel androidChannel = MethodChannel('com.diesetelecom.smartdiese.androidChannel');
androidChannel.invokeMethod("wakeUpApp");
}
Future<void> main() async {
...
FirebaseMessaging.onBackgroundMessage(firebaseMessagingBackgroundHandler);
...
await AssetsManager.initAssets();
await dotenv.load();
runApp(const App());
}
</code>
@pragma('vm:entry-point')
Future<void> firebaseMessagingBackgroundHandler(RemoteMessage message) async {
...
const MethodChannel androidChannel = MethodChannel('com.diesetelecom.smartdiese.androidChannel');
androidChannel.invokeMethod("wakeUpApp");
}
Future<void> main() async {
...
FirebaseMessaging.onBackgroundMessage(firebaseMessagingBackgroundHandler);
...
await AssetsManager.initAssets();
await dotenv.load();
runApp(const App());
}
Here is my MainActivity.kt, knowing that I have this error when I try to call the Android method from the firebaseMessagingBackgroundHandler but it works outside
<code>package com.diesetelecom.smart_diese
import android.content.Context
import android.content.Intent
import android.media.AudioManager
import androidx.annotation.NonNull
import io.flutter.embedding.android.FlutterActivity
import io.flutter.embedding.engine.FlutterEngine
import io.flutter.plugin.common.MethodCall
import io.flutter.plugin.common.MethodChannel
import android.util.Log
class MainActivity: FlutterActivity() {
private val CHANNEL = "androidChannel"
override fun configureFlutterEngine(@NonNull flutterEngine: FlutterEngine) {
super.configureFlutterEngine(flutterEngine)
MethodChannel(flutterEngine.dartExecutor.binaryMessenger, CHANNEL).setMethodCallHandler { call, result ->
if (call.method == "switchAudioOutput") {
val audioManager: AudioManager = getApplicationContext().getSystemService(Context.AUDIO_SERVICE) as AudioManager
audioManager.setMode(AudioManager.MODE_IN_CALL)
audioManager.setSpeakerphoneOn(!audioManager.isSpeakerphoneOn)
result.success(audioManager.isSpeakerphoneOn)
} else if(call.method == "wakeUpApp") {
Log.d("ActivityMain", "This is a small test text")
result.success(true)
} else {
result.notImplemented()
}
}
}
}
</code>
<code>package com.diesetelecom.smart_diese
import android.content.Context
import android.content.Intent
import android.media.AudioManager
import androidx.annotation.NonNull
import io.flutter.embedding.android.FlutterActivity
import io.flutter.embedding.engine.FlutterEngine
import io.flutter.plugin.common.MethodCall
import io.flutter.plugin.common.MethodChannel
import android.util.Log
class MainActivity: FlutterActivity() {
private val CHANNEL = "androidChannel"
override fun configureFlutterEngine(@NonNull flutterEngine: FlutterEngine) {
super.configureFlutterEngine(flutterEngine)
MethodChannel(flutterEngine.dartExecutor.binaryMessenger, CHANNEL).setMethodCallHandler { call, result ->
if (call.method == "switchAudioOutput") {
val audioManager: AudioManager = getApplicationContext().getSystemService(Context.AUDIO_SERVICE) as AudioManager
audioManager.setMode(AudioManager.MODE_IN_CALL)
audioManager.setSpeakerphoneOn(!audioManager.isSpeakerphoneOn)
result.success(audioManager.isSpeakerphoneOn)
} else if(call.method == "wakeUpApp") {
Log.d("ActivityMain", "This is a small test text")
result.success(true)
} else {
result.notImplemented()
}
}
}
}
</code>
package com.diesetelecom.smart_diese
import android.content.Context
import android.content.Intent
import android.media.AudioManager
import androidx.annotation.NonNull
import io.flutter.embedding.android.FlutterActivity
import io.flutter.embedding.engine.FlutterEngine
import io.flutter.plugin.common.MethodCall
import io.flutter.plugin.common.MethodChannel
import android.util.Log
class MainActivity: FlutterActivity() {
private val CHANNEL = "androidChannel"
override fun configureFlutterEngine(@NonNull flutterEngine: FlutterEngine) {
super.configureFlutterEngine(flutterEngine)
MethodChannel(flutterEngine.dartExecutor.binaryMessenger, CHANNEL).setMethodCallHandler { call, result ->
if (call.method == "switchAudioOutput") {
val audioManager: AudioManager = getApplicationContext().getSystemService(Context.AUDIO_SERVICE) as AudioManager
audioManager.setMode(AudioManager.MODE_IN_CALL)
audioManager.setSpeakerphoneOn(!audioManager.isSpeakerphoneOn)
result.success(audioManager.isSpeakerphoneOn)
} else if(call.method == "wakeUpApp") {
Log.d("ActivityMain", "This is a small test text")
result.success(true)
} else {
result.notImplemented()
}
}
}
}