I need to connect my app with paired bluetooth devices, that will print images via Bluetooth printer (Canon CP900 & CP800 - SELPHY).
And I did not find any Canon Printer Android SDK any help or link will appreciable.
I found this link helpful, but i am getting Bluetooth binder is Null
My program contains two java classes, first is BluetoothActivity.java and second is BluetoothShare.java
public class BluetoothActivity extends Activity {
public static final String LOG_TAG = "MainActivity";
BluetoothDevice device = null;
Uri contentUri;
BluetoothAdapter adapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final Button button = (Button) findViewById(R.id.btnPrint);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// Perform action on click
String filePath = Environment.getExternalStoragePublicDirectory
(Environment.DIRECTORY_PICTURES).toString() + "/kitkat.jpg";
adapter = BluetoothAdapter.getDefaultAdapter();
if (adapter == null) return;
if (adapter.isEnabled()) {
Set<BluetoothDevice> devices = adapter.getBondedDevices();
for (BluetoothDevice device : devices) {
//build bluetooth request
ContentValues values = new ContentValues();
values.put(BluetoothShare.URI, Uri.fromFile(new File(filePath)).toString());
values.put(BluetoothShare.DESTINATION, device.getAddress());
values.put(BluetoothShare.DIRECTION, BluetoothShare.DIRECTION_OUTBOUND);
Long ts = System.currentTimeMillis();
values.put(BluetoothShare.TIMESTAMP, ts);
@SuppressWarnings("unused")
Uri contentUri = getContentResolver().insert(BluetoothShare.CONTENT_URI, values);
}
}
//turn off the discovery
adapter.cancelDiscovery();
}
});
}
}
Using this code for BluetoothShare.java
Manifest Permissions:-
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />