### Get Printer Status Source: https://github.com/star-micronics/starxpand-sdk-android/blob/main/README.md Connect to a Star printer and retrieve its current status. Ensure you have the correct connection settings and handle potential exceptions during the process. The printer is disconnected in the finally block. ```kotlin fun getStatus() { // Specify your printer connection settings. val settings = StarConnectionSettings(interfaceType.Lan, "00:11:62:00:00:00") val printer = StarPrinter(settings, applicationContext) val job = SupervisorJob() val scope = CoroutineScope(Dispatchers.Default + job) scope.launch { try { // Connect to the printer. printer.openAsync().await() // Get printer status. val status = printer.getStatusAsync().await() Log.d("Status", "${status}") } catch (e: Exception) { // Exception. Log.d("Status", "${e.message}") } finally { // Disconnect from the printer. printer.closeAsync().await() } } } ``` -------------------------------- ### Product Label Template for 203dpi/300dpi Source: https://github.com/star-micronics/starxpand-sdk-android/blob/main/app/src/main/java/com/starmicronics/starxpandsdk/printingsamples/README.md Kotlin template for generating a product label. Supports both 203dpi and 300dpi. ```Kotlin package com.example.starxpand_sdk_printingsamples.label.for203dpiand300dpi import com.starmicronics.starxpandsdk.common.BitmapConverter import com.starmicronics.starxpandsdk.common.StarBitmap import com.starmicronics.starxpandsdk.label.LabelBuilder import com.starmicronics.starxpandsdk.label.LabelType import com.starmicronics.starxpandsdk.label.StarLabelPrinter fun createProductLabel(printer: StarLabelPrinter, labelType: LabelType) { val builder = LabelBuilder(labelType) // Add elements to the label builder.addText("Product Name", "", 10, 10, 10, 0, 0, 0, 0, 0, 0, 0) builder.addText("Price: $XX.XX", "", 10, 30, 10, 0, 0, 0, 0, 0, 0, 0) builder.addText("SKU: XXXXXX", "", 10, 50, 10, 0, 0, 0, 0, 0, 0, 0) // Build the label val label = builder.build() // Print the label printer.print(label) } ``` -------------------------------- ### Shelf Label for Inventory Template for 203dpi/300dpi Source: https://github.com/star-micronics/starxpand-sdk-android/blob/main/app/src/main/java/com/starmicronics/starxpandsdk/printingsamples/README.md Kotlin template for generating a shelf label for inventory. Supports both 203dpi and 300dpi. ```Kotlin package com.example.starxpand_sdk_printingsamples.label.for203dpiand300dpi import com.starmicronics.starxpandsdk.common.BitmapConverter import com.starmicronics.starxpandsdk.common.StarBitmap import com.starmicronics.starxpandsdk.label.LabelBuilder import com.starmicronics.starxpandsdk.label.LabelType import com.starmicronics.starxpandsdk.label.StarLabelPrinter fun createShelfLabelForInventory(printer: StarLabelPrinter, labelType: LabelType) { val builder = LabelBuilder(labelType) // Add elements to the label builder.addText("Item Name", "", 10, 10, 10, 0, 0, 0, 0, 0, 0, 0) builder.addText("Price: $XX.XX", "", 10, 30, 10, 0, 0, 0, 0, 0, 0, 0) builder.addText("SKU: XXXXXX", "", 10, 50, 10, 0, 0, 0, 0, 0, 0, 0) // Build the label val label = builder.build() // Print the label printer.print(label) } ``` -------------------------------- ### Inventory Label Template for 203dpi/300dpi Source: https://github.com/star-micronics/starxpand-sdk-android/blob/main/app/src/main/java/com/starmicronics/starxpandsdk/printingsamples/README.md Kotlin template for generating an inventory label. Adjustments may be needed for 300dpi printing. ```Kotlin package com.example.starxpand_sdk_printingsamples.label.for203dpiand300dpi import com.starmicronics.starxpandsdk.common.BitmapConverter import com.starmicronics.starxpandsdk.common.StarBitmap import com.starmicronics.starxpandsdk.label.LabelBuilder import com.starmicronics.starxpandsdk.label.LabelType import com.starmicronics.starxpandsdk.label.StarLabelPrinter fun createInventoryLabel(printer: StarLabelPrinter, labelType: LabelType) { val builder = LabelBuilder(labelType) // Set printable area for 300dpi // Follow the comments in the template to set the printable area for 300dpi. // Add elements to the label builder.addText("Inventory", "", 10, 10, 10, 0, 0, 0, 0, 0, 0, 0) builder.addText("Item Name:", "", 10, 30, 10, 0, 0, 0, 0, 0, 0, 0) builder.addText("SKU:", "", 10, 50, 10, 0, 0, 0, 0, 0, 0, 0) builder.addText("Quantity:", "", 10, 70, 10, 0, 0, 0, 0, 0, 0, 0) // Build the label val label = builder.build() // Print the label printer.print(label) } ``` -------------------------------- ### Food Product Label Template for 203dpi/300dpi Source: https://github.com/star-micronics/starxpand-sdk-android/blob/main/app/src/main/java/com/starmicronics/starxpandsdk/printingsamples/README.md Kotlin template for generating a food product label. Adjustments may be needed for 300dpi printing. ```Kotlin package com.example.starxpand_sdk_printingsamples.label.for203dpiand300dpi import com.starmicronics.starxpandsdk.common.BitmapConverter import com.starmicronics.starxpandsdk.common.StarBitmap import com.starmicronics.starxpandsdk.label.LabelBuilder import com.starmicronics.starxpandsdk.label.LabelType import com.starmicronics.starxpandsdk.label.StarLabelPrinter fun createFoodProductLabel(printer: StarLabelPrinter, labelType: LabelType) { val builder = LabelBuilder(labelType) // Set printable area for 300dpi // Follow the comments in the template to set the printable area for 300dpi. // Add elements to the label builder.addText("Product Name", "", 10, 10, 20, 0, 0, 0, 0, 0, 0, 0) builder.addText("Ingredients:", "", 10, 40, 10, 0, 0, 0, 0, 0, 0, 0) builder.addText("Allergens:", "", 10, 80, 10, 0, 0, 0, 0, 0, 0, 0) builder.addText("Best Before:", "", 10, 120, 10, 0, 0, 0, 0, 0, 0, 0) // Build the label val label = builder.build() // Print the label printer.print(label) } ``` -------------------------------- ### Visitor Label Template for 203dpi/300dpi Source: https://github.com/star-micronics/starxpand-sdk-android/blob/main/app/src/main/java/com/starmicronics/starxpandsdk/printingsamples/README.md Kotlin template for generating a visitor label. Supports both 203dpi and 300dpi. ```Kotlin package com.example.starxpand_sdk_printingsamples.label.for203dpiand300dpi import com.starmicronics.starxpandsdk.common.BitmapConverter import com.starmicronics.starxpandsdk.common.StarBitmap import com.starmicronics.starxpandsdk.label.LabelBuilder import com.starmicronics.starxpandsdk.label.LabelType import com.starmicronics.starxpandsdk.label.StarLabelPrinter fun createVisitorLabel(printer: StarLabelPrinter, labelType: LabelType) { val builder = LabelBuilder(labelType) // Add elements to the label builder.addText("Visitor Name:", "", 10, 10, 10, 0, 0, 0, 0, 0, 0, 0) builder.addText("Company:", "", 10, 30, 10, 0, 0, 0, 0, 0, 0, 0) builder.addText("Date:", "", 10, 50, 10, 0, 0, 0, 0, 0, 0, 0) // Build the label val label = builder.build() // Print the label printer.print(label) } ``` -------------------------------- ### Monitor Printer Events Source: https://github.com/star-micronics/starxpand-sdk-android/blob/main/README.md Monitor various events from a Star printer, including readiness, drawer status, input device data, and display connection. This snippet sets up delegates to receive callbacks for these events. The printer is connected asynchronously. ```kotlin fun monitor() { val job = SupervisorJob() val scope = CoroutineScope(Dispatchers.Default + job) scope.launch { // Specify your printer connection settings. val settings = StarConnectionSettings(interfaceType.Lan, "00:11:62:00:00:00") printer = StarPrinter(settings, applicationContext) // Callback for printer state changed. printer?.printerDelegate = object : PrinterDelegate() { override fun onReady() { super.onReady() Log.d("Monitor", "Printer: Ready") } // ... // Please refer to document for other callback. } printer?.drawerDelegate = object : DrawerDelegate() { override fun onOpenCloseSignalSwitched(openCloseSignal: Boolean) { super.onOpenCloseSignalSwitched(openCloseSignal) Log.d("Monitor", "Drawer: Open Close Signal Switched: ${openCloseSignal}") } // ... // Please refer to document for other callback. } printer?.inputDeviceDelegate = object : InputDeviceDelegate() { override fun onDataReceived(data: List) { super.onDataReceived(data) Log.d("Monitor", "Input Device: DataReceived ${data}") } // ... // Please refer to document for other callback. } printer?.displayDelegate = object : DisplayDelegate() { override fun onConnected() { super.onConnected() Log.d("Monitor", "Display: Connected") } // ... // Please refer to document for other callback. } try { // Connect to the printer. printer?.openAsync()?.await() } catch (e: Exception) { // Exception. Log.d("Monitor", "${e.message}") } } } ``` -------------------------------- ### Accessory Filter Configuration Source: https://github.com/star-micronics/starxpand-sdk-android/blob/main/README.md Define USB accessory filters in `accessory_filter.xml` to specify compatible Star Micronics accessories. ```xml ``` -------------------------------- ### Food Delivery Label (Thai) Template for 203dpi/300dpi Source: https://github.com/star-micronics/starxpand-sdk-android/blob/main/app/src/main/java/com/starmicronics/starxpandsdk/printingsamples/README.md Kotlin template for generating a Thai food delivery label. Adjustments may be needed for 300dpi printing. ```Kotlin package com.example.starxpand_sdk_printingsamples.label.for203dpiand300dpi import com.starmicronics.starxpandsdk.common.BitmapConverter import com.starmicronics.starxpandsdk.common.StarBitmap import com.starmicronics.starxpandsdk.label.LabelBuilder import com.starmicronics.starxpandsdk.label.LabelType import com.starmicronics.starxpandsdk.label.StarLabelPrinter fun createFoodDeliveryLabelThai(printer: StarLabelPrinter, labelType: LabelType) { val builder = LabelBuilder(labelType) // Set printable area for 300dpi // Follow the comments in the template to set the printable area for 300dpi. // Add elements to the label builder.addText("รายการอาหาร", "", 10, 10, 15, 0, 0, 0, 0, 0, 0, 0) // Food Items builder.addText("ชื่อร้าน", "", 10, 40, 10, 0, 0, 0, 0, 0, 0, 0) // Shop Name builder.addText("ที่อยู่", "", 10, 70, 10, 0, 0, 0, 0, 0, 0, 0) // Address builder.addText("เบอร์โทร", "", 10, 100, 10, 0, 0, 0, 0, 0, 0, 0) // Phone Number // Build the label val label = builder.build() // Print the label printer.print(label) } ``` -------------------------------- ### Device Filter Configuration Source: https://github.com/star-micronics/starxpand-sdk-android/blob/main/README.md Define USB device filters in `device_filter.xml` to specify compatible Star Micronics printers. ```xml ``` -------------------------------- ### Pharmacy Medication Label Template for 203dpi/300dpi Source: https://github.com/star-micronics/starxpand-sdk-android/blob/main/app/src/main/java/com/starmicronics/starxpandsdk/printingsamples/README.md Kotlin template for generating a pharmacy medication label. Adjustments may be needed for 300dpi printing. ```Kotlin package com.example.starxpand_sdk_printingsamples.label.for203dpiand300dpi import com.starmicronics.starxpandsdk.common.BitmapConverter import com.starmicronics.starxpandsdk.common.StarBitmap import com.starmicronics.starxpandsdk.label.LabelBuilder import com.starmicronics.starxpandsdk.label.LabelType import com.starmicronics.starxpandsdk.label.StarLabelPrinter fun createPharmacyMedicationLabel(printer: StarLabelPrinter, labelType: LabelType) { val builder = LabelBuilder(labelType) // Set printable area for 300dpi // Follow the comments in the template to set the printable area for 300dpi. // Add elements to the label builder.addText("Patient Name:", "", 10, 10, 10, 0, 0, 0, 0, 0, 0, 0) builder.addText("Medication:", "", 10, 30, 10, 0, 0, 0, 0, 0, 0, 0) builder.addText("Dosage:", "", 10, 50, 10, 0, 0, 0, 0, 0, 0, 0) builder.addText("Instructions:", "", 10, 70, 10, 0, 0, 0, 0, 0, 0, 0) // Build the label val label = builder.build() // Print the label printer.print(label) } ``` -------------------------------- ### Prescription Label Template for 203dpi/300dpi Source: https://github.com/star-micronics/starxpand-sdk-android/blob/main/app/src/main/java/com/starmicronics/starxpandsdk/printingsamples/README.md Kotlin template for generating a prescription label. Adjustments may be needed for 300dpi printing. ```Kotlin package com.example.starxpand_sdk_printingsamples.label.for203dpiand300dpi import com.starmicronics.starxpandsdk.common.BitmapConverter import com.starmicronics.starxpandsdk.common.StarBitmap import com.starmicronics.starxpandsdk.label.LabelBuilder import com.starmicronics.starxpandsdk.label.LabelType import com.starmicronics.starxpandsdk.label.StarLabelPrinter fun createPrescriptionLabel(printer: StarLabelPrinter, labelType: LabelType) { val builder = LabelBuilder(labelType) // Set printable area for 300dpi // Follow the comments in the template to set the printable area for 300dpi. // Add elements to the label builder.addText("Patient Name:", "", 10, 10, 10, 0, 0, 0, 0, 0, 0, 0) builder.addText("Prescription:", "", 10, 30, 10, 0, 0, 0, 0, 0, 0, 0) builder.addText("Doctor:", "", 10, 50, 10, 0, 0, 0, 0, 0, 0, 0) builder.addText("Date Filled:", "", 10, 70, 10, 0, 0, 0, 0, 0, 0, 0) // Build the label val label = builder.build() // Print the label printer.print(label) } ``` -------------------------------- ### Configure USB Device Attachment in AndroidManifest.xml Source: https://github.com/star-micronics/starxpand-sdk-android/blob/main/README.md Add these intent filters and meta-data elements to your AndroidManifest.xml to prevent the USB connection permission dialog from appearing and to allow automatic application startup when a USB device is attached. ```xml ``` -------------------------------- ### Add StarIO10 Library Dependency Source: https://github.com/star-micronics/starxpand-sdk-android/blob/main/README.md Add this dependency to your app/build.gradle file to include the StarIO10 library in your Android project. Replace VERSION_NUMBER with the latest library version. ```gradle dependencies { implementation 'com.starmicronics:stario10:VERSION_NUMBER' ... } ``` -------------------------------- ### Expiration Label (JP) Template for 203dpi/300dpi Source: https://github.com/star-micronics/starxpand-sdk-android/blob/main/app/src/main/java/com/starmicronics/starxpandsdk/printingsamples/README.md Kotlin template for generating a Japanese expiration label. Adjustments may be needed for 300dpi printing. ```Kotlin package com.example.starxpand_sdk_printingsamples.label.for203dpiand300dpi import com.starmicronics.starxpandsdk.common.BitmapConverter import com.starmicronics.starxpandsdk.common.StarBitmap import com.starmicronics.starxpandsdk.label.LabelBuilder import com.starmicronics.starxpandsdk.label.LabelType import com.starmicronics.starxpandsdk.label.StarLabelPrinter fun createExpirationLabelJP(printer: StarLabelPrinter, labelType: LabelType) { val builder = LabelBuilder(labelType) // Set printable area for 300dpi // Follow the comments in the template to set the printable area for 300dpi. // Add elements to the label builder.addText("消費期限", "", 10, 10, 15, 0, 0, 0, 0, 0, 0, 0) // Expiration Date builder.addText("YYYY/MM/DD", "", 10, 40, 10, 0, 0, 0, 0, 0, 0, 0) builder.addText("商品名", "", 10, 70, 10, 0, 0, 0, 0, 0, 0, 0) // Product Name // Build the label val label = builder.build() // Print the label printer.print(label) } ``` -------------------------------- ### Barcode Label 2 (Narrow) Template for 203dpi/300dpi Source: https://github.com/star-micronics/starxpand-sdk-android/blob/main/app/src/main/java/com/starmicronics/starxpandsdk/printingsamples/README.md Kotlin template for generating a narrow barcode label. Adjustments may be needed for 300dpi printing. ```Kotlin package com.example.starxpand_sdk_printingsamples.label.for203dpiand300dpi import com.starmicronics.starxpandsdk.common.BitmapConverter import com.starmicronics.starxpandsdk.common.StarBitmap import com.starmicronics.starxpandsdk.label.LabelBuilder import com.starmicronics.starxpandsdk.label.LabelType import com.starmicronics.starxpandsdk.label.StarLabelPrinter fun createBarcodeLabel2Narrow(printer: StarLabelPrinter, labelType: LabelType) { val builder = LabelBuilder(labelType) // Set printable area for 300dpi // Follow the comments in the template to set the printable area for 300dpi. // Add elements to the label builder.addBarcode("1234567890", "CODE128", 10, 10, 10, 10, 0, 0, 0, 0, 0, 0) builder.addText("Product ID", "", 10, 50, 10, 0, 0, 0, 0, 0, 0, 0) // Build the label val label = builder.build() // Print the label printer.print(label) } ``` -------------------------------- ### Barcode Label 2 (Wide) Template for 203dpi/300dpi Source: https://github.com/star-micronics/starxpand-sdk-android/blob/main/app/src/main/java/com/starmicronics/starxpandsdk/printingsamples/README.md Kotlin template for generating a wide barcode label. Adjustments may be needed for 300dpi printing. ```Kotlin package com.example.starxpand_sdk_printingsamples.label.for203dpiand300dpi import com.starmicronics.starxpandsdk.common.BitmapConverter import com.starmicronics.starxpandsdk.common.StarBitmap import com.starmicronics.starxpandsdk.label.LabelBuilder import com.starmicronics.starxpandsdk.label.LabelType import com.starmicronics.starxpandsdk.label.StarLabelPrinter fun createBarcodeLabel2Wide(printer: StarLabelPrinter, labelType: LabelType) { val builder = LabelBuilder(labelType) // Set printable area for 300dpi // Follow the comments in the template to set the printable area for 300dpi. // Add elements to the label builder.addBarcode("1234567890", "CODE128", 10, 10, 10, 10, 0, 0, 0, 0, 0, 0) builder.addText("Product ID", "", 10, 50, 10, 0, 0, 0, 0, 0, 0, 0) // Build the label val label = builder.build() // Print the label printer.print(label) } ``` -------------------------------- ### Bluetooth Scan Permission Source: https://github.com/star-micronics/starxpand-sdk-android/blob/main/README.md Add the `BLUETOOTH_SCAN` permission to `AndroidManifest.xml` for Bluetooth Low Energy communication on Android 12.0 and later. The `neverForLocation` flag is optional. ```xml ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.