我需要用我的应用程序打印图像。我需要一个 phonegap 插件。它只是浏览器的命令 window.print()
但我不确定它是如何为移动应用程序完成的。有什么建议吗?
是否可以在设备上配置打印机?
最佳答案
可以实现 SEND
Intent 与打印应用程序共享它。
编辑(您的应用将与之“共享”的打印应用列表):
https://market.android.com/details?id=com.dynamixsoftware.printershare
https://market.android.com/details?id=com.hp.android.print
https://market.android.com/details?id=jp.co.canon.bsd.android.aepp.activity
仅举几例。这确实是目前期望人们打印的唯一合理方式。虽然随着 Android 的引入 USB Host支持,在未来,Linux 打印机驱动程序可能会进入 Android,并允许通过插入 USB 从许多打印机进行即插即用打印。
您至少需要:
<activity android:name=".ShareActivity">
<intent-filter
android:label="Share with my app">
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
在您的 list 中...这至少会使其显示在“共享”列表中。
从显示的页面发送数据的方式取决于您要导出/打印的内容。
如果这是一张你想分享的图片,就像你说的:
http://sudarmuthu.com/blog/sharing-content-in-android-using-action_send-intent
会有所帮助。基本上对于图像,它看起来像:
Intent sharingIntent = new Intent(Intent.ACTION_SEND);
Uri screenshotUri = Uri.parse(path);
sharingIntent.setType("image/png");
sharingIntent.putExtra(Intent.EXTRA_STREAM, screenshotUri);
startActivity(Intent.createChooser(sharingIntent, "Share image using"));
希望这是一个有效的解决方案,比浏览器的 window.print()
复杂得多 :-(
现在,就 PhoneGap 而言:
Phonegap - Share functionality to Email, Twitter and Facebook
和
http://smus.com/android-phonegap-plugins
应该有助于理解它对共享的使用。
和
http://www.ryangillespie.com/downloads/SharePlugin.java
是一个实际的 PhoneGap 插件示例,供分享。
关于android - 使用适用于 Android 的 phonegap 插件打印图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8664564/