PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, September 18, 2022

[FIXED] how to send a photo using image picker to my hp color printer?

 September 18, 2022     android, flutter, imagepicker, printing     No comments   

Issue

I send some images to firebase storage, then another fetches the images and need to print it on a photo paper. what flutter API can I use.

I have managed to use call the native api using methodchannel and it seems to in redirecting to print service. But it only goes to the print service ,where i have to click print and does not initiate printing directly.

Please add your suggestions on how to directly initiate the printing.


Solution

package com.example.print1
import android.content.Context
import android.content.ContextWrapper
import android.content.Intent
import android.content.IntentFilter
import android.os.BatteryManager
import android.os.Build.VERSION
import android.os.Build.VERSION_CODES
import androidx.annotation.NonNull
import io.flutter.embedding.android.FlutterActivity
import io.flutter.embedding.engine.FlutterEngine
import io.flutter.plugin.common.MethodChannel
import android.R
import androidx.print.PrintHelper
import android.graphics.BitmapFactory
import android.R.drawable
class MainActivity : FlutterActivity() {
    private val CHANNEL = "samples.flutter.dev/battery"
    override fun configureFlutterEngine(@NonNull flutterEngine: FlutterEngine) {
        super.configureFlutterEngine(flutterEngine)
        MethodChannel(flutterEngine.dartExecutor.binaryMessenger, CHANNEL).setMethodCallHandler {
            // Note: this method is invoked on the main thread.
                call, result ->
            if (call.method == "Printphoto") {
                doPhotoPrint()

            } else {
                result.notImplemented()
            }
        }
    }


    private fun doPhotoPrint() {
        println("heloo the yout");
        activity.also { context ->
            PrintHelper(context).apply {
                scaleMode = PrintHelper.SCALE_MODE_FIT
            }.also { printHelper ->
                val bitmap = BitmapFactory.decodeResource(resources, R.drawable.alert_dark_frame)
                printHelper.printBitmap("droids.jpg - test print", bitmap)
            }
        }

    }
}


static const platform = const MethodChannel('samples.flutter.dev/battery');
      String _printstatus =       'printing photo';
      Future<void> Printphotocall() async {
        String batteryLevel;
        try {
          final int result = await platform.invokeMethod('doPhotoPrint');
          _printstatus = 'Battery level at $result % .';
        } on PlatformException catch (e) {
          _printstatus = "Failed to print: '${e.message}'.";
        }
        setState(() {
          _printstatus = batteryLevel;
        });
      }


Answered By - nimals1986
Answer Checked By - Senaida (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing