Richou / react-native-android-location-enabler

Display a GoogleMap like android popup to ask for user to enable location services if disabled
MIT License
201 stars 51 forks source link

Error: Undefined an object reactNativeAndroidLocationEnabler2 #17

Open kokorolx opened 5 years ago

kokorolx commented 5 years ago

I run this package with genymotion -- android 6.0 and have this error Please give me any help. Thanks! package.js:

"react": "16.5.0",
"expo": "^31.0.2",
screen shot 2018-12-01 at 9 26 48 pm
Richou commented 5 years ago

Can you post the code, that lead you to this error ?

kokorolx commented 5 years ago

Here is my code.

import React from 'react';
import { AppRegistry, Text, View, TouchableOpacity, StyleSheet, Alert } from 'react-native';
import RNAndroidLocationEnabler from 'react-native-android-location-enabler';
export default class App extends React.Component {
  constructor(props) {
      super(props);
    }

    componentDidMount() {
      RNAndroidLocationEnabler.promptForEnableLocationIfNeeded({interval: 10000, fastInterval: 5000})
        .then(data => {
          console.log("Location turn on")
        }).catch(err => {
          console.log("Location error: ", err)
        });
    }

    render() {
      return (
        <View style={style.container}>
          <Text style={style.text}>Hello</Text>
        </View>
      );
    }
  }

  const style = StyleSheet.create({
    container: {
      flex: 1,
      alignItems: 'center',
      justifyContent: 'center',
    },
    button: {
      padding: 20,
    },
    text: {
      fontSize: 20,
    },
    textSuccess: {
      fontSize: 20,
      color: 'green',
    },
  });

the image above was checkout. I created new project and have the same error image

Richou commented 5 years ago

Ok, I'll will check this asap.

Vigneshshivan-source commented 5 years ago

same issue plz

Richou commented 5 years ago

Did you add the following lines in your android/settings.gradle

include ':react-native-android-location-enabler'
project(':react-native-android-location-enabler').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-android-location-enabler/android')

And this line in dependencies section of your android/app/build.gradle

compile project(':react-native-android-location-enabler')

And finally in your MainApplication.java

import com.heanoria.library.reactnative.locationenabler.RNAndroidLocationEnablerPackage; // Import line

public class MainApplication extends Application implements ReactApplication {

    @Override
    protected List<ReactPackage> getPackages() {
      return Arrays.<ReactPackage>asList(
          new MainReactPackage(),
          new RNAndroidLocationEnablerPackage() // And this one
      );
    }
}
Vigneshshivan-source commented 5 years ago

I will try and thanks for reply

On Sun, Jan 13, 2019, 03:37 Richard notifications@github.com wrote:

Did you add the following lines in your android/settings.gradle

include ':react-native-android-location-enabler' project(':react-native-android-location-enabler').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-android-location-enabler/android')

And this line in dependencies section of your android/app/build.gradle

compile project(':react-native-android-location-enabler')

And finally in your MainApplication.java

import com.heanoria.library.reactnative.locationenabler.RNAndroidLocationEnablerPackage; // Import line public class MainApplication extends Application implements ReactApplication {

@Override
protected List<ReactPackage> getPackages() {
  return Arrays.<ReactPackage>asList(
      new MainReactPackage(),
      new RNAndroidLocationEnablerPackage() // And this one
  );
}

}

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/Richou/react-native-android-location-enabler/issues/17#issuecomment-453784592, or mute the thread https://github.com/notifications/unsubscribe-auth/AsMRMbUw9CTU6-aca1BtIJfatxsg90R0ks5vClyqgaJpZM4Y86_e .

fnLog0 commented 5 years ago

Same issue here..

Richou commented 5 years ago

Did you follow the installation instruction correctly ?

narek11 commented 5 years ago

same issue

fnLog0 commented 5 years ago

Did you follow the installation instruction correctly ?

yes

fnLog0 commented 5 years ago

RNAndroidLocationEnabler is Undefined

Richou commented 5 years ago

@devnasim Did you import the RNAndroidLocationEnabler in your code ?

import RNAndroidLocationEnabler from 'react-native-android-location-enabler';
djguruwap commented 5 years ago

does it work on expo ?

andrey-shostik commented 5 years ago

when I import the module import RNAndroidLocationEnabler from 'react-native-android-location-enabler'; I get in RNAndroidLocationEnabler undefined value

louicoder commented 4 years ago

when I import the module import RNAndroidLocationEnabler from 'react-native-android-location-enabler'; I get in RNAndroidLocationEnabler undefined value

@andrey-shostik Are you running this on iOS, as far as I'm concerned this will be null or undefined for iOS, wrap this function inside a platform check. I have realised this only works with Android since it's there's a different procedure for toggling location on and off for iOS. Do something like:

if (Platform.OS === 'android') {
  toggleLocation(); // check whether location is enabled or not
} else {
  // block to check ios location enabled or not
}
JardelSchaefer commented 4 years ago

Same problem here, did anyone find the solution?

BrunoTerra97 commented 4 years ago

Same problem here, did anyone find the solution?

A had the same problem. To fix this i did: $ npm start -- --reset-cache $ react-native run-android

JardelSchaefer commented 4 years ago

Same problem here, did anyone find the solution?

A had the same problem. To fix this i did: $ npm start -- --reset-cache $ react-native run-android

Unfortunately I'm using the expo, but I had looked at a topic here and they said it works = (

meta-utkarsh-ahuja commented 10 months ago

Did you add the following lines in your android/settings.gradle

include ':react-native-android-location-enabler'
project(':react-native-android-location-enabler').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-android-location-enabler/android')

And this line in dependencies section of your android/app/build.gradle

compile project(':react-native-android-location-enabler')

And finally in your MainApplication.java


import com.heanoria.library.reactnative.locationenabler.RNAndroidLocationEnablerPackage; // Import line

public class MainApplication extends Application implements ReactApplication {

    @Override
    protected List<ReactPackage> getPackages() {
      return Arrays.<ReactPackage>asList(
          new MainReactPackage(),
          new RNAndroidLocationEnablerPackage() // And this one
      );
    }
}
```same but no thing changed please help me out
Pankaj2208 commented 6 months ago

please anyone proper solution for that?