Skip to content
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

Adds AAR support #18

Merged
merged 3 commits into from
Oct 14, 2023
Merged
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
* Digital signature
* Smart poster
* Connection handover
* Android application record
* Media (MIME data)
* Bluetooth easy pairing / Bluetooth low energy
* other MIME data
Expand Down
11 changes: 4 additions & 7 deletions lib/ndef.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ export 'record/signature.dart';
export 'record/smartposter.dart';
export 'record/text.dart';
export 'record/uri.dart';
export 'record/androidApplication.dart';

import 'dart:typed_data';
import 'record.dart';
import 'utilities.dart';

/// Decode raw NDEF messages (containing at least one [NDEFRecord]) from byte array
List<NDEFRecord> decodeRawNdefMessage(Uint8List data,
{var typeFactory = NDEFRecord.defaultTypeFactory}) {
List<NDEFRecord> decodeRawNdefMessage(Uint8List data, {var typeFactory = NDEFRecord.defaultTypeFactory}) {
var records = <NDEFRecord>[];
var stream = new ByteStream(data);
while (!stream.isEnd()) {
Expand All @@ -36,17 +36,14 @@ List<NDEFRecord> decodeRawNdefMessage(Uint8List data,

/// Decode a NDEF record, providing its parts separately.
/// This is most useful in mobile environment because the APIs will give you these information in a separate manner.
NDEFRecord decodePartialNdefMessage(
TypeNameFormat tnf, Uint8List type, Uint8List payload,
{required Uint8List id}) {
NDEFRecord decodePartialNdefMessage(TypeNameFormat tnf, Uint8List type, Uint8List payload, {required Uint8List? id}) {
var decoded = NDEFRecord.doDecode(tnf, type, payload, id: id);
return decoded;
}

/// Encode an NDEF message (containing several [NDEFRecord]s) to byte array.
/// Set [canonicalize] to set the MB and ME fields automatically in the first / last record.
Uint8List encodeNdefMessage(List<NDEFRecord> records,
{bool canonicalize = true}) {
Uint8List encodeNdefMessage(List<NDEFRecord> records, {bool canonicalize = true}) {
if (records.length == 0) {
return new Uint8List(0);
}
Expand Down
34 changes: 34 additions & 0 deletions lib/record/androidApplication.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import 'dart:convert';
import 'dart:typed_data';

import 'package:ndef/record/externalRecord.dart';

class AARRecord extends ExternalRecord {
static const String classType = "android.com:pkg";

@override
String get decodedType {
return AARRecord.classType;
}

String packageName;

AARRecord(this.packageName);

@override
Uint8List? get payload {
return Uint8List.fromList(utf8.encode(packageName));
}

set payload(Uint8List? payload) {
packageName = utf8.decode(payload!);
}

@override
String toString() {
var str = "AARRecord: ";
str += basicInfoString;
str += "package=$packageName";
return str;
}
}
26 changes: 26 additions & 0 deletions lib/record/externalRecord.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import 'dart:typed_data';

import '../ndef.dart';

class ExternalRecord extends NDEFRecord {
static const TypeNameFormat classTnf = TypeNameFormat.nfcExternal;

TypeNameFormat get tnf {
return classTnf;
}

ExternalRecord({String? decodedType, Uint8List? payload, Uint8List? id}) : super(id: id, payload: payload) {
if (decodedType != null) {
this.decodedType = decodedType;
}
}

@override
String toString() {
var str = "ExternalRecord: ";
str += basicInfoString;
str += "type=$decodedType ";
str += "payload=${(payload?.toHexString()) ?? '(null)'}";
return str;
}
}
Loading