可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
I am working on an android app that should invoke android HP ePrint application for wireless printing. For that purpose, I'm using code:
Intent intent = new Intent("com.hp.android.print.PRINT"); intent.setPackage("com.hp.android.print"); startActivityForResult(intent, 0);
I am pretty sure that I didn't get intent's action right... Does anybody know what is the right action to invoke this HP ePrint application? And how can I pass the exact file to print (intent.putExtra(...)).
Thanks
回答1:
After more than 10 hours, I managed to find the solution. Right code to invoke HP ePrint application is like this:
Uri uri = Uri.fromFile( f ); Intent intent = new Intent ("org.androidprinting.intent.action.PRINT"); intent.setDataAndType( uri, "text/plain" ); context.startActivityForResult(intent, 0);
回答2:
After my android 5.0.1 app has created a JPEG file, I use the following code to start a wireless print operation (via HP ePrint version 3.4):
Intent intent = new Intent(); intent.setAction(Intent.ACTION_VIEW); Uri uri = Uri.fromFile(new File("something.jpg")); intent.setDataAndType(uri, "image/*"); activity.startActivity(intent);
The code works cleanly, but every time I print something I have to manually set the paper size to 'A4' and paper type to 'plain'. (It defaults to 'photo'.)
I would be very interested in documentation on how to pass Intent parameters to HP ePrint.