1

我正在开发餐厅应用程序。订单完成后,我需要在AlertView.

AlertViewwifi打印机可以打印出来吗?怎么做?

4

1 回答 1

1

是的,可以打印布局,从布局创建位图并将意图发送到打印机应用程序,如下面的代码所示

    yourRootLayout.setDrawingCacheEnabled(true);
    yourRootLayout.setDrawingCacheQuality(View.DRAWING_CACHE_QUALITY_HIGH);
    yourRootLayout.buildDrawingCache();

    Bitmap dummyImageBitmap = Bitmap.createBitmap(yourRootLayout
            .getDrawingCache());
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    dummyImageBitmap.compress(Bitmap.CompressFormat.JPEG, 100, out);
    byte[] photoArray = out.toByteArray();
    yourRootLayout.setDrawingCacheEnabled(false);

    try {

        File file = new File(getFilePath());//path to sdcard
        if (file.exists()) {
            file.delete();
        }
        FileOutputStream outPut = new FileOutputStream(file);
        outPut.write(photoArray);
        outPut.flush();
        outPut.close();
        Intent intent = new Intent();
        intent.setAction(Intent.ACTION_SEND);
        intent.setType("application/pdf");
        intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file));
        startActivity(intent);


    } catch (Exception e) {
        throw new Exception("Error generating file", e);
    }

现在这将弹出一个应用程序列表,您必须选择允许通过 wifi 打印的打印机应用程序

于 2016-02-05T08:08:49.293 回答