通过配对的蓝牙打印机佳能CP 900,CP 800打印图像(S)佳能、蓝牙、打印机、图像

2023-09-06 09:15:55 作者:、行ㄕ赱禸╮

我需要为与配对的蓝牙设备,连接我的应用程序,将 打印图像的透过 蓝牙打印机(佳能CP900和放大器; CP800 - SELPHY)的

和我的没有找到的任何 Canon打印机Android SDK中任何帮助或链接将AP preciable。

我发现这个link很有帮助,但我得到的的蓝牙粘合剂为空的

我的程序中包含两个Java类,首先是的 BluetoothActivity.java 和第二为 BluetoothShare.java

 公共类BluetoothActivity延伸活动{公共静态最后弦乐LOG_TAG =MainActivity;BluetoothDevice类设备= NULL;乌里contentUri;BluetoothAdapter适配器;@覆盖保护无效的onCreate(捆绑savedInstanceState){    super.onCreate(savedInstanceState);    的setContentView(R.layout.activity_main);    最后Button按钮=(按钮)findViewById(R.id.btnPrint);    button.setOnClickListener(新View.OnClickListener(){        公共无效的onClick(视图v){            //执行上的点击动作            字符串文件路径= Environment.getExternalStoragePublicDirectory                    (Environment.DIRECTORY_PICTURES)的ToString()+/kitkat.jpg;            适配器= BluetoothAdapter.getDefaultAdapter();            如果(适配器== NULL)回报;            如果(adapter.isEnabled()){                SET<&BluetoothDevice类GT;器件= adapter.getBondedDevices();                对于(BluetoothDevice类设备:设备){                    //建立蓝牙请求                    ContentValues​​值=新ContentValues​​();                    values​​.put(BluetoothShare.URI,Uri.fromFile(新文件(文件路径))的toString());                    values​​.put(BluetoothShare.DESTINATION,device.getAddress());                    values​​.put(BluetoothShare.DIRECTION,BluetoothShare.DIRECTION_OUTBOUND);                    长TS = System.currentTimeMillis的();                    values​​.put(BluetoothShare.TIMESTAMP,TS);                    @燮pressWarnings(未使用)                    乌里contentUri = getContentResolver()插入(BluetoothShare.CONTENT_URI,价值观)。                }            }            //关闭发现            adapter.cancelDiscovery();        }    });  }} 

使用该 code为 BluetoothShare.java

清单权限: -

 <使用许可权的android:NAME =android.permission.BLUETOOTH/><使用许可权的android:NAME =android.permission.BLUETOOTH_ADMIN/> 
送原装热升华相纸 佳能CP900打印机促销

解决方案

是的,我同意你的看法,这是通过蓝牙以佳能CP 900发送/打印图像的最简单的方法 ,CP 800 的和的的其他任何可用配对的蓝牙设备或打印机的

想通了,这将在4.1不再起作用。直接写入到内容提供商的许可,现在保护,签名这意味着你必须与用于签署蓝牙应用程序相同的密钥签署您的应用程序。

因此​​,这里是我们如何落得这样做了。首先使用共享意图直接发送到应用程序:

 意向意图=新的Intent();    intent.setAction(Intent.ACTION_SEND);    intent.setComponent(新组件名(        com.android.bluetooth        com.android.bluetooth.opp.BluetoothOppLauncherActivity));    intent.setType(图像/ JPEG);    档案文件=新的文件(Environment.getExternalStoragePublicDirectory            (Environment.DIRECTORY_PICTURES)+/kitkat.jpg);    intent.putExtra(Intent.EXTRA_STREAM,Uri.fromFile(文件));    startActivity(意向); 

这工作,但它会弹出选择设备UI。如果你不想让你不得不处理这个意图的 android.bluetooth.devicepicker.action.LAUNCH 并与响应广播消息的 android.bluetooth.devicepicker.action.DEVICE_SELECTED 。但是,用户仍然可以得到选择器弹出窗口。

如果仍然在你的心中有些疑惑,然后让我知道...

幸得到@grennis在我的蓝牙打印/发送应用我用同一个来源。

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" /> 

解决方案

Yeah I agree with you, this is the most easiest way to send / print image via Bluetooth to Canon CP 900, CP 800 and to any other available paired Bluetooth Devices or Printers.

Figured out this will no longer work on 4.1. The permission to write directly to the content provider is now protected with "signed" meaning you would have to sign your app with the same key used to sign the bluetooth app.

So here is how we ended up doing it. First use the share intent to send it directly to the app:

    Intent intent = new Intent();
    intent.setAction(Intent.ACTION_SEND);
    intent.setComponent(new ComponentName(
        "com.android.bluetooth",
        "com.android.bluetooth.opp.BluetoothOppLauncherActivity"));
    intent.setType("image/jpeg");

    File file = new File(Environment.getExternalStoragePublicDirectory
            (Environment.DIRECTORY_PICTURES) + "/kitkat.jpg");

    intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file));
    startActivity(intent);

That works, but it pops up the "Select device" UI. If you don't want that you have to handle the intent android.bluetooth.devicepicker.action.LAUNCH and respond with the broadcast message android.bluetooth.devicepicker.action.DEVICE_SELECTED. But the user could still gets the chooser popup.

If still have some doubts in your mind, then let me know...

Credit goes to @grennis in my Bluetooth printing/sending App i used same source.