skip to Main Content
void main() async{
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp(
  options: DefaultFirebaseOptions.currentPlatform
);
final _firebaseMessaing = FirebaseMessaging.instance;
await _firebaseMessaing.requestPermission();

final fCMToken = await _firebaseMessaing.getToken();
print("This is token =========> ${fCMToken}");

runApp(MyApp());
}

Here I want the token but some errors occurs and the Token does not print. Not getting why I am facing this problem?

Unhandled Exception: [firebase_messaging/unknown] java.io.IOException: SERVICE_NOT_AVAILABLE

  E/flutter (17731): #0      StandardMethodCodec.decodeEnvelope 
(package:flutter/src/services/message_codecs.dart:651:7)
 E/flutter (17731): #1      MethodChannel._invokeMethod 
 (package:flutter/src/services/platform_channel.dart:322:18)
 E/flutter (17731): <asynchronous suspension>
 E/flutter (17731): #2      MethodChannel.invokeMapMethod 
 (package:flutter/src/services/platform_channel.dart:522:43)
 E/flutter (17731): <asynchronous suspension>
 E/flutter (17731): #3      MethodChannelFirebaseMessaging.getToken

2

Answers


  1. Chosen as BEST ANSWER

    Got the answer to this. Mainly shit issue appeared because of my emulator issue. Because google services were being stopped for some issue. Reinstalling emulator and also updating emulator from SDK manager solved the issue. Task done:

    1. Reinstall Emulator
    2. Tools -> SDK Manager -> SDK Tools -> Android Emulator(Download/Upgrade)

  2. you’ve got _firebaseMessaing.RequestPermission(). This line requests notification permissions from the user. Ensure this call is a success before asking for the token. You can add a test for the permission fame using _firebaseMessaing.GetNotificationSettings() and handle cases in which permission is denied.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search