Skip to content

Commit

Permalink
#18 Listener not working
Browse files Browse the repository at this point in the history
-Adjusted the Listener logic to fix the crash when even published.
-Adds the demos as well.
-Upgrades the version to 0.1.5
  • Loading branch information
januslo committed Oct 16, 2017
1 parent 83fcdfc commit 3f3618e
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 26 deletions.
2 changes: 1 addition & 1 deletion android/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.sunmi.innerprinter">
<application>
<receiver android:name="com.sunmi.innerprinter.SunmiInnerPrinterModule.PrinterReceiver" android:enabled="true">
<receiver android:name="com.sunmi.innerprinter.PrinterReceiver" android:enabled="true">
<intent-filter android:priority="1000">
<!-- 缺纸异常 -->
<action android:name="woyou.aidlservice.jiuv5.OUT_OF_PAPER_ACTION" />
Expand Down
23 changes: 23 additions & 0 deletions android/src/main/java/com/sunmi/innerprinter/PrinterReceiver.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.sunmi.innerprinter;

import android.content.BroadcastReceiver;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContext;
import android.content.Context;
import android.content.Intent;
import com.facebook.react.modules.core.DeviceEventManagerModule;
import android.util.Log;

public class PrinterReceiver extends BroadcastReceiver {
public PrinterReceiver() {
}

@Override
public void onReceive(Context context, Intent data) {
String action = data.getAction();
String type = "PrinterStatus";
Log.d("PrinterReceiver", action);
SunmiInnerPrinterModule.reactApplicationContext.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
.emit(type, action);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,10 @@
import java.util.HashMap;

public class SunmiInnerPrinterModule extends ReactContextBaseJavaModule {
public static ReactApplicationContext reactApplicationContext;
private IWoyouService woyouService;
private BitmapUtils bitMapUtils;
private PrinterReceiver receiver = new PrinterReceiver();
private PrinterReceiver receiver=new PrinterReceiver();

// 缺纸异常
public final static String OUT_OF_PAPER_ACTION = "woyou.aidlservice.jiuv5.OUT_OF_PAPER_ACTION";
Expand Down Expand Up @@ -82,14 +83,13 @@ public void onServiceConnected(ComponentName name, IBinder service) {

public SunmiInnerPrinterModule(ReactApplicationContext reactContext) {
super(reactContext);

Intent intent = new Intent();
reactApplicationContext = reactContext;
Intent intent = new Intent();
intent.setPackage("woyou.aidlservice.jiuiv5");
intent.setAction("woyou.aidlservice.jiuiv5.IWoyouService");
reactContext.startService(intent);
reactContext.bindService(intent, connService, Context.BIND_AUTO_CREATE);
bitMapUtils = new BitmapUtils(reactContext);

IntentFilter mFilter = new IntentFilter();
mFilter.addAction(OUT_OF_PAPER_ACTION);
mFilter.addAction(ERROR_ACTION);
Expand All @@ -100,9 +100,7 @@ public SunmiInnerPrinterModule(ReactApplicationContext reactContext) {
mFilter.addAction(KNIFE_ERROR_2_ACTION);
mFilter.addAction(OVER_HEATING_ACITON);
mFilter.addAction(FIRMWARE_UPDATING_ACITON);

getReactApplicationContext().registerReceiver(receiver, mFilter);

Log.d("PrinterReceiver", "------------ init ");
}

Expand Down Expand Up @@ -981,21 +979,4 @@ public void onRaiseException(int code, String msg) {
}
});
}


public static class PrinterReceiver extends BroadcastReceiver {
public PrinterReceiver() {
}

@Override
public void onReceive(Context context, Intent data) {
String action = data.getAction();
String type = "PrinterStatus";
Log.d("PrinterReceiver", action);
if (context instanceof ReactContext) {
((ReactContext) context).getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
.emit(type, action);
}
}
}
}
50 changes: 49 additions & 1 deletion examples/index.android.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-native-sunmi-inner-printer",
"version": "0.1.4",
"version": "0.1.5",
"description": "http://docs.sunmi.com/htmls/index.html?lang=zh##V1文档资源 根据商米V1文档开发的蓝牙打印for React Native.",
"author": "Janus J K Lu <[email protected]>",
"contributors": [],
Expand Down

1 comment on commit 3f3618e

@januslo
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#14 fixed as well

Please sign in to comment.