darryncampbell / react-native-datawedge-intents

React Native interface for Zebra's DataWedge Intent API
MIT License
43 stars 46 forks source link

Problem linking DataWedgeIntents #14

Closed mindaugasnakrosis closed 3 years ago

mindaugasnakrosis commented 3 years ago

I just bought a Zebra TC21 phone and I am trying to implement DataWedge intents into my application on it. Using expo and tried running commands:

yarn add react-native-datawedge-intents
react-native link react-native-datawedge-intents 

I get a warning:

warn Calling react-native link [packageName] is deprecated in favor of autolinking. It will be removed in the next major release.
Autolinking documentation: https://github.com/react-native-community/cli/blob/master/docs/autolinking.md

However, I believe it links anyway. Then I run expo start --android which runs android react-native application on my connected device.

Then I get an error: TypeError: null is not an object (evaluating 'RNDataWedgeIntents.ACTION_SOFTSCANTRIGGER')

It might be a problem with expo, so I tried running: yarn react-native run-android

It doesn't recognise that this is an android project:

error Android project not found. Are you sure this is a React Native project?. Run CLI with --verbose flag for more details.

Any suggestions what I should try? This looked like a similar issue as https://github.com/darryncampbell/react-native-datawedge-intents/issues/3.

However I am not using create-react-app.

I am using React Native 0.61

darryncampbell commented 3 years ago

I have never used expo before but I gave it a try...

I ran through the instructions at https://docs.expo.io/bare/exploring-bare-workflow/ to spin up a new expo app. You need to use the "bare workflow" as this app has native Android code (Intents)

I ran react-native-unimodules but I'm not certain if that was necessary Then yarn add react-native-datawedge-intents as you had done

Then modified App.js as follows:

import { StatusBar } from 'expo-status-bar';
import React from 'react';
import { StyleSheet, Text, View, TouchableOpacity } from 'react-native';
import DataWedgeIntents from 'react-native-datawedge-intents';

export default function App() {
  return (
    <View style={styles.container}>
      <Text>Open up App.js to start working on your app!</Text>
      <StatusBar style="auto" />

      <TouchableOpacity
        onPress={() => DataWedgeIntents.sendBroadcastWithExtras({
        action: "com.symbol.datawedge.api.ACTION",
        extras: {"com.symbol.datawedge.api.SOFT_SCAN_TRIGGER":"START_SCANNING"}})}
        style={{ backgroundColor: 'blue' }}>
        <Text style={{ fontSize: 20, color: '#fff' }}> Emit Beam </Text>
      </TouchableOpacity>
    </View>
  );
}

Then yarn android to run it. The scanner beam will emit when you press the button which shows that in principle this should work.

mindaugasnakrosis commented 3 years ago

Thanks for a quick answer, looks like initialising expo with bare project type fixes the issue.