您是否针对特定的打印协议?(对于特定的打印机?)
如果没有,并且无论打印机是否连接,都可以进行通用打印,您可以使用以下代码片段:
将其写入您要打印特定文件的位置:
Intent intent = Tools.getSendToPrinterIntent(
DisplayActivity.this, mPdfAsPictures,
mPrintCurrentIndex);
// notify the activity on return (will need to ask the user for
// approvel)
startActivityForResult(intent, ACTIVITY_PRINT);
这是辅助方法:
public static Intent getSendToPrinterIntent(Context ctx, String[] fileFullPaths, int indexToPrint){
Intent sendIntent = new Intent(Intent.ACTION_SEND_MULTIPLE);
// This type means we can send either JPEG, or PNG
sendIntent.setType("image/*");
ArrayList<Uri> uris = new ArrayList<Uri>();
File fileIn = new File(fileFullPaths[indexToPrint]);
Uri u = Uri.fromFile(fileIn);
uris.add(u);
sendIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
return sendIntent;
}
最后,您将在以下位置收到答案:
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == ACTIVITY_PRINT) {
switch (resultCode) {
case Activity.RESULT_CANCELED:
Log.d(TAG(), "onActivityResult, resultCode = CANCELED");
break;
case Activity.RESULT_FIRST_USER:
Log.d(TAG(), "onActivityResult, resultCode = FIRST_USER");
break;
case Activity.RESULT_OK:
Log.d(TAG(), "onActivityResult, resultCode = OK");
break;
}
}
};
祝你好运!