Android端⽆线打印功能实现(附带源码Demo)
最近公司有个需求实现⼿机端打印合同的功能。上⽹搜索了⼀通,没靠谱的。⾛⼀些歪门邪道调⽤第三⽅软件实现打印功能。这⾥选
择对printershare下⼿。下载软件分析其中的源码。看其中的清单⽂件
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<manifest xmlns:android="schemas.android/apk/res/android"android:installLocation="auto"package="com.dynamixsoftware.printershare"
<supports-screens android:largeScreens="true"android:normalScreens="true"android:smallScreens="true"android:xlargeScreens="true"anyDensity <application android:allowBackup="false"android:debuggable="false"android:hardwareAccelerated="false"android:icon="@drawable/icon"android:labe <activity android:configChanges="locale|keyboardHidden|orientation|screenSize"android:name="com.dynamixsoftware.printershare.ActivityStart"
<activity android:configChanges="locale|keyboardHidden|orientation|screenSize"android:name="com.dy
namixsoftware.printershare.ActivityMain"
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity android:configChanges="locale|keyboardHidden|orientation|screenSize"android:name="com.dynamixsoftware.printershare.ActivityContacts"
<activity android:configChanges="locale|keyboardHidden|orientation|screenSize"android:name="com.dynamixsoftware.printershare.ActivityMessages <activity android:configChanges="locale|keyboardHidden|orientation|screenSize"android:name="com.dynamixsoftware.printershare.ActivityDocsBrow <activity android:configChanges="locale|keyboardHidden|orientation|screenSize"android:name="com.
dynamixsoftware.printershare.ActivityGDocsBro <activity android:configChanges="locale|keyboardHidden|orientation|screenSize"android:name="com.dynamixsoftware.printershare.ActivityGmail"
<activity android:configChanges="locale|keyboardHidden|orientation|screenSize"android:name="com.dynamixsoftware.printershare.ActivityGmailCon <activity android:configChanges="locale|keyboardHidden|orientation|screenSize"android:icon="@drawable/icon_title"android:name="com.dynamixso <intent-filter>
<category android:name="android.intent.category.DEFAULT"/>
<action android:name="android.intent.action.VIEW"/>
<data android:scheme="file"/>
<data android:scheme="content"/>
<data android:mimeType="text/html"/>
</intent-filter>
<intent-filter>
<category android:name="android.intent.category.DEFAULT"/>
<action android:name="android.intent.action.VIEW"/>
<data android:scheme="content"/>
<data android:scheme="file"/>
<data android:host="*"/>
<data android:pathPattern=".*\\.htm"/>
<data android:pathPattern=".*\\.html"/>
</intent-filter>
<intent-filter>
<category android:name="android.intent.category.DEFAULT"/>
<action android:name="android.intent.action.SEND"/>
<data android:mimeType="text/*"/>
</intent-filter>
</activity>
<activity android:configChanges="locale|keyboardHidden|orientation|screenSize"android:icon="@drawable/icon_title"android:name="com.dynamixso <intent-filter>
<category android:name="android.intent.category.DEFAULT"/>
<action android:name="android.intent.action.VIEW"/>
<data android:scheme="content"/>
<data android:scheme="file"/>
<data android:mimeType="application/pdf"/>
</intent-filter>
<intent-filter>
<category android:name="android.intent.category.DEFAULT"/>
<action android:name="android.intent.action.SEND"/>
<data android:mimeType="application/pdf"/>
</intent-filter>
<intent-filter>
<category android:name="android.intent.category.DEFAULT"/>
<action android:name="android.intent.action.VIEW"/>
<data android:scheme="content"/>
<data android:scheme="content"/>
<data android:scheme="file"/>
<data android:host="*"/>
<data android:pathPattern=".*\\.pdf"/>
</intent-filter>
</activity>
<activity android:configChanges="locale|keyboardHidden|orientation|screenSize"android:icon="@drawable/icon_title"android:name="com.dynamixso <intent-filter>
<category android:name="android.intent.category.DEFAULT"/>
<action android:name="android.intent.action.VIEW"/>
<data android:scheme="content"/>
<data android:scheme="file"/>
<data android:mimeType="text/plain"/>
<data android:mimeType="application/vnd.ms-word"/>
<data android:mimeType="application/msword"/>
<data android:mimeType="application/doc"/>
<data android:mimeType="application/vnd.msword"/>
<data android:mimeType="application/winword"/>
<data android:mimeType="application/word"/>
<data android:mimeType="application/x-msw6"/>
<data android:mimeType="application/x-msword"/>
<data android:mimeType="application/vnd.openxmlformats-officedocument.wordprocessingml.document"/>
<data android:mimeType="application/vnd.ms-excel"/>
<data android:mimeType="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"/>
<data android:mimeType="application/vnd.ms-powerpoint"/>
<data android:mimeType="application/vnd.openxmlformats-officedocument.presentationml.presentation"/>
<data android:mimeType="application/haansofthwp"/>
</intent-filter>
<intent-filter>
<category android:name="android.intent.category.DEFAULT"/>
<action android:name="android.intent.action.SEND"/>
<data android:mimeType="message/rfc822"/>
<data android:mimeType="application/vnd.ms-word"/>
<data android:mimeType="application/msword"/>
<data android:mimeType="application/doc"/>
<data android:mimeType="application/vnd.msword"/>
<data android:mimeType="application/winword"/>
<data android:mimeType="application/word"/>
<data android:mimeType="application/x-msw6"/>
<data android:mimeType="application/x-msword"/>
<data android:mimeType="application/vnd.openxmlformats-officedocument.wordprocessingml.document"/>
<data android:mimeType="application/vnd.ms-excel"/>
<data android:mimeType="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"/>
<data android:mimeType="application/vnd.ms-powerpoint"/>
<data android:mimeType="application/vnd.openxmlformats-officedocument.presentationml.presentation"/>
<data android:mimeType="application/haansofthwp"/>
</intent-filter>
<intent-filter>
<category android:name="android.intent.category.DEFAULT"/>
<action android:name="android.intent.action.VIEW"/>
<data android:scheme="content"/>
<data android:scheme="file"/>
<data android:host="*"/>
<data android:pathPattern=".*\\.txt"/>
<data android:pathPattern=".*\\.doc"/>
<data android:pathPattern=".*\\.docx"/>
<data android:pathPattern=".*\\.xls"/>
<data android:pathPattern=".*\\.xlsx"/>
<data android:pathPattern=".*\\.ppt"/>
<data android:pathPattern=".*\\.pptx"/>
<data android:pathPattern=".*\\.hwp"/>
</intent-filter>
</activity>
<activity android:configChanges="locale|keyboardHidden|orientation|screenSize"android:name="com.dynamixsoftware.printershare.ActivityDriversBro <activity android:configChanges="locale|keyboardHidden|orientation|screenSize"android:name="com.dynamixsoftware.printershare.ActivityPrinters"
<activity android:configChanges="locale|keyboardHidden|orientation|screenSize"android:name="com.dynamixsoftware.printershare.ActivityCloudPrint
<activity android:configChanges="locale|keyboardHidden|orientation|screenSize"android:name="com.dynamixsoftware.printershare.ActivityCloudPrint <activity android:configChanges="locale|keyboardHidden|orientation|screenSize"android:name="com.dynamixsoftware.printershare.ActivityLocalPrint <activity android:configChanges="locale|keyboardHidden|orientation|screenSize"android:name="com.dynamixsoftware.printershare.ActivityFindPrinte <activity android:configChanges="locale|keyboardHidden|orientation|screenSize"android:name="com.dynamixsoftware.printershare.ActivityProfile"
<activity android:configChanges="locale|keyboardHidden|orientation|screenSize"android:name="com.dynamixsoftware.printershare.ActivityProfileEdit <activity android:configChanges="locale|keyboardHidden|orientation|screenSize"android:name="com.dynamixsoftware.printershare.ActivityAbout"
<activity android:configChanges="locale|keyboardHidden|orientation|screenSize"android:name="com.dynamixsoftware.printershare.ActivityHelp"
<activity android:configChanges="locale|keyboardHidden|orientation|screenSize"android:name="com.dynamixsoftware.printershare.ActivityPreview" <activity android:configChanges="locale|keyboardHidden|orientation|screenSize"android:icon="@drawable/icon_title"android:name="com.dynamixso <intent-filter>
<category android:name="android.intent.category.DEFAULT"/>
<action android:name="android.intent.action.VIEW"/>
<data android:mimeType="image/gif"/>
<data android:mimeType="image/png"/>
<data android:mimeType="image/jpeg"/>
</intent-filter>
<intent-filter>
<category android:name="android.intent.category.DEFAULT"/>
<action android:name="android.intent.action.SEND"/>
<action android:name="android.intent.action.SEND_MULTIPLE"/>
<data android:mimeType="image/gif"/>
<data android:mimeType="image/png"/>
<data android:mimeType="image/jpeg"/>
</intent-filter>
<intent-filter>
<category android:name="android.intent.category.DEFAULT"/>
<action android:name="android.intent.action.VIEW"/>
<data android:scheme="content"/>
<data android:scheme="file"/>
<data android:host="*"/>
<data android:pathPattern=".*\\.gif"/>
<data android:pathPattern=".*\\.png"/>
<data android:pathPattern=".*\\.jpeg"/>
<data android:pathPattern=".*\\.jpg"/>
</intent-filter>
<intent-filter>
<action android:name="com.sec.bileprint.PRINT"/>
<action android:name="com.sec.bileprint.PRINT_SETTING"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
<activity android:configChanges="locale|keyboardHidden|orientation|screenSize"android:name="com.dynamixsoftware.printershare.ActivityPrintConta <activity android:configChanges="locale|keyboardHidden|orientation|screenSize"android:name="com.dynamixsoftware.printershare.ActivityPrintMess <activity android:configChanges="locale|keyboardHidden|orientation|screenSize"android:name="com.dynamixsoftware.printershare.ActivityPrintCallLo <activity android:configChanges="locale|keyboardHidden|orientation|screenSize"android:name="com.dynamixsoftware.printershare.ActivityCalendar" <activity android:configChanges="locale|keyboardHidden|orientation|screenSize"android:name="com.dynamixsoftware.printershare.ActivityPrintCalen <activity android:configChanges="locale|keyboardHidden|orientation|screenSize"android:name="com.dynamixsoftware.printershare.ActivityPrintWeb" <activity android:configChanges="locale|keyboardHidden|orientation|screenSize"android:name="com.dynamixsoftware.printershare.ActivityPrintGmai <activity android:configChanges="locale|keyboardHidden|orientation|screenSize"android:name="com.
dynamixsoftware.printershare.ActivityPrintAndro <activity android:configChanges="locale|keyboardHidden|orientation|screenSize"android:name="com.dynamixsoftware.printershare.ActivityPrintTestP <activity android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|screenSize|smallestScreenSize|uiMode"android:hardwareAcce <service android:name="com.dynamixsoftware.printershare.AndroidPrintService"android:permission="android.permission.BIND_PRINT_SERVICE"
<intent-filter>
<action android:name="android.printservice.PrintService"/>
</intent-filter>
</service>
<receiver android:name="com.dynamixsoftware.printershare.BoxOneCloud">
<intent-filter>
<action android:name="com.box.android.VIEW_FILE"/>
<data android:mimeType="image/gif"/>
<data android:mimeType="image/png"/>
<data android:mimeType="image/jpeg"/>
<data android:mimeType="text/plain"/>
<data android:mimeType="application/pdf"/>
<data android:mimeType="application/vnd.ms-word"/>
<data android:mimeType="application/msword"/>
<data android:mimeType="application/msword"/>
<data android:mimeType="application/doc"/>
<data android:mimeType="application/vnd.msword"/>
<data android:mimeType="application/winword"/>
<data android:mimeType="application/word"/>
<data android:mimeType="application/x-msw6"/>
<data android:mimeType="application/x-msword"/>
<data android:mimeType="application/vnd.openxmlformats-officedocument.wordprocessingml.document"/>
<data android:mimeType="application/vnd.ms-excel"/>
<data android:mimeType="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"/>
<data android:mimeType="application/vnd.ms-powerpoint"/>
<data android:mimeType="application/vnd.openxmlformats-officedocument.presentationml.presentation"/>
<data android:mimeType="application/haansofthwp"/>
</intent-filter>
document有安卓版吗
<intent-filter>
<action android:name="com.box.android.LAUNCH"/>
<action android:name="com.android.vending.INSTALL_REFERRER"/>
</intent-filter>
</receiver>
</application>
<uses-feature android:name="lephony"android:required="false"/>
<uses-feature android:name="uchscreen"android:required="false"/>
<uses-feature android:name="android.hardware.bluetooth"android:required="false"/>
<uses-feature android:name="android.hardware.wifi"android:required="false"/>
<uses-feature android:name="android.hardware.usb.host"android:required="false"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.WAKE_LOCK"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.BLUETOOTH"/>
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<uses-permission android:name="android.permission.READ_CONTACTS"/>
<uses-permission android:name="android.permission.READ_CALENDAR"/>
<uses-permission android:name="android.permission.READ_CALL_LOG"/>
<uses-permission android:name="android.permission.READ_SMS"/>
<uses-permission android:name="android.permission.GET_ACCOUNTS"/>
<uses-permission android:name="android.permission.USE_CREDENTIALS"/>
<uses-permission android:name="android.permission.MANAGE_ACCOUNTS"/>
<uses-permission android:name="com.android.browser.permission.READ_HISTORY_BOOKMARKS"/>
<uses-permission android:name="leapps.permission.GOOGLE_AUTH"/>
<uses-permission android:name="leapps.permission.GOOGLE_AUTH.mail"/>
<uses-permission android:name="leapps.permission.GOOGLE_AUTH.wise"/>
<uses-permission android:name="leapps.permission.GOOGLE_AUTH.writely"/>
</manifest>
这⾥⾯到了各种⽂档格式的Activity我们只需要调⽤相应的Intent就可以了。
String path = SDCardRootDir()+"/hetong.docx";
File doc= new File(path);
Logger.e(path);
//  ComponentName comp = new ComponentName("com.dynamixsoftware.printershare","com.dynamixsoftware.printershare.ActivityPrintPDF"
ComponentName comp = new ComponentName("com.dynamixsoftware.printershare","com.dynamixsoftware.printershare.ActivityPrintDocument                Intent intent = new Intent();
intent.setComponent(comp);
intent.setAction("android.intent.action.VIEW");
intent.setType("application/doc");
intent.setData(Uri.fromFile(doc));
startActivity(intent);
OK,功能实现。关于软件中调⽤的时候你可以引导⽤户去下载对应的printershare或者⾃⼰把这个软件放到asserts⽬录静默安装(⽐较流氓),推荐第⼀种办法。
其他⾃由发挥吧

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。