@ReactMethod public void createSpeechRecognizer(final Promise promise) { if (reactContext == null) throw new IllegalArgumentException("ReactApplicationContext must be defined!"); if (mSpeechRecognizer != null) { mSpeechRecognizer.destroy(); mSpeechRecognizer = null; } if (SpeechRecognizer.isRecognitionAvailable(reactContext)) { mSpeechRecognizer = SpeechRecognizer.createSpeechRecognizer(reactContext); mSpeechRecognizer.setRecognitionListener(new SpeechRecognitionListener( this.reactContext.getJSModule(RCTNativeAppEventEmitter.class) )); promise.resolve(null); } else{ promise.reject("error", "SpeechRecognizer not available"); } }
@ReactMethod public void initialize() { ReactApplication application = (ReactApplication)getReactApplicationContext() .getCurrentActivity() .getApplication(); DevSupportManager devSupportManager = application .getReactNativeHost() .getReactInstanceManager() .getDevSupportManager(); devSupportManager.addCustomDevOption("Log AsyncStorage", new DevOptionHandler() { @Override public void onOptionSelected() { getReactApplicationContext() .getJSModule(RCTNativeAppEventEmitter.class) .emit("LogAsyncStorage", null); } }); }
@Override public List<Class<? extends JavaScriptModule>> createJSModules() { List<Class<? extends JavaScriptModule>> jsModules = new ArrayList<>(Arrays.asList( DeviceEventManagerModule.RCTDeviceEventEmitter.class, JSTimersExecution.class, RCTEventEmitter.class, RCTNativeAppEventEmitter.class, AppRegistry.class, com.facebook.react.bridge.Systrace.class, HMRClient.class)); if (ReactBuildConfig.DEBUG) { jsModules.add(DebugComponentOwnershipModule.RCTDebugComponentOwnership.class); jsModules.add(JSCHeapCapture.HeapCapture.class); jsModules.add(JSCSamplingProfiler.SamplingProfiler.class); } return jsModules; }
public ListenerMapRecognitionListener( Set<String> enabledEvents, RCTNativeAppEventEmitter emitter, String eventPrefix ) { this.enabledEvents = enabledEvents; this.emitter = emitter; this.eventPrefix = eventPrefix; }
private void doCreateSpeechRecognizer(final Promise promise) { this.speechRecognizer = SpeechRecognizer.createSpeechRecognizer(this.reactContext); this.speechRecognizer.setRecognitionListener(new ListenerMapRecognitionListener( this.enabledEvents, this.reactContext.getJSModule(RCTNativeAppEventEmitter.class), this.eventPrefix )); promise.resolve(null); }
public void sendEvent(String eventName, @Nullable WritableMap params) { if(reactContext!=null) getReactApplicationContext() .getJSModule(RCTNativeAppEventEmitter.class) .emit(eventName, params); }
private void sendEvent(String eventName, @Nullable WritableMap params) { if(this.reactContext==null) return; reactContext .getJSModule(RCTNativeAppEventEmitter.class) .emit(eventName, params); }
@Override public void onReceive(Context context, Intent intent) { if (MPushService.ACTION_MESSAGE_RECEIVED.equals(intent.getAction())) { byte[] bytes = intent.getByteArrayExtra(MPushService.EXTRA_PUSH_MESSAGE); int messageId = intent.getIntExtra(MPushService.EXTRA_PUSH_MESSAGE_ID, 0); String message = new String(bytes, Constants.UTF_8); // Toast.makeText(context, "收到新的通知:" + message, Toast.LENGTH_SHORT).show(); if (messageId > 0) MPush.I.ack(messageId); if (TextUtils.isEmpty(message)) return; reactContext.getJSModule(RCTNativeAppEventEmitter.class).emit(MPUSH_EVENT_MESSAGE, message); } else { //reactContext.getJSModule(RCTNativeAppEventEmitter.class).emit(MPUSH_EVENT, intent.getAction()); } Log.d("MPush", intent.toString()); if (MPushService.ACTION_KICK_USER.equals(intent.getAction())) { Toast.makeText(context, "用户被踢下线了", Toast.LENGTH_SHORT).show(); } else if (MPushService.ACTION_BIND_USER.equals(intent.getAction())) { Toast.makeText(context, "绑定用户:" + intent.getStringExtra(MPushService.EXTRA_USER_ID) + (intent.getBooleanExtra(MPushService.EXTRA_BIND_RET, false) ? "成功" : "失败") , Toast.LENGTH_SHORT).show(); } else if (MPushService.ACTION_UNBIND_USER.equals(intent.getAction())) { Toast.makeText(context, "解绑用户:" + (intent.getBooleanExtra(MPushService.EXTRA_BIND_RET, false) ? "成功" : "失败") , Toast.LENGTH_SHORT).show(); } else if (MPushService.ACTION_CONNECTIVITY_CHANGE.equals(intent.getAction())) { Toast.makeText(context, intent.getBooleanExtra(MPushService.EXTRA_CONNECT_STATE, false) ? "MPUSH连接建立成功" : "MPUSH连接断开" , Toast.LENGTH_SHORT).show(); } else if (MPushService.ACTION_HANDSHAKE_OK.equals(intent.getAction())) { Toast.makeText(context, "MPUSH握手成功, 心跳:" + intent.getIntExtra(MPushService.EXTRA_HEARTBEAT, 0) , Toast.LENGTH_SHORT).show(); } }
private void sendEvent(String eventName, @Nullable WritableMap params) { //ReactApplicationContext r = getReactApplicationContext(); //RCTNativeAppEventEmitter jm = r.getJSModule(RCTNativeAppEventEmitter.class); //jm.emit(eventName, params); //getReactApplicationContext() this.reactContext.getJSModule(RCTNativeAppEventEmitter.class) .emit(eventName, params); }
public void getLocales() { Intent detailsIntent = new Intent(RecognizerIntent.ACTION_GET_LANGUAGE_DETAILS); reactContext.sendOrderedBroadcast( detailsIntent, null, new LocalesBroadcastReceiver(this.reactContext.getJSModule(RCTNativeAppEventEmitter.class)), null, Activity.RESULT_OK, null, null); }
@Override public BarcodePicker createViewInstance(ThemedReactContext context) { // Store event dispatcher for emission of events eventDispatcher = context.getNativeModule(UIManagerModule.class).getEventDispatcher(); nativeAppEventEmitter = context.getJSModule(RCTNativeAppEventEmitter.class); // BarcodePicker extends View picker = new BarcodePicker(context, scanSettings); // Tell picker to call our didScan method on scan picker.setOnScanListener(this); return picker; }
@Override public List<Class<? extends JavaScriptModule>> createJSModules() { return Arrays.asList( DeviceEventManagerModule.RCTDeviceEventEmitter.class, JSTimersExecution.class, RCTEventEmitter.class, RCTNativeAppEventEmitter.class, AppRegistry.class, com.facebook.react.bridge.Systrace.class, HMRClient.class, DebugComponentOwnershipModule.RCTDebugComponentOwnership.class); }
@Override public List<Class<? extends JavaScriptModule>> createJSModules() { return Arrays.asList( DeviceEventManagerModule.RCTDeviceEventEmitter.class, JSTimersExecution.class, RCTEventEmitter.class, RCTNativeAppEventEmitter.class, com.facebook.react.bridge.Systrace.class, JSCHeapCapture.HeapCapture.class ); }
@Override public List<Class<? extends JavaScriptModule>> createJSModules() { return Arrays.asList( DeviceEventManagerModule.RCTDeviceEventEmitter.class, JSTimersExecution.class, RCTEventEmitter.class, RCTNativeAppEventEmitter.class, AppRegistry.class, com.facebook.react.bridge.Systrace.class, HMRClient.class, JSCHeapCapture.HeapCapture.class, DebugComponentOwnershipModule.RCTDebugComponentOwnership.class); }
@Override public void onActivityResult(Activity activity , final int requestCode, final int resultCode, final Intent data) { if (requestCode == REQUEST_CODE_PAYMENT && resultCode == activity.RESULT_OK) { this.handleResultData(data); } else { RCTNativeAppEventEmitter emitter = getReactApplicationContext().getJSModule(RCTNativeAppEventEmitter.class); WritableMap map = Arguments.createMap(); map.putString("errMsg", "返回错误"); emitter.emit("Pingpp_Resp", map); } }
private void handleResultData(Intent data) { String result = data.getExtras().getString("pay_result"); if (result != null) { RCTNativeAppEventEmitter emitter = getReactApplicationContext().getJSModule(RCTNativeAppEventEmitter.class); WritableMap map = Arguments.createMap(); map.putString("result", result); if (!result.equals("success")) { map.putInt("errCode", data.getExtras().getInt("code")); map.putString("errMsg", data.getExtras().getString("error_msg")); map.putString("extraMsg", data.getExtras().getString("extra_msg")); } emitter.emit("Pingpp_Resp", map); } }
/** * Helper for sending events back to Javascript. * * @param eventName * @param params */ private void sendAppEvent(String eventName, Object params) { ReactApplicationContext context = this.getReactApplicationContext(); if (context == null || !context.hasActiveCatalystInstance()) { return; } context .getJSModule(RCTNativeAppEventEmitter.class) .emit(eventName, params); }
protected void sendEvent( String eventName, Object data) { reactContext .getJSModule(RCTNativeAppEventEmitter.class) .emit(eventName, data); }
private void sendEvent(String eventName, @Nullable WritableMap params) { getReactApplicationContext() .getJSModule(RCTNativeAppEventEmitter.class) .emit(eventName, params); }
private void sendEvent(String eventName, @Nullable WritableMap params) { reactContext .getJSModule(RCTNativeAppEventEmitter.class) .emit(eventName, params); }
public LocalesBroadcastReceiver(RCTNativeAppEventEmitter emitter) { this.emitter = emitter; }
public SpeechRecognitionListener(RCTNativeAppEventEmitter emitter) { this.emitter = emitter; }
public void sendEvent(String eventName, @Nullable WritableMap params) { getReactApplicationContext() .getJSModule(RCTNativeAppEventEmitter.class) .emit(eventName, params); }
private void sendEvent(String eventName) { getReactApplicationContext() .getJSModule(RCTNativeAppEventEmitter.class) .emit(eventName, null); }
private void sendEvent(ReactContext reactContext, String eventName, @Nullable WritableMap params) { reactContext .getJSModule(RCTNativeAppEventEmitter.class) .emit(eventName, params); }
@Override public void onPowerSaveChange(Boolean isPowerSaveMode) { getReactApplicationContext().getJSModule(RCTNativeAppEventEmitter.class).emit(BackgroundGeolocation.EVENT_POWERSAVECHANGE, isPowerSaveMode); }
private void sendEvent(String eventName, WritableMap params) { getReactApplicationContext().getJSModule(RCTNativeAppEventEmitter.class).emit(eventName, params); }
private void sendEvent(String eventName, String result) { getReactApplicationContext().getJSModule(RCTNativeAppEventEmitter.class).emit(eventName, result); }