【发布时间】:2013-12-24 18:18:01
【问题描述】:
我需要将我的应用与配对的蓝牙设备连接,这将通过蓝牙打印机(佳能)打印图像 CP900 & CP800 - SELPHY).
我没有找到任何 Canon Printer Android SDK 任何帮助或链接都会很重要。
我发现这个link 很有帮助,但我得到了蓝牙绑定为空
我的程序包含两个java类,第一个是BluetoothActivity.java,第二个是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();
}
});
}
}
将此code 用于BluetoothShare.java
清单权限:-
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
【问题讨论】:
-
嗨,Moon,您是否已通过佳能 selphy 找到可行的解决方案?对于蓝牙,我需要单独的适配器吗?在规范页面中没有提到佳能网站上的蓝牙..谢谢
标签: java android printing bluetooth