Skip to content

修复空指针问题 #1060

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 12 additions & 11 deletions android/src/main/java/com/pauldemarco/flutter_blue/ProtoMaker.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,11 @@
import android.bluetooth.le.ScanRecord;
import android.bluetooth.le.ScanResult;
import android.os.Build;
import android.os.Parcel;
import android.os.ParcelUuid;
import android.util.Log;
import android.util.SparseArray;

import com.google.protobuf.ByteString;

import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.UUID;
Expand Down Expand Up @@ -68,17 +65,21 @@ static Protos.ScanResult from(BluetoothDevice device, ScanResult scanResult) {
}
// Manufacturer Specific Data
SparseArray<byte[]> msd = scanRecord.getManufacturerSpecificData();
for (int i = 0; i < msd.size(); i++) {
int key = msd.keyAt(i);
byte[] value = msd.valueAt(i);
a.putManufacturerData(key, ByteString.copyFrom(value));
if (msd!=null){
for (int i = 0; i < msd.size(); i++) {
int key = msd.keyAt(i);
byte[] value = msd.valueAt(i);
a.putManufacturerData(key, ByteString.copyFrom(value));
}
}
// Service Data
Map<ParcelUuid, byte[]> serviceData = scanRecord.getServiceData();
for (Map.Entry<ParcelUuid, byte[]> entry : serviceData.entrySet()) {
ParcelUuid key = entry.getKey();
byte[] value = entry.getValue();
a.putServiceData(key.getUuid().toString(), ByteString.copyFrom(value));
if (serviceData!=null){
for (Map.Entry<ParcelUuid, byte[]> entry : serviceData.entrySet()) {
ParcelUuid key = entry.getKey();
byte[] value = entry.getValue();
a.putServiceData(key.getUuid().toString(), ByteString.copyFrom(value));
}
}
// Service UUIDs
List<ParcelUuid> serviceUuids = scanRecord.getServiceUuids();
Expand Down
2 changes: 1 addition & 1 deletion example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class BluetoothOffScreen extends StatelessWidget {
'Bluetooth Adapter is ${state != null ? state.toString().substring(15) : 'not available'}.',
style: Theme.of(context)
.primaryTextTheme
.subhead
.subtitle1
?.copyWith(color: Colors.white),
),
],
Expand Down
10 changes: 5 additions & 5 deletions example/lib/widgets.dart
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ class ServiceTile extends StatelessWidget {
children: <Widget>[
Text('Service'),
Text('0x${service.uuid.toString().toUpperCase().substring(4, 8)}',
style: Theme.of(context).textTheme.body1?.copyWith(
style: Theme.of(context).textTheme.bodyText1?.copyWith(
color: Theme.of(context).textTheme.caption?.color))
],
),
Expand Down Expand Up @@ -183,7 +183,7 @@ class CharacteristicTile extends StatelessWidget {
Text('Characteristic'),
Text(
'0x${characteristic.uuid.toString().toUpperCase().substring(4, 8)}',
style: Theme.of(context).textTheme.body1?.copyWith(
style: Theme.of(context).textTheme.bodyText1?.copyWith(
color: Theme.of(context).textTheme.caption?.color))
],
),
Expand Down Expand Up @@ -245,7 +245,7 @@ class DescriptorTile extends StatelessWidget {
Text('0x${descriptor.uuid.toString().toUpperCase().substring(4, 8)}',
style: Theme.of(context)
.textTheme
.body1
.bodyText1
?.copyWith(color: Theme.of(context).textTheme.caption?.color))
],
),
Expand Down Expand Up @@ -289,11 +289,11 @@ class AdapterStateTile extends StatelessWidget {
child: ListTile(
title: Text(
'Bluetooth adapter is ${state.toString().substring(15)}',
style: Theme.of(context).primaryTextTheme.subhead,
style: Theme.of(context).primaryTextTheme.subtitle1,
),
trailing: Icon(
Icons.error,
color: Theme.of(context).primaryTextTheme.subhead?.color,
color: Theme.of(context).primaryTextTheme.subtitle1?.color,
),
),
);
Expand Down