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)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.