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
you cannot extend PrintManager class. It is a final class .Please check below link
These guys have designed their own printing framework.Where they are designing their own dialog.Have a look
http://apf.isb-vietnam.com/index.php/programming-with-apf.html
It seems to me like the answer is yes.
Here is the print()
method from Android's PrintManager
class:
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;
}
Simply create your own class (I will pretend it is named MyPrintManager
) which extends PrintManager
and @Override
the print()
method in it. Then, use the code above, but remove this line:
mContext.startIntentSender(intent, null, 0, 0, 0);
Then, get an instance of the MyPrintManager
class using the code below:
MyPrintManager printManager = (MyPrintManager) appContext.getSystemService(Context.PRINT_SERVICE);
You could try this, though I am not sure if it works, because I haven't tested it. Please reply with the result, and I will try to help you further if it didn't work.
来源:https://stackoverflow.com/questions/28738148/is-this-possible-to-print-the-web-page-in-android-without-popup