簡體   English   中英

使用Delphi從Android設備打印報告

[英]Print reports from Android device using Delphi

我正在使用Delphi XE8開發應用程序,我需要打印報告。

該報告有更多頁面,所以我無法創建簡單的圖像並共享它。

這個想法是使用FMX.Printer。

但是TPrintDialog僅在Windows上不能在Android上使用。 如何從“雲打印”列表中選擇打印機?

你有什么建議嗎?

謝謝

如果設備上安裝了官方的Google Cloud Print應用程序,那么您應該能夠按照此問題的答案中所述的意圖來訪問它: 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的示例代碼

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM