react-native-device-battery icon indicating copy to clipboard operation
react-native-device-battery copied to clipboard

Readme not up to date?

Open natterstefan opened this issue 7 years ago • 1 comments

Hi,

I am not sure, if I am missing something. But, my MainActivity.java file (Android) does not look like the one in your Readme:

This is yours:

import com.robinpowered.react.battery.DeviceBatteryPackage;  // <--- import

public class MainActivity extends Activity implements DefaultHardwareBackBtnHandler {
  ......

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mReactRootView = new ReactRootView(this);

    mReactInstanceManager = ReactInstanceManager.builder()
      .setApplication(getApplication())
      .setBundleAssetName("index.android.bundle")
      .setJSMainModuleName("index.android")
      .addPackage(new MainReactPackage())
      .addPackage(new DeviceBatteryPackage()) // <------ add this line to yout MainActivity class
      .setUseDeveloperSupport(BuildConfig.DEBUG)
      .setInitialLifecycleState(LifecycleState.RESUMED)
      .build();

    mReactRootView.startReactApplication(mReactInstanceManager, "AndroidRNSample", null);

    setContentView(mReactRootView);
  }

  ......

}

This is mine:

package com.xxxxx;

import com.facebook.react.ReactActivity;

public class MainActivity extends ReactActivity {

    /**
     * Returns the name of the main component registered from JavaScript.
     * This is used to schedule rendering of the component.
     */
    @Override
    protected String getMainComponentName() {
        return "xxxxxx";
    }
}

When I try to build the app I see errors like:

public class MainActivity extends Activity implements DefaultHardwareBackBtnHandler {
                                  ^
  symbol: class Activity

My questions are:

  • do I really need to add onCreate here and not in the MainApplication.java file instead?
  • does it work with react-native 0.50.3?

Thanks for your help.

natterstefan avatar Jan 09 '18 09:01 natterstefan

Hi,

I've tried using this library in my project, using react-native 0.50.4. What I ended up doing is using react-native link, which didn't change MainActivity.java, but changed MainApplication.java instead.

Now it works.

gullsharon avatar Feb 28 '18 13:02 gullsharon