'Print an image on Android Studio

Hello everyone I've just finished reading the official documentation about the new printing system in Android Studio (https://developer.android.com/training/printing/photos.html) but I wasn't able to make it work. I've basically copy-pasted this code:

private void doPhotoPrint() {
    PrintHelper photoPrinter = new PrintHelper(getActivity());
    photoPrinter.setScaleMode(PrintHelper.SCALE_MODE_FIT);
    Bitmap bitmap = BitmapFactory.decodeResource(getResources(),R.drawable.droids);
    photoPrinter.printBitmap("droids.jpg - test print", bitmap);
}

But the Android print user interface doesn't appear.

My scope is to set up a printer (where I will print all my photos) and once the setup is complete I will give the printer the Bitmap to print. I will be greatful to everybody who answer me even for explaining how printing works. Thank you, S.



Solution 1:[1]

the Android print user interface doesn't appear

Apparently, PrintHelper fails quietly with a null Bitmap, rather than throwing a NullPointerException or something else.

Solution 2:[2]

private void doPhotoPrint() {
    PrintHelper photoPrinter = new PrintHelper(this);//can use getActivity() here

    photoPrinter.setScaleMode(PrintHelper.SCALE_MODE_FIT);

    Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.logontig);

    photoPrinter.printBitmap("myLogo.jpg", bitmap);
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 CommonsWare
Solution 2 Eric Aya