HomeiOS Developmentandroid - Find out how to disguise the app content material with...

android – Find out how to disguise the app content material with splash display screen when app is in backgorund/inactive in flutter with bundle or methodology channel


Hey guys i’m engaged on an app the place the shopper desires to indicate the splash display screen when app is in background mode not a black display screen utilizing flag safe, anybody who may also help me with it for android and ios
counsel a bundle which may also help me perceive it or assist me with methodology channel

Right here is the code for each

Android

class MainActivity: FlutterFragmentActivity() {

    personal val CHANNEL = "safety"

    override enjoyable onCreate(savedInstanceState: Bundle?) {
        if (intent.getIntExtra("org.chromium.chrome.further.TASK_ID", -1) == this.taskId) {
            this.end()
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            startActivity(intent);
        }
        tremendous.onCreate(savedInstanceState)
    }

    override enjoyable configureFlutterEngine(flutterEngine: FlutterEngine) {
        tremendous.configureFlutterEngine(flutterEngine)

        
        setupMethodChannel(flutterEngine)
    }



        personal enjoyable setupMethodChannel(flutterEngine: FlutterEngine) {
        MethodChannel(flutterEngine.dartExecutor.binaryMessenger, CHANNEL).setMethodCallHandler { name, outcome ->
            when (name.methodology) {
                "enableAppSecurity" -> {
                    enableAppSecurity()
                    outcome.success(null)
                }
                "disableAppSecurity" -> {
                    disableAppSecurity()
                    outcome.success(null)
                }
                else -> outcome.notImplemented()
            }
        }
    }

    override enjoyable onWindowFocusChanged(hasFocus: Boolean) {
        tremendous.onWindowFocusChanged(hasFocus)
        toggleAppSecurity(hasFocus)
    }

    override enjoyable onPause() {
        tremendous.onPause()
        enableAppSecurity()
    }

    override enjoyable onResume() {
        tremendous.onResume()
        disableAppSecurity()
    }

    personal enjoyable toggleAppSecurity(hasFocus: Boolean) {
        if (hasFocus) {
            disableAppSecurity()
        } else {
            enableAppSecurity()
        }
    }

    personal enjoyable enableAppSecurity() {
        window.setFlags(WindowManager.LayoutParams.FLAG_SECURE, WindowManager.LayoutParams.FLAG_SECURE)
    }

    personal enjoyable disableAppSecurity() {
        window.clearFlags(WindowManager.LayoutParams.FLAG_SECURE)
    }
}

IOS

@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {

   personal var flutterViewController: FlutterViewController!
  personal var securityChannel: FlutterMethodChannel!
  personal var blurEffectView: UIVisualEffectView?
  personal var isInBackground: Bool = false // Observe whether or not app is in background


  override func software(
    _ software: UIApplication,
    didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
  ) -> Bool {
    GeneratedPluginRegistrant.register(with: self)
    setupFlutterCommunication()
//      FirebaseApp.configure()
    return tremendous.software(software, didFinishLaunchingWithOptions: launchOptions)
  }

  personal func setupFlutterCommunication() {
    flutterViewController = window?.rootViewController as? FlutterViewController
    securityChannel = FlutterMethodChannel(
      identify: "safety",
      binaryMessenger: flutterViewController.binaryMessenger
    )

    securityChannel.setMethodCallHandler(deal with)
  }

  override func applicationDidEnterBackground(_ software: UIApplication) {
    isInBackground = true // App entered background
    enableAppSecurity()
  }

  override func applicationDidBecomeActive(_ software: UIApplication) {
    // Test if the app was in background earlier than turning into energetic
    if isInBackground {
      disableAppSecurity()
      isInBackground = false
    }
  }

  personal func deal with(_ name: FlutterMethodCall, outcome: @escaping FlutterResult) {
    change name.methodology {
    case "enableAppSecurity":
      outcome(nil)
    case "disableAppSecurity":
      outcome(nil)
    default:
      outcome(FlutterMethodNotImplemented)
    }
  }

  personal func enableAppSecurity() {
    let blurEffect = UIBlurEffect(model: .gentle)
    blurEffectView = UIVisualEffectView(impact: blurEffect)
    blurEffectView?.body = window!.body
    window?.addSubview(blurEffectView!)
  }

  personal func disableAppSecurity() {
    blurEffectView?.removeFromSuperview()
  }
}

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments