npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

com.cordova.plugins.sunmi

v1.0.8

Published

cordova plugin for sunmi devices

Downloads

5

Readme

功能

  1. 获取SN,兼容Android 10 以上商米设备
  2. 打印,兼容Android 10 以上商米设备

安装

cordova plugin add com.cordova.plugins.sunmi

SN

问题1:V2S获取不到SN

原因:Android 10开始,权限变更,原来获取SN的方法不再支持
解决方案:使用商米官方提供的方法
  1. 将商米官方提供的方法封装为cordova插件

  2. 安装sunmi插件

    cordova plugin add com.cordova.plugins.sunmi  //已封装获取SN功能
  3. 修改npn.init.js onDeviceReady方法,改后的代码如下

    var onDeviceReady = function(){
            NPNLib.init();
            NPNLib.deviceSN(function(res){
                deviceSN = res;
       
                deviceVersion = NPNLib.appVersion();
                //调用通知事件
                NPNLib.notificationRegister(notifi_event_callback);
                document.addEventListener("backbutton", function(){
                    return false;
                }, false);
       
                //footer 展示sn 和版本号
               $("#footer_sn").html("Version:"+deviceVersion+"          SN:"+deviceSN);
            });
        }
  4. 修改npn.lib.js deviceSN方法,改后的代码如下:

    deviceSN: function(success) {
          window.sunmi.getSN(function(res){
                success(res);
          }, function(err){
              success("unknown")
          });
      },

打印

问题1:V2S不打印

原因:Android 10开始,商米原生打印有修改,不可兼容使用
解决方案:使用商米远程接口,远程判断型号,自动适配。
  1. 根目录下的build.gradle文件增加中央仓库

    jcenter()下增加下面内容:
    mavenCentral()
  2. 引入google core包

    复制 core-3.3.0.jar 到 platforms\android\app\libs
  3. app目录下的build.gradle文件增加依赖

    implementation('com.sunmi:printerlibrary:1.0.19')
  4. 针对V2s和V2s_plus,在AndroidManifest.xml中添加包引用:

    <uses-permission android:name="android.permission.BLUETOOTH" />下,增加下面内容:
       
    <queries>
        <package android:name="woyou.aidlservice.jiuiv5" />
    </queries>
  5. 更新sunmi插件

    // 卸载插件
    cordova plugin remove com.cordova.plugins.sunmi
    //重新安装插件
    cordova plugin add com.cordova.plugins.sunmi
  6. 移除pos插件

    cordova plugin remove com.cordova.plugins.pos
  7. 修改npn.lib.js

    改为使用新的打印方法
    	window.pos. 改为 window.sunmi.
  8. 重新编译

    Terminal 执行:
    	cordova build
    Android Studio执行:
    	Build > Make Project

问题2:V2 打印QR过大

原因:官方打印sdk,宽度从1-12分段,需转换数值
解决方案:转换计算
  1. 修改platforms/android/app/src/main/java/com/npn/utils/SunmiPrinterUtil.java

    else if (param.containsKey("qrcode")) {
                        int width = 6;
       
                        SunmiPrintHelperUtil.getInstance().setAlign(1);//默认居中  0-left;1-center;2-right
                        SunmiPrintHelperUtil.getInstance().printQr(param.get("qrcode"),width,3,callback);
                        SunmiPrintHelperUtil.getInstance().setAlign(0);//打印完成还原为居左 0-left;1-center;2-right
                    }

通知

问题1:横幅通知不显示

原因:Android 8开始,创建通知需先创建channel
解决方案:创建channel
  1. 修改notification插件,兼容Android 8以后设备

  2. 重装notification插件

    // 卸载插件
    cordova plugin remove com.cordova.plugins.notification
    //重新安装插件
    cordova plugin add com.cordova.plugins.notification

问题2:服务器通知接收不到

原因:建立socket连接时,未成功。因为SN还是使用老的方式获取
解决方案:重新按商米官方方式获取SN
  1. 修改platforms/android/app/src/main/java/com/npn/utils/GlobalUtils.java文件

    	getSN() 
    	内容改为:
    	public static String getSN() {
    		if (sn == null) {
    			if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
    				String serial = null;
    				try {
    					Class<?> c =Class.forName("android.os.SystemProperties");
    					Method get =c.getMethod("get", String.class);
    					serial = (String)get.invoke(c, "ro.sunmi.serial");
    				} catch (Exception e) {
    					e.printStackTrace();
    				}
    				sn = serial;
    			} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
    				sn = Build.getSerial();
    			} else {
    				sn = Build.SERIAL;
    			}
    		}
    		return sn;
    	}

问题3:通知显示上下不居中

原因:view设置问题
解决方案:优化界面设置
  1. 修改platforms/android/app/src/main/res/layout/view_notify.xml文件

    //RelativeLayout
    gravity设置center_vertical
    //notify_icon 
    margin top修改为20dip
    //LinearLayout
    layout_height设置为90dip
    gravity设置center_vertical