简体   繁体   中英

How i can make Flutter application start when it receives background firebase message even if the screen is locked i want my app to start

I tried this code but it didn't works:

package com.example.flutter_telegram

import android.os.Bundle
import io.flutter.app.FlutterActivity
import io.flutter.plugins.GeneratedPluginRegistrant
import android.content.Intent
import android.util.Log
import androidx.annotation.NonNull
import com.dexterous.flutterlocalnotifications.FlutterLocalNotificationsPlugin
import io.flutter.app.FlutterApplication;
import io.flutter.embedding.engine.FlutterEngine
import io.flutter.plugin.common.MethodChannel
import io.flutter.plugin.common.PluginRegistry;
import io.flutter.plugin.common.PluginRegistry.PluginRegistrantCallback;
import io.flutter.plugins.firebasemessaging.FlutterFirebaseMessagingService;

class MainActivity: FlutterActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        GeneratedPluginRegistrant.registerWith(this)
      
        val engine = FlutterEngine(applicationContext)

        MethodChannel(engine.dartExecutor,"flutter/MethodChannelDemo").setMethodCallHandler{
            call, _ ->
            if (call.method=="Documents"){
                Log.d("TAG", "message")
                val intent = Intent(this, MainActivity::class.java)
                startActivity(intent)
            }
        }
    }
}

and I have tried android_intent package but I got an exception:

PlatformException(error, No Activity found to handle Intent { act=android.intent.action.VIEW dat=.MainActivity (has extras) }, null)

I don't think that IOS supports this type of behavior

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM