remote_controller_identifier 0.0.1 copy "remote_controller_identifier: ^0.0.1" to clipboard
remote_controller_identifier: ^0.0.1 copied to clipboard

PlatformAndroid

Introducing a new Flutter plugin designed to identify remote controllers and display which remote controller is being used. This will enhance productivity for mobile applications.

example/lib/main.dart

import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'dart:async';
import 'package:flutter/services.dart';
import 'package:lottie/lottie.dart';
import 'package:remote_controller_identifier/remote_controller_identifier.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatefulWidget {
  const MyApp({super.key});

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  String _platformVersion = 'Unknown';
  final _remoteControllerIdentifierPlugin = RemoteControllerIdentifier();

  late String _remoteControllerAppName = "";
  late bool isRemoteAppRunning = false;

  List<String> packageNames = [
    'com.teamviewer.teamviewer.market.mobile',
    'com.anydesk.anydeskandroid',
    'com.anydesk.adcontrol.ad1',
    'com.microsoft.rdc.android',
    'com.microsoft.rdc',
    'com.google.chromeremotedesktop',
    'com.splashtop.remote',
    'com.remotepc.client',
    'com.realvnc.viewer.android',
    'com.logmein.ignitionpro.android',
    'com.uptodown.remotecontrol',
    'com.paretologic.antitheft',
    'com.apowersoft.remoteviewer',
    'com.bomgar.ios',
    'com.zoho.assist',
    'com.splashtop.remote.pad',
    'com.supremocontrol',
    'com.dameware.mini.remotecontrol',
    'com.pd7l.wifimouse',
    'com.Banamalon.RemoteControl',
    'com.lite.remoteapp',
    'com.teamviewer.teamviewer',
    'com.nexlink.screenstream'
  ];

  Future<void> findRemoteAppIsRunning(
      {required String? appName,
      required String? appPackageName,
      required String? isEnabled}) async {
    final bool? isRunning =
        await _remoteControllerIdentifierPlugin.getScreenMirroring();
    if (kDebugMode) {
      print(
          "findRemoteAppIsRunning==> $appName is ${isRunning == true ? 'Running' : 'Disabled'}");
    }
    setState(() {
      isRemoteAppRunning = isRunning!;
      _remoteControllerAppName = appName!;
    });
  }

  Future<void> _GetPackageInfo() async {
    for (String packageName in packageNames) {
      try {
        final Map? result =
            await _remoteControllerIdentifierPlugin.getPackageInfo(packageName);
        if (kDebugMode) {
          print("Package data===>$result");
        }
        if (result != null && result.isNotEmpty) {
          final String? appName = result['appName'] as String?;
          final String? appPackageName = result['appPackageName'] as String?;
          final String isEnabled = result['isEnabled'].toString();
          final String? name = result['name'] as String?;
          if (appName != null &&
              appName.isNotEmpty &&
              appPackageName != null &&
              appPackageName.isNotEmpty) {
            if (kDebugMode) {
              print(
                  'App Name: $appName, Package Name: $appPackageName, Is Enabled: $isEnabled, Name: $name');
            }
            findRemoteAppIsRunning(
                appName: appName,
                appPackageName: appPackageName,
                isEnabled: isEnabled);
          }
          break;
        } else {
          // Handle case when result is null
        }
      } on PlatformException {
        // Handle PlatformException
      }
    }
  }

  @override
  void initState() {
    super.initState();
    _GetPackageInfo();
    initPlatformState();
  }

  // Platform messages are asynchronous, so we initialize in an async method.
  Future<void> initPlatformState() async {
    String platformVersion;
    // Platform messages may fail, so we use a try/catch PlatformException.
    // We also handle the message potentially returning null.
    try {
      platformVersion =
          await _remoteControllerIdentifierPlugin.getPlatformVersion() ??
              'Unknown platform version';
    } on PlatformException {
      platformVersion = 'Failed to get platform version.';
    }

    // If the widget was removed from the tree while the asynchronous platform
    // message was in flight, we want to discard the reply rather than calling
    // setState to update our non-existent appearance.
    if (!mounted) return;

    setState(() {
      _platformVersion = platformVersion;
    });
  }

  @override
  Widget build(BuildContext context) {
    _GetPackageInfo();
    initPlatformState();
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      home: Scaffold(
        appBar: AppBar(
          title: const Text("Remote Control Identifier"),
          centerTitle: true,
        ),
        body: SafeArea(
          child: Center(
            child: Column(
              mainAxisAlignment: MainAxisAlignment.center,
              crossAxisAlignment: CrossAxisAlignment.center,
              children: [
                Lottie.asset("assets/assets.json"),
                const SizedBox(
                  height: 5.0,
                ),
                Text(isRemoteAppRunning
                    ? 'This app does not allow remote control.'
                    : 'Running on: $_platformVersion'),
                const SizedBox(
                  height: 5.0,
                ),
                isRemoteAppRunning
                    ? Text.rich(
                        textAlign: TextAlign.center,
                        TextSpan(
                          children: [
                            const TextSpan(
                              text: 'You\'re trying to access this app using ',
                              style: TextStyle(
                                  color: Colors.redAccent,
                                  fontWeight: FontWeight.w600),
                            ),
                            TextSpan(
                              text: _remoteControllerAppName,
                              style: TextStyle(
                                  color: Colors.redAccent,
                                  fontWeight: FontWeight.w900,
                                  textBaseline: TextBaseline.ideographic,
                                  decoration: TextDecoration.underline,
                                  decorationColor: Theme.of(context)
                                      .textTheme
                                      .titleLarge!
                                      .color),
                            ),
                            const TextSpan(
                              text: '. Please disconnect and continue!',
                              style: TextStyle(
                                  color: Colors.redAccent,
                                  fontWeight: FontWeight.w600),
                            ),
                          ],
                        ),
                      )
                    : const SizedBox(
                        height: 0.0,
                        width: 0.0,
                      ),
              ],
            ),
          ),
        ),
      ),
    );
  }
}
1
likes
160
points
18
downloads

Publisher

verified publishervinothmuthu.in

Weekly Downloads

Introducing a new Flutter plugin designed to identify remote controllers and display which remote controller is being used. This will enhance productivity for mobile applications.

Homepage
Repository (GitHub)

Documentation

API reference

License

MIT (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on remote_controller_identifier