### Example Printed Output Source: https://docs.sunmi.com/en-US/cdixeghjk491/xmafeghjk535 The expected text output generated by the printText method. ```plaintext Hello Sunmi! ``` -------------------------------- ### Development Workflow Overview Source: https://docs.sunmi.com/en-US/cdixeghjk491/xmafeghjk535 Visual representation of the application lifecycle from device request to release. ```plaintext [ Request Test Device ] ──> [ Register Partner Platform ] ──> [ Apply for Developer Status ] │ ▼ [ App Deployment/Release ] <── [ Integration & Debugging ] <── [ Access Hardware Capabilities ] ``` -------------------------------- ### Configure Module-level build.gradle Source: https://docs.sunmi.com/en-US/cdixeghjk491/xzcxeghjk491 Define the SDK versions and include the required biometric and appcompat dependencies. ```gradle android { compileSdkVersion 34 defaultConfig { minSdkVersion 23 // Minimum system version targetSdkVersion 34 } } dependencies { // Core dependency implementation 'androidx.biometric:biometric:1.1.0' implementation 'androidx.appcompat:appcompat:1.6.1' } ``` -------------------------------- ### Implement Biometric Authentication in Java Source: https://docs.sunmi.com/en-US/cdixeghjk491/xzcxeghjk491 A complete Activity implementation using BiometricPrompt to handle fingerprint verification, including hardware checks and callback management. ```java import android.os.Bundle; import android.widget.Toast; import androidx.appcompat.app.AppCompatActivity; import androidx.biometric.BiometricManager; import androidx.biometric.BiometricPrompt; import androidx.core.content.ContextCompat; import java.util.concurrent.Executor; public class SunmiBiometricActivity extends AppCompatActivity { private BiometricPrompt biometricPrompt; private BiometricPrompt.PromptInfo promptInfo; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_sunmi_biometric); // 1. Request permission requestBiometricPermission(this); // 2. Initialize biometrics initBiometric(); // 3. Bind button to trigger verification findViewById(R.id.btn_verify).setOnClickListener(v -> startBiometricVerify()); } /** * Initialize biometric components */ private void initBiometric() { Executor executor = ContextCompat.getMainExecutor(this); // Build verification callback biometricPrompt = new BiometricPrompt(this, executor, new BiometricPrompt.AuthenticationCallback() { @Override public void onAuthenticationSucceeded(BiometricPrompt.AuthenticationResult result) { super.onAuthenticationSucceeded(result); runOnUiThread(() -> { Toast.makeText(SunmiBiometricActivity.this, "Verification succeeded, execute business logic", Toast.LENGTH_SHORT).show(); // TODO: Integrate checkout/login/payment and other business logic }); } @Override public void onAuthenticationFailed() { super.onAuthenticationFailed(); runOnUiThread(() -> Toast.makeText(SunmiBiometricActivity.this, "Fingerprint mismatch, please try again", Toast.LENGTH_SHORT).show()); } @Override public void onAuthenticationError(int errorCode, CharSequence errString) { super.onAuthenticationError(errorCode, errString); runOnUiThread(() -> Toast.makeText(SunmiBiometricActivity.this, "Verification error: " + errString, Toast.LENGTH_LONG).show()); } }); // Build verification dialog promptInfo = new BiometricPrompt.PromptInfo.Builder() .setTitle("Fingerprint Verification") .setSubtitle("Place finger to complete checkout/authorization") .setNegativeButtonText("Cancel") .setAllowedAuthenticators(BiometricManager.Authenticators.BIOMETRIC_STRONG) // Strong security mode .build(); } /** * Start fingerprint verification (pre-check device compatibility) */ private void startBiometricVerify() { BiometricManager biometricManager = BiometricManager.from(this); switch (biometricManager.canAuthenticate(BiometricManager.Authenticators.BIOMETRIC_STRONG)) { case BiometricManager.BIOMETRIC_SUCCESS: biometricPrompt.authenticate(promptInfo); break; case BiometricManager.BIOMETRIC_ERROR_NO_HARDWARE: Toast.makeText(this, "No fingerprint hardware on device", Toast.LENGTH_LONG).show(); break; case BiometricManager.BIOMETRIC_ERROR_NONE_ENROLLED: Toast.makeText(this, "No fingerprint enrolled, please add in Settings", Toast.LENGTH_LONG).show(); break; default: Toast.makeText(this, "Fingerprint function unavailable", Toast.LENGTH_LONG).show(); } } // Dynamic permission request method (same as 2.3) private void requestBiometricPermission(Context context) { // ... Copy code from 2.3 ... } @Override public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { // ... Copy code from 2.3 ... } } ``` -------------------------------- ### Implement Plain Text Printing in Android Activity Source: https://docs.sunmi.com/en-US/cdixeghjk491/xmafeghjk535 Demonstrates how to retrieve the printer service from the application instance and invoke the printText method with null-safety checks. ```java package com.sm.sdk.demo; import android.os.Bundle; import android.util.Log; import androidx.appcompat.app.AppCompatActivity; import com.sunmi.peripheral.printer.SunmiPrinterService; public class MainActivity extends AppCompatActivity { private static final String TAG = "SunmiDebug"; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // Execute test print executeTextPrint("Hello SUNMI!\n"); } private void executeTextPrint(String text) { SunmiPrinterService printerService = MyApplication.getInstance().getSunmiPrinterService(); if (printerService != null) { try { // Invoke print interface. Pass null to the second argument to use default styling callbacks. printerService.printText(text, null); } catch (Exception e) { Log.e(TAG, "Failed to send print command.", e); } } else { Log.w(TAG, "SUNMI Printer Service is unavailable. Verify service binding state and hardware compatibility."); } } } ``` -------------------------------- ### Add SUNMI Printer SDK Dependency Source: https://docs.sunmi.com/en-US/cdixeghjk491/xmafeghjk535 Include the core SUNMI printer library in the module-level build.gradle file. ```groovy dependencies { // Core SUNMI Printer SDK implementation 'com.sunmi:printerlibrary:1.0.23' } ``` -------------------------------- ### Implement Dynamic Permission Request Source: https://docs.sunmi.com/en-US/cdixeghjk491/xzcxeghjk491 Handle runtime permission checks and result callbacks for Android 10+ compatibility. ```java private static final int REQUEST_BIOMETRIC_PERMISSION = 1001; // Request permission private void requestBiometricPermission(Context context) { if (ContextCompat.checkSelfPermission(context, Manifest.permission.USE_BIOMETRIC) != PackageManager.PERMISSION_GRANTED) { ActivityCompat.requestPermissions((Activity) context, new String[]{Manifest.permission.USE_BIOMETRIC}, REQUEST_BIOMETRIC_PERMISSION); } } // Permission callback @Override public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { super.onRequestPermissionsResult(requestCode, permissions, grantResults); if (requestCode REQUEST_BIOMETRIC_PERMISSION) { if (grantResults.length 0 || grantResults[0] != PackageManager.PERMISSION_GRANTED) { Toast.makeText(this, "Fingerprint permission not enabled, function unavailable", Toast.LENGTH_LONG).show(); } } } ``` -------------------------------- ### Bind SUNMI Printer Service Source: https://docs.sunmi.com/en-US/cdixeghjk491/xmafeghjk535 Implement asynchronous binding to the SunmiPrinterService within a custom Application class to handle hardware interactions. ```java package com.sm.sdk.demo; import android.app.Application; import android.content.Context; import com.sunmi.peripheral.printer.InnerPrinterCallback; import com.sunmi.peripheral.printer.InnerPrinterException; import com.sunmi.peripheral.printer.InnerPrinterManager; import com.sunmi.peripheral.printer.SunmiPrinterService; public class MyApplication extends Application { private static MyApplication instance; private SunmiPrinterService sunmiPrinterService; public static MyApplication getInstance() { return instance; } @Override public void onCreate() { super.onCreate(); instance = this; bindPrintService(this); } /** * Binds to the built-in SUNMI printer service asynchronously. */ private void bindPrintService(Context context) { try { InnerPrinterManager.getInstance().bindService(context, new InnerPrinterCallback() { @Override protected void onConnected(SunmiPrinterService service) { sunmiPrinterService = service; } @Override protected void onDisconnected() { sunmiPrinterService = null; } }); } catch (InnerPrinterException e) { e.printStackTrace(); } } /** * Returns the active printer service instance. * @return SunmiPrinterService instance, or null if the service is not ready. */ public SunmiPrinterService getSunmiPrinterService() { return sunmiPrinterService; } } ``` -------------------------------- ### Configure AndroidManifest.xml Permissions Source: https://docs.sunmi.com/en-US/cdixeghjk491/xzcxeghjk491 Declare biometric permissions and hardware features. Setting required to false for hardware features prevents device filtering in the Play Store. ```xml ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.