问题标签 [react-native-native-module]
For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.
android - React-native Access Device Camera? (Android Specifically)
I'm trying to allow users to upload a video in a react-native application, but am having trouble even getting access to the camera.
** Not using Expo. I used the react-native cli and used react-native-init to generate my project **
** Using react-native version 0.53.0. Android version 5.1 **
** UPDATE: After some good advice, I've changed the compileSdkVersions and targetSdkVersions in my android/app/build.gradle file to > 23 and know that the problem isn't with my permissions. Also, the deprecated RCTCamera version of react-native-camera works fine and I'm able to capture still images and video and save them to the device. Only the master version, which uses RNCamera, still crashes the app every time the screen loads :/
This is less than ideal because I don't want to have deprecated code in my app. So when I'm referring to react-native-camera below, I mean the current version that uses RNCamera and not RCTCamera. **
I tried using the react-native-camera package (https://github.com/react-native-community/react-native-camera) but this causes my app to crash every time. Plus I want to use a camera app that the user has already installed, rather than having to build my own camera view, which is what react-native-camera requires.
Looking around, I have stumbled across three promising ways to solve this:
1) Linking - As far as I understand from this StackOverflow post (React native send a message to specific whatsapp Number2) linking can be used to open other apps the user has on their device. I figure that this can be used to access camera apps as well. But I haven't found any info on this. How do I check that a user has a camera app, and then link to them? Ideally a pop-up menu would appear on the user's phone asking the user to choose from a list of available camera apps to use.
2) This post from the android developer's docs - https://developer.android.com/training/camera/videobasics.html . This describes how to do exactly what I want to do, but I am having trouble making a native module for use in my components. I have very basic knowledge of building bridges in react-native, and was only able to make a simple native Toast module work after reading a couple articles laying out all the code. So could anyone write a VideoModule.java file that can be used to implement the same functionality as the android docs specify? This seems like the easiest solution to me, but my lack of knowledge of Java/android is standing in the way.
3) ReactNativeWebRTC - I have already included this module (https://github.com/oney/react-native-webrtc) successfully on a different screen in the application. But as I am using this module to stream video between two peers, it don't see how to use it to upload video. I looked to see if there was something akin to the MediaRecorder API that I am using for the web version of the app, but I haven't had any luck. But I know that if I can get the binary data from the media stream, then I can send this directly to my server. So, is there a way to directly store the media streams from the getUserMedia() method that react-native-webrtc employs in a buffer without a MediaRecorder like on the web?
Any solution would be tremendously helpful here. And since I only have an Android phone to test on currently, I don't need info for how to make this work with iOS. Just a solution for android. Thank you very much.
Here's my AndroidManifest.xml permissions:
My android/app/build.gradle file:
And my android/build.gradle:
android - 我应该使用哪个线程来调用 react-native 本机 ui 组件中的 uiManager 调用?
我正在为 Android 构建一个原生 UI 组件,它使用扩展ReactRootView
.
SyncRootView
如果我检查我得到的线程,那么在我的视图(名为)的构造函数上,Thread curThread = Thread.current(); // main
我们在主线程上。
问题是,如果我尝试运行任何uiManager
调用(例如uiManager.createView
,我收到该错误:
所以基本上问题是一个名为SingleThreadAsserter的类react-native
,我什至不确定它为什么在那里。它的mThread
值设置为,native_module_thread...
因此我得到一个,AssertionError
因为我在主线程上。
如果我尝试uiManager
在 native_module 线程上运行这些调用(通过使用ctx.runOnNativeModulesQueueThread(myRunnable)
),起初它似乎可以工作,但后来(我猜一旦模块初始化结束??)我得到
有任何想法吗?
android - 类必须被声明为抽象或在 ReactPackage 中实现名为 createJSModules 的抽象方法
我正在关注 android 的 Native Module 文档: https ://facebook.github.io/react-native/docs/native-modules-android.html#docsNav
我的包裹目前看起来像这样
我收到以下错误
类必须被声明为抽象或在 ReactPackage 中实现名为 createJSModules 的抽象方法
文档没有提到createJSModules
我应该包含它以及这样做的正确方法是什么?
这是使用最新的依赖
android - 为 react-native 本机 android 方法编写单元测试
我正在构建 react-native 应用程序,其中包含一些本机 android 模块。
在 MainApplication.java 中,
在我的 MyCustomPackage 中,
我有几个其他模块,但这是一个例子。所有功能都运行良好。现在我想为 MyCustomModule java 类中的方法编写单元测试。我尝试使用 Robolectric 框架,但不知道它是如何与 react native 一起工作的。有没有其他工具可以做到这一点?谁能给我一些示例或指导为 react-native 本机 android 代码编写单元测试?
android - 如何从 Android 的 react-native 模块访问 google-services?
我正在关注使用 android sdk 进行 google 登录的 firebase 设置教程,并在此处为它制作小型 react-native 模块asq-react-native-google-sign-in
通过android实现,我偶然发现了一个问题。
Firebase 教程提到了这一步
简而言之,它的作用是从google-services.json
firebase 生成的文件中获取某个值,并在应用google-services
依赖项时将其转换为 xml 源(所有这些都在链接指南中进行了描述)。
我不知道如何从我的反应本机模块中访问它,我最接近的是使用
但default_web_client_id
没有定义。通过在 android studio 中检查它R
与我的本机模块而不是主应用程序有关,所以难怪它未定义。有没有办法让我访问R
我的主应用程序?
编辑我可以将它添加到本机模块的构造函数中并从主应用程序中传递它,但这对用户来说还有 1 个步骤,如果可能的话,我想从我的模块中获取这个值。
android - React Native、Native Android Module在View中添加TextView
我正在尝试按照该教程视频在 Android 上为 React Native 制作一个本机模块,但它似乎不完整,我找不到完成它的方法。
我正在尝试显示一个 Square,并且在该正方形内,一个文本作为道具传递。
但我无法在 Android 上的视图中添加 TextView。
这是我的SquarePackage.java
这是我的 SquareManager.java
到目前为止,我只有一个蓝色 Square。我走对了吗?
android - React Native,Android Studio,JDBC,MySql - 用户'root'@'ipaddress'的访问被拒绝
我正在反应本机应用程序中开发一个 android 本机模块。我正在使用 JDBC 直接连接到我的电脑上托管的 mysql 数据库。我的手机和电脑在同一个 wifi 网络上,当我试图访问数据库时,我收到以下错误。
以下是我用来连接数据库的代码:
另请注意,此代码在我的个人笔记本电脑上运行良好,但当我尝试使用公司的电脑在公司网络上运行此代码时出现此错误。
react-native - 无法在本机反应中将arraylist传递给本机模块库
你好朋友我想为本地模块调用创建库所以下面是我的代码
Mylib 是我在 android 中的库项目
我从我的 js 中调用它,如下所示
当我运行上面的代码时,出现“无法连接类型类 TagInfo 的参数”之类的错误
知道如何解决这个问题吗?你的所有建议都是可观的。
react-native - 无法从 React 本机项目调用 ios 本机模块
你好朋友我想让我的插件在 react native 中我想从我的 react native js 文件中调用我的 ios 本机模块函数所以下面是我的代码
ios库代码如下
JS文件代码如下
我只想从我的 js 文件中调用简单的函数到 ios 本机库类,但是当我在上面运行代码时,我得到类似TypeError: undefined is not an object (evalating 'MyLibManager.findEvents') 的错误
知道如何解决这个问题吗?你的所有建议都适用