@Override public boolean onOptionsItemSelected(MenuItem item) { int id = item.getItemId(); switch (id) { case R.id.print_test: // mBtp.printLogo(); // PrintHelper.TestPrint("Siti"); // PrintHelper.TestPrint("Name", "Jayachandra"); // Display the dialog here. AppGlobals.printerTestDialogFragment.show(getFragmentManager(), "PrintTestDialog"); return true; case R.id.app_setting: AppSettingsActivity appSettingsActivity = new AppSettingsActivity(); appSettingsActivity.setAppSetting(setting); appSettingsActivity.show(getFragmentManager(), "App Settings Dialog"); return true; case R.id.action_connect_device: // show a dialog to select from the list of available printers // mBtp.showDeviceList(this); // mBtp.connectToPrinterUsingMacAddress("98:D3:31:70:3B:9C"); // mBtp.showDeviceList(this); PrintHelper.ConnectToPrinter(); return true; case R.id.action_unpair_device: Builder u = new AlertDialog.Builder(this); u.setTitle("Bluetooth Printer unpair"); // d.setIcon(R.drawable.ic_launcher); u.setMessage("Are you sure you want to unpair all Bluetooth printers ?"); u.setPositiveButton( android.R.string.yes, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { if (mBtp.unPairBluetoothPrinters()) { Toast.makeText( getApplicationContext(), "All Bluetooth printer(s) unpaired", Toast.LENGTH_SHORT) .show(); } } }); u.setNegativeButton( android.R.string.no, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { // do nothing } }); u.show(); return true; } return super.onOptionsItemSelected(item); }
@Override public void onReceive(Context context, Intent intent) { String action = intent.getAction(); BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE); if (BluetoothDevice.ACTION_FOUND.equals(action)) { // ... //Device found } else if (BluetoothDevice.ACTION_ACL_CONNECTED.equals(action)) { // Device is now connected PrintHelper.SetIsConnected(true); AppGlobals.printerTestDialogFragment.SetPrinterStatus(); } else if (BluetoothAdapter.ACTION_DISCOVERY_FINISHED.equals(action)) { // Done searching } else if (BluetoothDevice.ACTION_ACL_DISCONNECT_REQUESTED.equals(action)) { // Device is about to disconnect } else if (BluetoothDevice.ACTION_ACL_DISCONNECTED.equals(action)) { // Device has disconnected PrintHelper.SetIsConnected(false); AppGlobals.printerTestDialogFragment.SetPrinterStatus(); } }