Discovering Printers
The SDK also offers API to discover Brother printers from your application. We recommend you to use these sample code outside the main thread.
Sample Codes
Wi-Fi Printer
You can discover Wi-Fi Printer connected to the same network with the mobile device and tablets.
iOS - Objective-C:
- (BRLMPrinterSearchResult *)startSearchWiFiPrinter {
BRLMNetworkSearchOption *option = [[BRLMNetworkSearchOption alloc] init];
option.searchDuration = 15;
optoin.printerList = [NSArray arrayWithObjects:@"Brother YourModel", @"Brother YourModel", nil];
BRLMPrinterSearchResult * result;
result = [BRLMPrinterSearcher startNetworkSearch:option callback:^(BRLMChannel *channel){
NSString *modelName_ = [channel.extraInfo objectForKey:BRLMChannelExtraInfoKeyModelName];
NSString *ipaddress = channel.channelInfo;
NSLog(@"Model: %@, IP Address: %@", modelName, ipaddress);
}];
return result;
}
iOS - Swift:
fun startSearchWiFiPrinter() -> BRLMPrinterSearchResult {
let option = BRLMNetworkSearchOption()
option.searchDuration = 15
optoin.printerList = ["Brother YourModel", "Brother YourModel"]
let result = BRLMPrinterSearcher.startNetworkSearch(option) { channel in
let modelName = channel.extraInfo?.value(forKey: BRLMChannelExtraInfoKeyModelName) as? String ?? ""
let ipaddress = channel.channelInfo
print("Model : \(modelName), IP Address: \(ipaddress)")
}
return result
}
Android - Java:
PrinterSearchResult startSearchWiFiPrinter()
{
NetworkSearchOption option = new NetworkSearchOption(15, false);
PrinterSearchResult result = PrinterSearcher.startNetworkSearch(context, option, new Consumer<Channel>() {
@Override
public void accept(Channel channel) {
String modelName = channel.getExtraInfo().get(Channel.ExtraInfoKey.ModelName);
String ipaddress = channel.getChannelInfo();
Log.d("TAG", "Model : $modelName, IP Address: $ipaddress")
}
});
return result
}
Android - Kotlin:
fun startSearchWiFiPrinter(): PrinterSearchResult
{
val option = NetworkSearchOption(15, false)
val result = PrinterSearcher.startNetworkSearch(context, option){ channel ->
val modelName = channel.extraInfo[Channel.ExtraInfoKey.ModelName] ?: ""
val ipaddress = channel.channelInfo
Log.d("TAG", "Model : $modelName, IP Address: $ipaddress")
}
return result
}
Bluetooth Printer
You can discover bluetooth printers which are already paired with the mobile device and tablets.
iOS - Objective-C:
- (NSArray<BRLMChannel *> *)startSearchBluetoothPrinter {
return [BRLMPrinterSearcher startBluetoothSearch].channels;
}
iOS - Swift:
func startSearchBluetoothPrinter() -> [BRLMChannel] {
return BRLMPrinterSearcher.startBluetoothSearch().channels
}
Android - Java:
ArrayList<Channel> startSearchBluetoothPrinter()
{
return PrinterSearcher.startBluetoothSearch(context).getChannels();
}
Android - Kotlin:
fun startSearchBluetoothPrinter(): ArrayList<Channel!>!
{
return PrinterSearcher.startBluetoothSearch(context).channels
}
Bluetooth Low Energy Printer
You can discover nearby Bluetooth Low Energy Printer.
iOS - Objective-C:
- (void)startSearchBLEPrinter {
BRLMBLESearchOption *option = [[BRLMBLESearchOption alloc] init];
option.searchDuration = 15;
BRLMPrinterSearchResult * result = [BRLMPrinterSearcher startBLESearch:option callback:^(BRLMChannel *channel){
NSString *modelName_ = [channel.extraInfo objectForKey:BRLMChannelExtraInfoKeyModelName];
NSString *advertiseLocalName = channel.channelInfo;
NSLog(@"Model: %@, AdvertiseLocalName: %@", modelName, advertiseLocalName);
}];
return result;
}
iOS - Swift:
func startSearchBLEPrinter() -> BRLMPrinterSearchResult {
let option = BRLMBLESearchOption()
option.searchDuration = 15
let result = BRLMPrinterSearcher.startBLESearch(option) { channel in
let modelName = channel.extraInfo?.value(forKey: BRLMChannelExtraInfoKeyModelName) as? String ?? ""
let advertiseLocalName = channel.channelInfo
print("Model : \(modelName), AdvertiseLocalName: \(advertiseLocalName)")
}
return result
}
Android - Java:
PrinterSearchResult startSearchBLEPrinter()
{
NetworkSearchOption option = new BLESearchOption(15);
PrinterSearchResult result = PrinterSearcher.startBLESearch(context, option, new Consumer<Channel>() {
@Override
public void accept(Channel channel) {
String modelName = channel.getExtraInfo().get(Channel.ExtraInfoKey.ModelName);
String localName = channel.getChannelInfo();
Log.d("TAG", "Model : $modelName, Local Name: $localName")
}
});
return result
}
Android - Kotlin:
fun startSearchBLEPrinter(): PrinterSearchResult
{
val option = BLESearchOption(15)
val result = PrinterSearcher.startBLESearch(context, option){ channel ->
val modelName = channel.extraInfo[Channel.ExtraInfoKey.ModelName] ?: ""
val localName = channel.channelInfo
Log.d("TAG", "Model : $modelName, Local Name: $localName")
}
return result
}
USB Printer
You can discover a printer connected via USB.
Android - Java:
ArrayList<Channel> startSearchUSBPrinter()
{
return PrinterSearcher.startUSBSearch(context).getChannels();
}
Android - Kotlin:
fun startSearchUSBPrinter(): ArrayList<Channel!>!
{
return PrinterSearcher.startUSBSearch(context).channels
}
Notes
You don't have to use these APIs if you can get the following identifier of the printer beforehand.
OS | USB | Wi-Fi | Bluetooth | Bluetooth Low Energy |
---|---|---|---|---|
iOS | N/A | IP address | Serial Number | Local Name |
Android | No ID (*1) | IP address or MAC address | Bluetooth device address | Local Name |
- (*1) The connected Brother printer is automatically specified