Skip to content

Commit

Permalink
Version 0.0.4
Browse files Browse the repository at this point in the history
  • Loading branch information
edufolly committed Dec 20, 2018
1 parent 09ab5ff commit a7542c5
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 20 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## [0.0.4] - 2018-12-20

* Unsupported value error correction (thanks @rafaelterada)
* Added openSettings, which opens the bluetooth settings screen (thanks @rafaelterada)


## [0.0.3] - 2018-11-22

* async connection and null exception handled (thanks @MohiuddinM)
Expand Down
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# flutter_bluetooth_serial


[![pub package](https://img.shields.io/pub/v/flutter_bluetooth_serial.svg)](https://pub.dartlang.org/packages/flutter_bluetooth_serial)

Flutter basic implementation for Classical Bluetooth.

Based on [flutter_blue](https://github.com/pauldemarco/flutter_blue).
Expand All @@ -8,7 +11,7 @@ The first goal of this project is making an interface for Serial Port Protocol (

This plugin needs a lot of improvements, so I need your help. Any kind of collaboration will be awesome.

Click on the :star: star above and open your issue.
Click on the :star: above to support the project!

## Getting Started

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,33 +37,33 @@
import io.flutter.plugin.common.PluginRegistry.RequestPermissionsResultListener;


public class FlutterBluetoothSerialPlugin implements MethodCallHandler, RequestPermissionsResultListener {
public class FlutterBluetoothSerialPlugin implements MethodCallHandler,
RequestPermissionsResultListener {

private static final String TAG = "FlutterBluePlugin";
private static final String NAMESPACE = "flutter_bluetooth_serial";
private static final int REQUEST_COARSE_LOCATION_PERMISSIONS = 1451;
private static final UUID MY_UUID = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB");
private static ConnectedThread THREAD = null;
private final Registrar registrar;
private final MethodChannel channel;
private final EventChannel stateChannel;
private final EventChannel readChannel;
private final BluetoothManager mBluetoothManager;
private BluetoothAdapter mBluetoothAdapter;

private Result pendingResult;

private EventSink readSink;
private EventSink statusSink;

public static void registerWith(Registrar registrar) {
final FlutterBluetoothSerialPlugin instance = new FlutterBluetoothSerialPlugin(registrar);
registrar.addRequestPermissionsResultListener(instance);
}

FlutterBluetoothSerialPlugin(Registrar registrar) {
this.registrar = registrar;
this.channel = new MethodChannel(registrar.messenger(), NAMESPACE + "/methods");
this.stateChannel = new EventChannel(registrar.messenger(), NAMESPACE + "/state");
this.readChannel = new EventChannel(registrar.messenger(), NAMESPACE + "/read");
this.mBluetoothManager = (BluetoothManager) registrar.activity()
MethodChannel channel = new MethodChannel(registrar.messenger(), NAMESPACE + "/methods");
EventChannel stateChannel = new EventChannel(registrar.messenger(), NAMESPACE + "/state");
EventChannel readChannel = new EventChannel(registrar.messenger(), NAMESPACE + "/read");
BluetoothManager mBluetoothManager = (BluetoothManager) registrar.activity()
.getSystemService(Context.BLUETOOTH_SERVICE);
assert mBluetoothManager != null;
this.mBluetoothAdapter = mBluetoothManager.getAdapter();
Expand Down Expand Up @@ -99,7 +99,7 @@ public void onMethodCall(MethodCall call, Result result) {
case "isConnected":
result.success(THREAD != null);
break;

case "openSettings":
ContextCompat.startActivity(registrar.activity(),
new Intent(android.provider.Settings.ACTION_BLUETOOTH_SETTINGS),
Expand All @@ -111,7 +111,8 @@ public void onMethodCall(MethodCall call, Result result) {
try {

if (ContextCompat.checkSelfPermission(registrar.activity(),
Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
Manifest.permission.ACCESS_COARSE_LOCATION)
!= PackageManager.PERMISSION_GRANTED) {

ActivityCompat.requestPermissions(registrar.activity(),
new String[]{Manifest.permission.ACCESS_COARSE_LOCATION},
Expand Down Expand Up @@ -198,7 +199,7 @@ private void getBondedDevices(Result result) {
result.success(list);
}

private String exceptionToString(Exception ex){
private String exceptionToString(Exception ex) {
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
ex.printStackTrace(pw);
Expand Down Expand Up @@ -349,7 +350,6 @@ public void cancel() {
/**
*
*/
private EventSink statusSink;
private final StreamHandler stateStreamHandler = new StreamHandler() {

private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
Expand Down Expand Up @@ -394,7 +394,6 @@ public void onCancel(Object o) {
/**
*
*/
private EventSink readSink;
private final StreamHandler readResultsHandler = new StreamHandler() {
@Override
public void onListen(Object o, EventSink eventSink) {
Expand Down
2 changes: 1 addition & 1 deletion example/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ buildscript {
}

dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
classpath 'com.android.tools.build:gradle:3.2.1'
}
}

Expand Down
4 changes: 2 additions & 2 deletions example/android/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Fri Jun 23 08:50:38 CEST 2017
#Sun Dec 16 17:15:46 BRST 2018
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip
2 changes: 1 addition & 1 deletion lib/flutter_bluetooth_serial.dart
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class FlutterBluetoothSerial {

Future<bool> get isConnected async =>
await _channel.invokeMethod('isConnected');

Future<bool> get openSettings async =>
await _channel.invokeMethod('openSettings');

Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: flutter_bluetooth_serial
description: A basic Flutter Bluetooth Serial
version: 0.0.3
version: 0.0.4
author: Eduardo Folly <edufolly@gmail.com>
homepage: https://github.com/edufolly/flutter_bluetooth_serial

Expand Down

0 comments on commit a7542c5

Please sign in to comment.