Android sensor manager-react native error - android

I need to access accelerometer in my react native app. Apparently the only one for Android is this one and it does not work. Ive even tried it on a separate clean project and still shows undefined is not an object (evaluating mSensorManager.startAccelerometer). I'm using the sample code provided in readme, What am I doing wrong?
PS: I'm using an actual device, not a VM.

The problem is solved here. I added to MainActivity.java following code:
import com.facebook.react.ReactPackage;
import com.facebook.react.shell.MainReactPackage;
import com.sensormanager.SensorManagerPackage;
import java.util.Arrays;
import java.util.List;
protected List<ReactPackage> getPackages() {
return Arrays.<ReactPackage>asList(
new MainReactPackage(),
new SensorManagerPackage()
);
}

Make sure to follow the steps in the README file.
after you do the npm i react-native-sensor-manager --save ,
instead of doing rnpm link , my approach was to do react-native link react-native-sensor-manager and you are done.
import it using import { SensorManager } from 'NativeModules'
It would definitely work.

Related

How to use react-native-batch-push on android? RNBatch is undefined when trying to access RNBatch.NOTIFICATION_TYPES

I'm trying to use this package in my react native project.
So far I've followed all the steps in their installation guide and I made it work on iOS.
However, on Android, every time I try to import Batch or BatchPush in my code like this:
import { BatchPush, Batch } from "#bam.tech/react-native-batch";
I get an error on Android only:
null is not an object (evaluating 'RNBatch.NOTIFICATION_TYPES')
So when I go to node_modules/#bam.tech/react-native-batch/dist/BatchPush.js I see this
const RNBatch = react_native_1.NativeModules.RNBatch;
exports.AndroidNotificationTypes = RNBatch.NOTIFICATION_TYPES;
So somehow the native module is not being imported correctly. Do I need to follow extra steps for this to work?
#bam.tech/react-native-batch is being used with version 5.2.1
npm version 6.14.7
react-native version 0.60.5
Update: it turns out that the package was not linked correctly and that I had to manually add the package in MainApplication.java (I don't know why react-native link did not add this automatically)
Add the import:
import tech.bam.RNBatchPush.RNBatchPackage;
And then add
new RNBatchPackage(), in the getPackages() method.

React Native Android app white screen won't start

I get the following error log when I run my Android app: http://pastebin.com/1jHEfdQ3 The app sometimes crashes in the simulator but most of the time it just displays a white screen. I can console.log one or two things until the app won't respond. R-R to refresh doesn't work. None of the dev tools work. I'm stumped with what to do at this point.
I'm running react native 0.38.0
EDIT:
I've tried cleaning my gradle and deleting and reinstalling my node modules.
One thing to note is that I am using React Native Navigation which means I had to modify MainApplication and MainActivity to the following:
MainActivity:
package com.prayerrequest;
import com.facebook.react.ReactActivity;
import com.reactnativenavigation.NavigationApplication;
import com.airbnb.android.react.maps.MapsPackage;
import com.cmcewen.blurview.BlurViewPackage;
import io.realm.react.RealmReactPackage;
import com.reactnativenavigation.controllers.SplashActivity;
public class MainActivity extends SplashActivity {
}
MainApplication:
package com.prayerrequest;
import com.facebook.react.ReactPackage;
import com.cmcewen.blurview.BlurViewPackage;
import io.realm.react.RealmReactPackage;
import com.airbnb.android.react.maps.MapsPackage;
import com.reactnativenavigation.NavigationApplication;
import java.util.Arrays;
import java.util.List;
public class MainApplication extends NavigationApplication {
#Override
public boolean isDebug() {
// Make sure you are using BuildConfig from your own application
return BuildConfig.DEBUG;
}
#Override
public List<ReactPackage> createAdditionalReactPackages() {
return Arrays.<ReactPackage>asList(
new RealmReactPackage(),
new BlurViewPackage(),
new MapsPackage()
);
}
}
I've crossposted on React Native's issues page here
The issue seems to be 'Couldn't load memtrack module (No such file or directory)'
It looks like there's an issue with the simulator.
This is a config of my fully functional simulator:
Lots of other suggestions can be found here:
Couldn't load memtrack module Logcat Error
I had a similar problem. I would get this white screen when trying to get it to run on device.
The problem was when I would do adb devices or react-native run-android I would get "ADB is Not Recognized as an internal or external command".
So my fix was to add the path to adb.exe's parent directory to my Environment Variables and then restart my command prompts.I then ran react-native run-android and on startup no more red screen showing the completely useless error message Error calling AppRegistry.runApplication! :)
So I found ADB was located in my folder:
C:\Users\dell\AppData\Local\Android\sdk\platform-tools\adb.exe
I am on a Windows 10 system. dell is my user name of the computer.
So I went to System Environment Variables then found "Path" then clicked "Edit", then clicked "New" and added in "C:\Users\dell\AppData\Local\Android\sdk\platform-tools".

React Native Sqlite for android configuration

I am playing with react native for android and i have special interest with sqlite.
I try to use the sqlite lib here react-native-sqlite-storage buy i always have BUILD FAILED when "run-android". I'm a little lost at step 4 (How to use Android)
configuring the MainActivity
The error:
E:\Documents\Visual Studio CODE\MyApp\android\app\src\main\java\com\myapp\MainActivity.java:22: error: cannot find symbol
protected List getPackages() {
^
symbol: class List
location: class MainActivity
...
Have somebody a very simple sample project for android to see the correct conf?
thanks in advance.
You are missing import statement for the List.
import java.util.List;
#Override
protected List getPackages() {
//noinspection RedundantArrayCreation
return Arrays.asList(new ReactPackage[]{
new MainReactPackage(),
});
}
Any java IDE has some kind of fix import function so it would automatically propose you correct solution.
Try android studio it's free and react-native automatically generate gradle configuration. All you need to do is to import your project folder with gradle files (android by default) into IDE and press ctrl+space to turn IntelliSense on.
You should change MainAplication.java and not MainActivity.java

WebIntent plugin for Phonegap: Cannot find import org.apache.cordova.api.Plugin

I just downloaded the WebIntent plugin for phonegap, but immediately ran into an error when setting it up. The first few lines of WebIntent.java are
import java.util.HashMap;
import java.util.Map;
import org.apache.cordova.DroidGap;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import android.content.Intent;
import android.net.Uri;
import android.util.Log;
import android.text.Html;
import org.apache.cordova.api.Plugin;
import org.apache.cordova.api.PluginResult;
...
public class WebIntent extends Plugin {
Eclipse recognizes all of these imports except for
org.apache.cordova.api.Plugin
After some research, I discovered that Phonegap 2.0 wants plugins to extend the Plugin class. Phonegap 2.7 wants plugins to extend "CordovaPlugin" instead.
A quick look at the Phonegap github reveals that no class called "Plugin" even exists in that package anymore. This confuses me because the WebIntent github was updated just a few months ago, and it still uses Plugin.
I tried changing Plugin to CordovaPlugin wherever I could find it in the file. Surprisingly, most of the errors vansihed. However, the onNewIntent method still has an error:
#Override
public void onNewIntent(Intent intent) {
if (this.onNewIntentCallback != null) {
PluginResult result = new PluginResult(PluginResult.Status.OK, intent.getDataString());
result.setKeepCallback(true);
this.success(result, this.onNewIntentCallback);
}
}
"success(...)" is not a function in CordovaPlugin and there is no function similar to it.
Can anyone think of a way to solve this problem? Or is there information that I'm missing? (A more up-to-date version of WebIntent would be fantastic, but I can't seem to find one)
Had the same problem upgrading to Phonegap 3.0 and found solution is not only change plugin to CordovaPlugin but also you will need to remove "api" from the import statement.
Change
import org.apache.cordova.api.Plugin;
import org.apache.cordova.api.PluginResult;
To this:
import org.apache.cordova.CordovaPlugin;
import org.apache.cordova.PluginResult;
Answer reference: http://devgirl.org/2013/09/05/phonegap-3-0-stuff-you-should-know/
I ran into exactly the same problem.
The issue here is that org.apache.cordova.api.plugin is completely removed as of phonegap-2.7.0 and should be replaced with org.apache.cordova.api.CordovaPlugin.
For more info on how to do this, look at http://simonmacdonald.blogspot.fr/2013/06/why-dont-my-plugins-work-in-phonegap.html.
I followed these instructions and you can find the relevant part of my replacement code for WebIntent.java at https://github.com/phonegap/phonegap-plugins/issues/1047.

android import error

I am trying use the GPE code for App-Android Android-App communication. Both the two new created folders (Android, AppEngine) have errors. I think the problem is that there are
errors with the packages:
import com.google.web.bindery.requestfactory.shared.InstanceRequest;
import com.google.web.bindery.requestfactory.shared.Request;
import com.google.web.bindery.requestfactory.shared.RequestContext;
import com.google.web.bindery.requestfactory.shared.RequestFactory;
import com.google.web.bindery.requestfactory.shared.ServiceName;
It says "The import com.google.web cannot be resolved." I tried adding everything able to be checked checked in the build path. I also know I installed the Web Toolkit and everything. What is wrong?
Statements like the following also have error markings:
#ProxyForName(value = "com.glm.server.Message",
locator = "com.glm.server.MessageLocator") and actually there are so many errors it must be the imports.

Categories

Resources