Android 使用第三方软件PrinterShare实现USB 或WIFI 打印功能

news/2024/10/18 10:14:52/

想要调用第三方软件首先必须知道intent
这里使用逆向工具获取清单文件的IntentFilter

PrinterShare 清单

 <activity android:configChanges="keyboardHidden|locale|orientation|screenSize" android:icon="@drawable/icon_title" android:name="com.dynamixsoftware.printershare.ActivityWeb"><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="keyboardHidden|locale|orientation|screenSize" android:icon="@drawable/icon_title" android:name="com.dynamixsoftware.printershare.ActivityPrintPDF"><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="file"/><data android:host="*"/><data android:pathPattern=".*\\.pdf"/></intent-filter></activity><activity android:configChanges="keyboardHidden|locale|orientation|screenSize" android:icon="@drawable/icon_title" android:name="com.dynamixsoftware.printershare.ActivityPrintDocuments"><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="keyboardHidden|locale|orientation|screenSize" android:icon="@drawable/icon_title" android:name="com.dynamixsoftware.printershare.ActivityPrintPictures"><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="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.android.app.mobileprint.PRINT"/><action android:name="com.sec.android.app.mobileprint.PRINT_SETTING"/><category android:name="android.intent.category.DEFAULT"/></intent-filter>
</activity>

主要就4个Activity

  • ActivityPrintPDF 打印PDF
  • ActivityPrintDocuments 打印文档
  • ActivityPrintPictures 打印图片
  • ActivityWeb 打印网页

最后根据intent-filter 封装工具类

package me.leon;import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Environment;
import android.text.TextUtils;import java.io.File;/*** <p>description:</p>* <p>author:Leon</p>* <p>date:2019/7/18 0018</p>* <p>e-mail:deadogone@gmail.com</p>*/
public class PrinterShareMgr {private static PrinterShareMgr mgr = new PrinterShareMgr();public static PrinterShareMgr getInstance() {return mgr;}private PrinterShareMgr() {}public void printFile(Context context, String filePath) {if (TextUtils.isEmpty(filePath)) {return;}Intent intent = new Intent(Intent.ACTION_VIEW);Uri data = Uri.fromFile(new File(filePath));ComponentName comp = null;if (filePath.endsWith("pdf")) {intent.setDataAndType(data,"application/pdf");comp = new ComponentName("com.dynamixsoftware.printershare", "com.dynamixsoftware.printershare.ActivityPrintPDF");} else if (filePath.endsWith("doc") || filePath.endsWith("docx")||filePath.endsWith("txt")){intent.setDataAndType(data,"application/doc");comp = new ComponentName("com.dynamixsoftware.printershare", "com.dynamixsoftware.printershare.ActivityPrintDocuments");}else if (filePath.endsWith("jpg") || filePath.endsWith("jpeg") || filePath.endsWith("gif") || filePath.endsWith("png")){intent.setDataAndType(data,"image/jpeg");comp = new ComponentName("com.dynamixsoftware.printershare", "com.dynamixsoftware.printershare.ActivityPrintPictures");}else if (filePath.endsWith("html")||filePath.endsWith("htm")){intent.setDataAndType(data,"text/html");comp = new ComponentName("com.dynamixsoftware.printershare", "com.dynamixsoftware.printershare.ActivityWeb");}intent.setComponent(comp);context.startActivity(intent);}
}

Note:

  1. 安装PrinterShare完成后 请自行更新对应打印机驱动
  2. 请自行兼容android 7.0 及补全未包含的文件格式
  3. 隐藏导航栏时,打印成功无法返回

参考
https://blog.csdn.net/qilin001cs/article/details/54616108
附件下载:
PrinterShare
AndroidKiller 1.3.1 csdn 蓝奏


http://www.ppmy.cn/news/338918.html

相关文章

cxGrid自动保存当前单元格输入的数据

遇到的问题&#xff0c;利用cxGrid做数据录入界面&#xff0c;当用户在一个单元格中录入数据&#xff0c;没有回车&#xff0c;然后直接点工具条上的保存按钮&#xff0c;执行数据提交&#xff0c;结果当前输入的内容丢掉了&#xff0c;又回到输入前的值。 在群中求助&#xf…

优友机器人价格_优友U05类人型机器人 换汤不换药

在过去机器人听起来似乎和现在的社会太遥远&#xff0c;但是随着科技的进步&#xff0c;机器人已不再是那么神秘了。尽管现在的机器人层出不穷&#xff0c;但功能单一&#xff0c;没有多大的创新&#xff0c;只不过是换汤不换药。和电影里的机器人相差甚远。 北京时间11月24号&…

欢颜机器人价格_好口碑的欢颜机器人现货,欢颜机器人厂家报价

好口碑的欢颜机器人现货 欢颜机器人焊接机器人的使用不仅可以稳定和提高焊接质量&#xff0c;提高生产效率&#xff0c;而且还降低了对工人焊接技术的要求&#xff0c;从而缩短了产品升级的准备周期&#xff0c;减少了相应的设备投资。选择自动生产线结构相匹配、适合的焊接机器…

电销机器人价格_电话电销机器人价格如何?会很贵吗?

如今人工智能非常流行&#xff0c;越来越多的产品被打上智能标签以提高价格。因此&#xff0c;当人们听到“智能”这个词时&#xff0c;他们会第一时间就会想到价格一定很贵吧&#xff01;那么电话电销机器人价格如何?会很贵吗&#xff1f;在这里就由深圳易网行电销机器人的小…

机器人杆长标定_机器人校准系统

机器人校准系统 AutoCal 在线机器人校准方案 专为快速自动确保机器人设备性能。适用于不同机器人应用&#xff0c;与大多数机器人类型兼容。能够检测机器人 结构的偏移或瞬间变化&#xff0c;然后自动更正错误。不浪费宝贵时间且质量保证。 主要是用于机器人中心点复位。完全在…

机器人避障相关知识

目录 一、避障概念&#xff1a; 二、避障常用哪些传感器 2.1 超声波 2.2 红外 2.3 激光 2.4 视觉 三、避障常用算法原理 3.1 Bug算法 3.2 势场法&#xff08;PFM&#xff09; 3.3 向量场直方图&#xff08;VFH&#xff09; 3.4 模糊逻辑控制 3.5 人工神经网络避障…

返利机器人分享话术_返利机器人裂变话术

百应电销机器人话术怎么弄? 答&#xff1a;话术录入是不需要自己太操心的&#xff0c;只要是整理好完整的话术&#xff0c;让闪赢科技的工作人员来进行话术的录入就可以了 电话邀约的脚本话术 邀约方(简称1)被邀方(简称2)如下: 1:您好!请问是*先生/*小姐吗? 2:你是? 1:*先生…

scara机器人动荷载_揭密SCARA机器人

原标题&#xff1a;揭密SCARA机器人 SCARA机器人&#xff0c;即Selective Compliance AssemblyRobot Arm&#xff0c;又名水平多关节机器人&#xff0c;是工业机器人家庭应用非常广泛的一个构型。 SCARA机器人有3个旋转关节&#xff0c;其轴线相互平行&#xff0c;在平面内进行…