moyoung_bluetooth_plugin 0.0.3 copy "moyoung_bluetooth_plugin: ^0.0.3" to clipboard
moyoung_bluetooth_plugin: ^0.0.3 copied to clipboard

A Flutter plugin for communicating with the watch. Includes the following features: Scan BLE device, Connect and so on, more than 50 functional modules.

MoYoung Ble Plugin #

1 Introduction #

Welcome to use this plugin. This is a Flutter plugin for communicating with the watch.

1.1Platform Support #

Android iOS
✔️ ✔️

1.2 Usage #

To use this plugin, add moyoung_bluetooth_plugin as a dependency in your pubspec.yaml file.

moyoung_bluetooth_plugin: ^latestVersion

1.3 Project configuration #

  • Android

1.Perform the following configuration when generating apk for code obfuscation. Please add the following configuration to your proguard-rules.pro file.

-keep class com.crrepa.ble.** { *; }
-keep class com.example.moyoung_bluetooth_plugin.** { *; }

2.In your App Module, modify the following configuration.

android {
    ...
    defaultConfig {
        ...
        minSdkVersion 18
        ...
    }
    ...
}
  • IOS

1.You need to add it to the info.plist .

<key>NSAppTransportSecurity</key>
<dict>
    <key>NSAllowsArbitraryLoads</key>
    <true/>
</dict>
<key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
<string>Use the location to sync weather from your phone to your watch.</string>
<key>NSBluetoothAlwaysUsageDescription</key>
<string>Use the Bluetooth to connect to your Nokia Watch</string>
<key>NSCalendarsUsageDescription</key>
<string>Use the calendar to sync events from your phone to your watch.</string>
<key>NSCameraUsageDescription</key>
<string>Use the camera to scan the QR code on your watch screen.</string>
<key>NSContactsUsageDescription</key>
<string>The selected contacts will be added to your Watch contacts.</string>
<key>NSPhotoLibraryUsageDescription</key>
<string>Use the Photo to change your watch face.</string>
<key>UIApplicationSupportsIndirectInputEvents</key>
<true/>
<key>UIBackgroundModes</key>
<array>
<string>bluetooth-central</string>
</array>

2.Use terminal, in your path for project,use pod install to import the library.

1.4 Example #

  • First setp

    Import package.

    import 'package:moyoung_bluetooth_plugin/moyoung_ble.dart';
    
  • Second step

    Apply for some permissions: [location, storage].

    • Tip1: You need to apply for these permissions yourself

    • Tip2: Of course you can use the example in the Example project to apply for permissions. But, please note the configuration of permissions in this file:AndroidManifest.xml

  • Third step

    Use in pages.

    class _MyAppState extends State<MyApp> {
      final _streamSubscriptions = <StreamSubscription<dynamic>>[];
      final MoYoungBle _blePlugin = MoYoungBle();
      final List<BleScanBean> _deviceList = [];
      
      @override
      void initState() {
        super.initState();
        subscriptStream();
      }
      
      void subscriptStream() {
        _streamSubscriptions.add(
          _blePlugin.bleScanEveStm.listen(
            (BleScanBean event) async {
              setState(() {
                if (event.isCompleted) {
                  //Scan completed, do something
                } else {
                  _deviceList.add(event);
                }
              });
            },
          ),
        );
      }
      
      @override
      void dispose() {
        super.dispose();
        for (final subscription in _streamSubscriptions) {
          subscription.cancel();
        }
      }
      
      // Scanning bluetooth devices
      void startScan() {
        if (!mounted) return;
        _blePlugin.startScan(10*1000).then((value) => {
          setState(() {
            // Do something.
            print(value ? "Scanning" : "Have not started");
          })
        }).onError((error, stackTrace) => {
          //Usually some permissions are not requested
          print(error.toString())
        });
      }
    }
    

1.5 Detailed usage document #

Click to Wiki.

1.6 Full sample project #

The Example project contains details about how the code is used.

Click to Example.

1.7 GNU GENERAL PUBLIC LICENSE License #

Click to License.

0
likes
105
pub points
0%
popularity

Publisher

unverified uploader

A Flutter plugin for communicating with the watch. Includes the following features: Scan BLE device, Connect and so on, more than 50 functional modules.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (LICENSE)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on moyoung_bluetooth_plugin