【发布时间】:2015-09-11 07:10:15
【问题描述】:
我正在使用 Delphi XE8 开发一个应用程序,我需要打印一份报告。
报告有更多页面,所以我无法创建简单的图像并分享它。
这个想法是使用 FMX.Printer。
但 TPrintDialog 仅适用于 Windows,不适用于 Android。 如何从云打印列表中选择打印机?
你有什么建议吗?
谢谢
【问题讨论】:
标签: android delphi firemonkey
我正在使用 Delphi XE8 开发一个应用程序,我需要打印一份报告。
报告有更多页面,所以我无法创建简单的图像并分享它。
这个想法是使用 FMX.Printer。
但 TPrintDialog 仅适用于 Windows,不适用于 Android。 如何从云打印列表中选择打印机?
你有什么建议吗?
谢谢
【问题讨论】:
标签: android delphi firemonkey
如果设备上安装了官方的Google Cloud Print 应用程序,那么您应该能够使用该问题的答案中描述的 Intent 访问它:Print Intent for Google Cloud Print App
Intent printIntent = new Intent(Intent.ACTION_SEND);
printIntent.setType("text/html");
printIntent.putExtra(Intent.EXTRA_TITLE, "some cool title for your document");
printIntent.putExtra(Intent.EXTRA_STREAM, uri);
startActivity(printIntent);
我猜 Android 会显示一个包含可用选项的对话框,包括云打印打印机。
Google 云打印文档:https://developers.google.com/cloud-print/docs/android
获取打印机列表的API:https://developers.google.com/cloud-print/docs/proxyinterfaces#list
【讨论】:
把它放到 Delphi 中应该是这样的:
uses
...
FMX.Platform.Android,
Androidapi.Helpers,
Androidapi.JNI.GraphicsContentViewText,
Androidapi.JNI.Embarcadero,
...
var
printIntent: JIntent;
begin
printIntent := TJIntent.Create;
printIntent.setAction(TJIntent.JavaClass.ACTION_SEND);
printIntent.setType(StringToJString('text/html'));
printIntent.putExtra(TJIntent.JavaClass.EXTRA_TITLE, StringToJString('Testing print from Android'));
printIntent.putExtra(TJIntent.JavaClass.EXTRA_STREAM, StringToJString(uri));
if MainActivity.getPackageManager.queryIntentActivities(printIntent, TJPackageManager.JavaClass.MATCH_DEFAULT_ONLY).size > 0 then //Checks if there is at least one application capable of receiving the intent.
MainActivity.startActivity(printIntent) //Calls startActivity() to send the intent to the system.
else
ShowMessage('Receiver not found');
基于http://docwiki.embarcadero.com/CodeExamples/Seattle/en/FMX.Android_Intents_Sample的示例代码
【讨论】: