For the android installation of this component:
https://github.com/lwansbrough/react-native-camera
The first installation step is:
Modify the ReactInstanceManager.builder() calls chain in
android/app/main/java/.../MainActivity.java to include:
.addPackage(new RCTCameraPackage())
But my MainActivity.java file located at
android/app/src/main/java/com/.../MainActivity.java
Doesn't seem to have any reference to ReactInstanceManager.
Here it is in it's entirety:
package com.app;
import com.facebook.react.ReactActivity;
import com.facebook.react.ReactPackage;
import com.facebook.react.shell.MainReactPackage;
import com.rssignaturecapture.RSSignatureCapturePackage;
import java.util.Arrays;
import java.util.List;
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 "app";
}
/**
* Returns whether dev mode should be enabled.
* This enables e.g. the dev menu.
*/
#Override
protected boolean getUseDeveloperSupport() {
return BuildConfig.DEBUG;
}
/**
* A list of packages used by the app. If the app uses additional views
* or modules besides the default ones, add more packages here.
*/
#Override
protected List<ReactPackage> getPackages() {
return Arrays.<ReactPackage>asList(
new RSSignatureCapturePackage(this),
new MainReactPackage()
);
}
}
EDIT:
This seems to be related to changes in React 0.18
Here is a similar issue / solution on another Module:
https://github.com/marcshilling/react-native-image-picker/issues/74
I've tried applying the same changes to this Module as well with no luck.
I was able to solve the same issues with the following steps:
Installed react-native-camera from github and not with version "latest" but with github link
npm install react-native-camera#https://github.com/lwansbrough/react-native-camera.git --save
(thank you https://github.com/lwansbrough/react-native-camera/issues/164)
In file "/node_modules/react-native-camera/android/src/main/AndroidManifest.xml" I added the following permissions
<uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.autofocus" />
In file "/node_modules/react-native-camera/android/src/main/java/com/lwansbrough/RCTCamera/RCTCameraViewManager.java" I modified the part
public class RCTCameraViewManager extends SimpleViewManager
to
public class RCTCameraViewManager extends ViewGroupManager
(thank you for 2. and 3. to https://github.com/lwansbrough/react-native-camera/issues/165)
In File "/android/app/src/main/java/com/myapp/MainActivity.java" (do not forget to exchange "myapp" with your correct path name) I added to the "#Override" section the line:
new RCTCameraPackage(),
in order to look like:
#Override
protected List<ReactPackage> getPackages() {
return Arrays.<ReactPackage>asList(
new RCTCameraPackage(),
new MainReactPackage());
}
This is related to a change that was made in React Native 0.18:
https://github.com/facebook/react-native/commit/935cbb76c02cffd378a8f391c6e7443a3da13adc
In order to solve for it, I had to make sure to import the package at the correct location:
import com.lwansbrough.RCTCamera.RCTCameraPackage;
and reference it in the packages list:
new RCTCameraPackage(),
like so:
package com.myapp;
import com.facebook.react.ReactActivity;
import com.facebook.react.ReactPackage;
import com.facebook.react.shell.MainReactPackage;
import com.lwansbrough.RCTCamera.RCTCameraPackage; // IMPORT REACT-NATIVE-CAMERA
import java.util.Arrays;
import java.util.List;
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 "myapp";
}
/**
* Returns whether dev mode should be enabled.
* This enables e.g. the dev menu.
*/
#Override
protected boolean getUseDeveloperSupport() {
return BuildConfig.DEBUG;
}
/**
* A list of packages used by the app. If the app uses additional views
* or modules besides the default ones, add more packages here.
*/
#Override
protected List<ReactPackage> getPackages() {
return Arrays.<ReactPackage>asList(
new RCTCameraPackage(), // ADD REACT-NATIVE_CAMERA
new MainReactPackage()
);
}
}
Update: This fixed the error, but did not get the module working.
Related
What we're starting with
I have a main test listener, which just set up the web driver on set up, and free the resource on teardown:
import org.openqa.selenium.WebDriver
import org.openqa.selenium.chrome.ChromeDriver
import org.openqa.selenium.chrome.ChromeOptions
import com.kms.katalon.core.annotation.AfterTestCase
import com.kms.katalon.core.annotation.BeforeTestCase
import com.kms.katalon.core.context.TestCaseContext
import com.kms.katalon.core.webui.driver.DriverFactory
import internal.GlobalVariable
class NewTestListener {
private WebDriver driver;
/**
* Executes before every test case starts.
* #param testCaseContext related information of the executed test case.
*/
#BeforeTestCase
def sampleBeforeTestCase(TestCaseContext testCaseContext) {
String pathToChromeDriver = System.getProperty("user.home") + GlobalVariable.pathToKatalon + '\\configuration\\resources\\drivers\\chromedriver_win32\\chromedriver.exe'
System.setProperty('webdriver.chrome.driver', pathToChromeDriver)
ChromeOptions chromeProfile = new ChromeOptions()
chromeProfile.addArguments('user-data-dir=' + System.getProperty("user.home") + GlobalVariable.pathToUserDataDir)
chromeProfile.addArguments('profile-directory=Default')
this.driver = new ChromeDriver(chromeProfile)
this.driver.manage().window().maximize()
this.driver.get('https://crm.zoho.com')
DriverFactory.changeWebDriver(this.driver)
}
#AfterTestCase
def sampleAfterTestCase(TestCaseContext testCaseContext) {
this.driver.quit()
}
}
What we're tryna do
I have dozens of test cases, that pertain to distinct pages, categorized under distinct folders, which I want to abstract out common set up,teardown concerns.
How do we want to do it
I try to create some BaseCategoryListener, which get implemented by the category of test:
import java.util.regex.Pattern
import com.kms.katalon.core.annotation.AfterTestCase
import com.kms.katalon.core.annotation.BeforeTestCase
import com.kms.katalon.core.context.TestCaseContext
abstract class BaseCategoryListener {
abstract List<Pattern> getCategory();
public void setup(TestCaseContext testCaseContext) {
}
public void teardown(TestCaseContext testCaseContext) {
}
boolean isInCategory(TestCaseContext testCaseContext) {
for (Pattern regex : this.getCategory()) {
if (regex.matcher(testCaseContext.getTestCaseId()).matches()) return true;
}
return false;
}
/**
* Executes before every test case starts.
* #param testCaseContext related information of the executed test case.
*/
#BeforeTestCase
def sampleBeforeTestCase(TestCaseContext testCaseContext) {
if (this.isInCategory(testCaseContext)) {
this.setup(testCaseContext)
}
}
/**
* Executes after every test case ends.
* #param testCaseContext related information of the executed test case.
*/
#AfterTestCase
def sampleAfterTestCase(TestCaseContext testCaseContext) {
if (this.isInCategory(testCaseContext)) {
this.teardown(testCaseContext)
}
}
}
implement it like so:
import static com.kms.katalon.core.testobject.ObjectRepository.findTestObject
import java.util.regex.Pattern
import com.kms.katalon.core.context.TestCaseContext
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI
class ContractTestsListener extends BaseCategoryListener{
#Override
public List<Pattern> getCategory() {
return [
~/Test Cases\/New Zoho\/Practice Contract\/.*/
]
}
#Override
public void setup(TestCaseContext testCaseContext) {
WebUI.navigateToUrl(testCaseContext.getTestCaseVariables()["initURL"])
WebUI.click(findTestObject('Page_Practice - Zoho CRM/Third Row Section/Contract Tab Pane/New Contract button'))
WebUI.waitForElementNotPresent(findTestObject('Page_Practice - Zoho CRM/Third Row Section/Contract Tab Pane/New Contract button'), 3)
WebUI.waitForPageLoad(5)
}
}
What happens when you try to use that:
When I pick a test case in the folder Test Cases/New Zoho/Practice Contract to remove the setup hook from (because it was already copied and pasted into the test listener), that test case now fails because the ContractTestsListener setup happens before the NewTestListener setup!
How can I control the flow of the test listener hooks in Katalon Studio?
My junior and I are working on a React Native application which responds to calls made by the Android system. We have two classes which need to communicate between the two classes shown below: MyModule (the first code block), which should be notified by OtherClass (the second code block) when an event happens in the Android system.
What we're seeing that is:
We create an instance of MyModule, which extends ReactContextBaseJavaModule, where we pass the ReactApplicationContext in via its Constructor.
This creates an instance of OtherClass and passes the ReactApplicationContext into OtherClass, again via its constructor.
In OtherClass, the method onEvent is called when a certain system event is fired. When this happens, OtherClass' private variable reactContext becomes null.
So what we're trying to do is allow our ReactNative application to receive messages from an Android class when a given system event happens. We've attempted to use the "tutorial" at http://facebook.github.io/react-native/docs/native-modules-android.html but, because this is provided without full source code, we're getting a bit lost.
Any suggestions please?
Thanks!
OtherClass.java:
package com.ats;
import com.ats.SuperClass;
import com.ats.MyModule;
import android.content.Context;
import com.ats.MyModule;
import com.facebook.react.bridge.Arguments;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.WritableMap;
import com.facebook.react.modules.core.DeviceEventManagerModule;
import java.util.Date;
import javax.annotation.Nullable;
public class OtherClass extends SuperClass {
private ReactApplicationContext reactContext;
public OtherClass(ReactApplicationContext reactContext) {
super();
this.reactContext = reactContext;
}
public OtherClass() {
super();
}
#Override
protected void onEventTriggered(Context ctx, String number, Date start) {
WritableMap params = Arguments.createMap();
params.putInt("test", 0);
sendEvent("sendCall", params);
}
private void sendEvent(String eventName, #Nullable WritableMap params) {
System.out.println("OtherClass ReactAppContext: " + this.reactContext); //ReactContext is being lost at this point(Nullpointexeception)
this.reactContext.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class).emit(eventName, params);
}
}
...
MyModule.java:
package com.ats;
import com.ats.OtherClass;
import android.telecom.Call;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactMethod;
import com.facebook.react.bridge.ReactContext;
import com.facebook.react.bridge.ReactContext;
import com.facebook.react.bridge.WritableMap;
import com.facebook.react.bridge.Arguments;
import com.facebook.react.modules.core.DeviceEventManagerModule;
import com.facebook.react.bridge.Callback;
import com.facebook.react.bridge.ReadableMap;
import javax.annotation.Nullable;
/**
* Provides a bridge between JavaScript and Java
*/
public class MyModule extends ReactContextBaseJavaModule {
private OtherClass OR;
/**
* Our local copy of the React Application Context
*/
/**
* Construct an instance of this class and the OtherClass Java class
*
* #param reactContext
*/
public MyModule(ReactApplicationContext reactContext) {
super(reactContext);
this.OR = new OtherClass(reactContext);
}
/**
* Define the name of this ReactNative [Native] Module
*
* #return String
*/
#Override
public String getName() {
return "Module";
}
/**
* Perform a simple println to test whether this code is reachable
*/
#ReactMethod
public void print() {
System.out.println("React Method Print");
}
}
Im having some trouble setting up Google Analytics on my Android app. Could any one help me out and point me to some sample code or tutorial. Im trying to follow this one
Heres my code:
package com.examp2.testq;
import java.util.HashMap;
import com.google.analytics.tracking.android.GoogleAnalytics;
import com.google.analytics.tracking.android.Tracker;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.ActionBar;
import android.support.v4.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.os.Build;
public class MainActivity extends ActionBarActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public enum TrackerName {
APP_TRACKER, // Tracker used only in this app.
}
HashMap<TrackerName, Tracker> mTrackers = new HashMap<TrackerName, Tracker>();
synchronized Tracker getTracker(TrackerName trackerId) {
if (!mTrackers.containsKey(trackerId)) {
GoogleAnalytics analytics = GoogleAnalytics.getInstance(this);
Tracker t = (trackerId == TrackerName.APP_TRACKER) ? analytics.newTracker(PROPERTY_ID)
:
mTrackers.put(trackerId, t);
}
return mTrackers.get(trackerId);
}
Im not sure what to do with the PROPERTY ID or how to call it?
Thanks!
Put the following line inside MainActivity:
private static final String PROPERTY_ID = "UA-xxxxx-x";
private Tracker tracker;
HashMap<TrackerName, Tracker> mTrackers = new HashMap<TrackerName, Tracker>();
replacing UA-xxxxx-x with the tracking id for your app.
I'm using Google Analytics in an app that is only one screen, so my MainActivity onCreate method looks like this:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
GoogleAnalytics.getInstance(this).newTracker(PROPERTY_ID);
GoogleAnalytics.getInstance(this).getLogger().setLogLevel(Logger.LogLevel.VERBOSE);
tracker = getTracker(TrackerName.APP_TRACKER);
tracker.setScreenName("MainActivity");
tracker.send(new HitBuilders.AppViewBuilder().build());
setContentView(R.layout.main);
//...etc.
This is enough for a ton of useful data in Analytics.
You'll have to add the following includes:
import com.google.android.gms.analytics.HitBuilders;
import com.google.android.gms.analytics.Logger;
import com.google.android.gms.analytics.Tracker;
import com.google.android.gms.analytics.GoogleAnalytics;
Don't forget to add the following permissions before the <application> tag inside the <manifest> tag of AndroidManifest.xml:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
Google also says to add the following tag inside the <application> tag.
<meta-data android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
Lastly, if you're using Android Studio, Google says to add the following lines to proguard-rules.txt:
-keep class * extends java.util.ListResourceBundle {
protected Object[][] getContents();
}
-keep public class com.google.android.gms.common.internal.safeparcel.SafeParcelable {
public static final *** NULL;
}
-keepnames #com.google.android.gms.common.annotation.KeepName class *
-keepclassmembernames class * {
#com.google.android.gms.common.annotation.KeepName *;
}
-keepnames class * implements android.os.Parcelable {
public static final ** CREATOR;
}
...and also this dependency to your project's build.gradle file:
apply plugin: 'android'
...
dependencies {
compile 'com.android.support:appcompat-v7:+'
compile 'com.google.android.gms:play-services:4.3.23'
}
Property id is simply a string of the format UA-XXXXXX-Y. It is also called the tracking id, webproperty id etc. You can get this from the admin settings of Google Analytics account. Most likely you already have it.
There are basically two ways of getting a tracker. You can create it from an xml file. If you are doing that, you need to use public Tracker newTracker (int configResId)
The second method is to use public Tracker newTracker (String trackingId). In your code snippet, you are using the second method.
Try this tutorial https://developers.google.com/analytics/devguides/collection/android/v4/
and this https://developers.google.com/analytics/devguides/collection/android/v4/events
hope this helps.
Property id i the "UA-XXXXXX-Y" In admob i think, you can create this trackig ID.
I import an existing project into eclipse, and always encountered this problem. First, it appears the error: R cannot be solved. After import android.R. the error turned to the following methods. "start cannot be or is not a field"
I also checked the gen folder, where contains a R.java file. The file looks good, including the following contents: I also tried to clear the project and rebuilt which didnot work. Does any body have any idea how to solve this? Thanks a lot.
R.java:
public static final class layout {
public static final int kbd=0x7f030000;
public static final int main=0x7f030001;
public static final int start=0x7f030002;
}
startactivity.java:
import android.R;
import android.R.layout;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.WindowManager;
public class StartActivity extends Activity {
Intent mMain;
/** Called when the activity is first created. */
/* (non-Javadoc)
* #see android.app.Activity#onCreate(android.os.Bundle)
*/
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.start);//where error appears**
}
public void onStartButtonClick(View v) {
mMain = new Intent(this, MainActivity.class);
startActivity(mMain);
}
you are importing
android.R
first remove android.R and android.R.layout from import
and import R with your packagename.R
for eg. com.example.R instead of android.R
Try doing Project -> Clean. If that doesn't work it looks like this might have already been answered: R cannot be resolved - Android error
To any one who may face the similar problem with me. I found an answer from the link below:
R cannot be resolved - Android error
My problem was solved by:
1. delete all the imports lines.
2. press ctrl+shift+O to manually regenerate all imports.
And then the problem disappeared.
Many thanks for all the comments above.
For some reason I can only call native functions from my main activity and not any custom views that I've created. Here is an example file (I followed a tutorial, but renamed the classes http://mindtherobot.com/blog/452/android-beginners-ndk-setup-step-by-step/)
See the usage of the native function "getNewString".
package com.example.native;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.os.Bundle;
import android.view.View;
public class NativeTestActivity extends Activity
{
static
{
System.loadLibrary("nativeTest");
}
private native String getNewString();
#Override public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
this.setContentView(new BitmapView(this));
String hello = getNewString(); // This line works fine
new AlertDialog.Builder(this).setMessage(hello).show();
}
}
class BitmapView extends View
{
static
{
System.loadLibrary("nativeTest");
}
private native String getNewString();
public BitmapView(Context context)
{
super(context);
String hello = getNewString(); // This line throws the UnsatisfiedLinkError
new AlertDialog.Builder(this.getContext()).setMessage(hello).show();
}
}
How can I call native functions in my custom views?
I've built the application as an Android 2.2 app. I'm running the application on my HTC Desire. I have the latest SDK (9) and latest NDK (r5).
Your problem is that you are trying to call the native function from a class where it dont belongs to.
You defined the following JNI function in your c file:
jstring Java_com_example_native_NativeTestActivity_getNewString()
This states that the native function when loaded will bind with the method declared as native in NativeTestActivity class. So when you try to call it from your View class it doesn't find any function to bind to.
In that case it will look for the following function (which of course does not exist in your .so):
jstring Java_com_example_native_BitmapView_getNewString()
If you still want to be able to call the same function from different classes you can declare it in a container class that can be accessed from any class you want.
eg:
java code:
package com.example.native;
public class NativeHelper {
public native String getNewString();
static
{
System.loadLibrary("nativeTest");
}
}
c code:
jstring Java_com_example_native_NativeHelper_getNewString(JNIEnv* env, jobject javaThis)
{
return (*env)->NewStringUTF(env, "Hello from native code!");
}