Skip to content

Develop via Android Studio

You can develop Android applications to use Brother Print SDK via Android Studio.

Add the SDK

There are 2 ways to add the SDK into your project.

Use Android Studio Wizard

  • Click File > New > Project Structure... > Dependencies.
  • Select your module such as app and click plus sign "+" and select JAR/AAR Dependency.
  • Input a path to BrotherPrintLibrary.aar and select a dependency type and click OK.
  • Confirm that build.gradle for your module has been updated like below:
dependencies {
    implementation(name: '<path-to-lib>/BrotherPrintLibrary', ext: 'aar')
}

The path is either a relative or absolute path.

Add dependency into build.gradle files manually

( Our Samples uses this. )

  • Create a directory such as libs in any directory under your project root, and put BrotherPrintLibrary.aar in the directory.
    For example : < Repository Root >/app/libs/BrotherPrintLibrary.aar

  • Open build.gradle for your module then add flatDir{} and add dependency as below.

repositories {
    flatDir {
        dirs 'libs'
    }
}
dependencies {
    implementation(name:'BrotherPrintLibrary', ext:'aar')
}

Add Permissions

Write the following permissions to Manifest.xml.

<!-- For Wi-Fi -->
<uses-permission android:name="android.permission.INTERNET" />

<!-- For Bluetooth -->
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />

<!-- For Bluetooth Low Energy, Android 11 and earlier-->
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

<!-- For Bluetooth Low Energy, Android 12 and later -->
<uses-permission android:name="android.permission.BLUETOOTH_SCAN"
        android:usesPermissionFlags="neverForLocation"
        tools:targetApi="s" />

android.permission.WRITE_EXTERNAL_STORAGE is not required if you set a scoped storage for your application to workPath of PrinterInfo class.

Implement Feature using the SDK

Follows is minimum code to connect to the printer. See each guides for more details.

import com.brother.sdk.lmprinter.Channel;
import com.brother.sdk.lmprinter.OpenChannelError;
import com.brother.sdk.lmprinter.PrinterDriver;
import com.brother.sdk.lmprinter.PrinterDriverGenerateResult;
import com.brother.sdk.lmprinter.PrinterDriverGenerator;

void yourGreatFeature() {
    Channel channel = Channel.newWifiChannel("IPAddress.of.your.printer");

    PrinterDriverGenerateResult result = PrinterDriverGenerator.openChannel(channel);
    if (result.getError().getCode() != OpenChannelError.ErrorCode.NoError) {
        Log.e("", "Error - Open Channel: " + result.getError().getCode());
        return;
    }
    Log.d("", "Success - Open Channel");

    PrinterDriver printerDriver = result.getDriver();
    //
    // Put any code to use printer
    //

    printerDriver.closeChannel();
}

For USB connectivity, permisson must be requested to communicate with USB devices.