是否可以在不弹出的情况下打印 android 中的网页?

is this possible to print the web page in android without popup?

I am using default android printer option (android version 4.4)

I want to byPass printManager adapter popup. how to hide the popup and give a direct print to the printer in android

在我看来答案是

这是 Android 的 PrintManager class 中的 print() 方法:

public PrintJob print(String printJobName, PrintDocumentAdapter documentAdapter, PrintAttributes attributes)
{
    if (mService == null)
    {
        Log.w(LOG_TAG, "Feature android.software.print not available");
        return null;
    }
    if (!(mContext instanceof Activity))
    {
        throw new IllegalStateException("Can print only from an activity");
    }
    if (TextUtils.isEmpty(printJobName))
    {
        throw new IllegalArgumentException("printJobName cannot be empty");
    }
    if (documentAdapter == null)
    {
        throw new IllegalArgumentException("documentAdapter cannot be null");
    }
    PrintDocumentAdapterDelegate delegate = new PrintDocumentAdapterDelegate((Activity) mContext, documentAdapter);
    try
    {
        Bundle result = mService.print(printJobName, delegate, attributes, mContext.getPackageName(), mAppId, mUserId);
        if (result != null)
        {
            PrintJobInfo printJob = result.getParcelable(EXTRA_PRINT_JOB);
            IntentSender intent = result.getParcelable(EXTRA_PRINT_DIALOG_INTENT);
            if (printJob == null || intent == null)
            {
                return null;
            }
            try
            {
                mContext.startIntentSender(intent, null, 0, 0, 0);
                return new PrintJob(printJob, this);
            }
            catch (SendIntentException sie)
            {
                Log.e(LOG_TAG, "Couldn't start print job config activity.", sie);
            }
        }
    }
    catch (RemoteException re)
    {
        Log.e(LOG_TAG, "Error creating a print job", re);
    }
    return null;
}

只需创建您自己的 class(我会假装它被命名为 MyPrintManager)其中 extends PrintManager@Override 中的 print() 方法。然后,使用上面的代码,但删除这一行:

mContext.startIntentSender(intent, null, 0, 0, 0);

然后,使用下面的代码获取 MyPrintManager class 的实例:

MyPrintManager printManager = (MyPrintManager) appContext.getSystemService(Context.PRINT_SERVICE);

你可以试试这个,虽然我不确定它是否有效,因为我没有测试过它。请回复结果,如果不行我会尽力帮助你。

您不能扩展 PrintManager class。这是一个最终的class。请检查下面link

http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/4.4.4_r1/android/print/PrintManager.java

这些家伙设计了自己的印花framework.Where他们正在设计自己的dialog.Have外观

http://apf.isb-vietnam.com/index.php/programming-with-apf.html