Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to wake up flutter android app with firebase push notification

How can i use broadcast receiver/intent to open flutter android app when receive firebase message.

like image 495
harsha.kuruwita Avatar asked Jun 01 '21 09:06

harsha.kuruwita


1 Answers

Implment FirebaseMessagingService and start Main activity from onMessageReceived:


public class FirebaseMsgService extends FirebaseMessagingService {

    @Override
    public void onMessageReceived(RemoteMessage remoteMessage) {

    //...
    Intent intent = new Intent(this, MainActivity.class);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    startActivity(intent);
    }
}

and also in MainActivity you may want to unlock device:


public class MainActivity extends FlutterActivity {

    @Override
  public void configureFlutterEngine(@NonNull FlutterEngine flutterEngine) {
    GeneratedPluginRegistrant.registerWith(flutterEngine);
        

    Window window = this.getWindow();
    window.addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);
    window.addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
    window.addFlags(WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
        
       

  }
}
like image 197
Develocode 777 Avatar answered Sep 16 '22 15:09

Develocode 777