标签: react-native-android

如何将pdf保存到android文件系统,然后查看PDF - react-native

我正在使用react-native-fs,我正在尝试将pdf文件的base64保存到我的android模拟器文件系统中.

我从服务器收到base64编码的pdf.
然后我用行解码base64字符串:

var pdfBase64 = 'data:application/pdf;base64,'+base64Str;
Run Code Online (Sandbox Code Playgroud)

saveFile()函数

saveFile(filename, pdfBase64){

    // create a path you want to write to
    var path = RNFS.DocumentDirectoryPath + '/' + filename;

     // write the file
     RNFS.writeFile(path, base64Image, 'base64').then((success) => {
       console.log('FILE WRITTEN!');
     })
     .catch((err) => {
       console.log("SaveFile()", err.message);
     });
}
Run Code Online (Sandbox Code Playgroud)

错误
当我尝试保存pdfBase64时,saveFile()函数捕获以下错误:

bad base-64
Run Code Online (Sandbox Code Playgroud)

问题
任何人都可以告诉我哪里或者我做错了什么?谢谢.

base64 react-native react-native-android react-native-fs

9
推荐指数
1
解决办法
8434
查看次数

react-native-tcp无法在Android 7+上运行

我正在开发的应用程序在所有其他版本的Android和iOS中运行良好,但网络功能真正以它为中心.

我没有额外的调试信息.但是有几个问题.

是react-native-tcp被称为主线程上?在这种情况下,它不会驱逐错误?https://developer.android.com/about/versions/nougat/android-7.0-changes.html

如果是这样,我怎么能在其他线程上使用它?

编辑:似乎你一次只能打开一个套接字,无论是UDP还是TCP,如果我试图并行打开它就不会让我们.

android tcp react-native react-native-android

9
推荐指数
0
解决办法
378
查看次数

如何在应用APK文件的情况下检测应用是否使用React Native?

我从Google Play下载了APK文件,想知道应用程序的开发是否使用了React Native库.什么是快速稳定的方法呢?(如果我以后可以自动化的话会更好 - 但这种自动化本身超出了这个问题的范围.)

android decompiling apk react-native react-native-android

9
推荐指数
3
解决办法
5667
查看次数

如何实时从react-native-camera获取帧

我在我正在开发的应用程序中使用react-native-camera组件(https://github.com/lwansbrough/react-native-camera).

有没有办法从视频/摄像机馈送中获取单个帧,以便我可以实时执行处理.

我的最终目标是使用tracking.js库实时跟踪对象,以实现AR效果.

谢谢您的帮助!

react-native react-native-camera react-native-android tracking.js

9
推荐指数
1
解决办法
3944
查看次数

必须通过contentContainerStyle prop应用ScrollView子布局

我正在使用反应原生swiper.并且显示此错误我不知道为什么.怎么解决?在过去,没有像这样的问题.这是第一次发生.怎么了?

这是完整错误的图像:

这是完整错误的图像

<Swiper loop={false}
          index={0}
          style={styles.wrapper}
          activeDotColor={'#EEE'}>

          <View style={styles.slide1}>
            <Text style={styles.text}>Choose category you like</Text>
          </View>
          <View style={styles.slide2}>
            <Text style={styles.text}>Bookmark articles that you</Text>
            <Text style={styles.text}>like</Text>
          </View>
          <View style={styles.slide3}>
            <Text style={styles.text}>Get notifications about your</Text>
            <Text style={styles.text}>chosen topic</Text>
            <Button style={styles.text} onPress={() => this.props.navigation.navigate("Home")}>
              <Text style={styles.text}>Main Screen</Text>
            </Button>
          </View>
        </Swiper>
      )
    } else {
      return <View></View>
    }
  }
}

const styles = {
  wrapper: {
    justifyContent: 'center',
    alignItems: 'center'
  },
  slide1: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: '#9DD6EB'
  },
  slide2: {
    flex: …
Run Code Online (Sandbox Code Playgroud)

javascript reactjs react-native react-native-android react-native-ios

9
推荐指数
2
解决办法
6657
查看次数

Android React Native ReactRootView应该使用Activity还是Application上下文?

在与Android集成的React Native 文档中,它包含用于与Android集成的代码段:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    mReactRootView = new ReactRootView(this);
    mReactInstanceManager = ReactInstanceManager.builder()
            .setApplication(getApplication())
            .setBundleAssetName("index.android.bundle")
            .setJSMainModulePath("index")
            .addPackage(new MainReactPackage())
            .setUseDeveloperSupport(BuildConfig.DEBUG)
            .setInitialLifecycleState(LifecycleState.RESUMED)
            .build();
    mReactRootView.startReactApplication(mReactInstanceManager, "MyReactNativeApp", null);

    setContentView(mReactRootView);
}
Run Code Online (Sandbox Code Playgroud)

但是,当我按原样使用它时,我得到一个100%的repro内存泄漏ThemedReactContext,ReactRootView这是由于持有对我的自定义活动的引用的引用.

这是因为Context传递给构造函数的参数ReactRootView是this,这是对我的自定义活动的引用.

相反,如果我这样做:

mReactRootView = new ReactRootView(getApplication());
Run Code Online (Sandbox Code Playgroud)

我没有内存泄漏.

为新的ReactRootView更改我的上下文源是否安全,这是一个应该a)修复还是b)应该看到文档发生变化的错误?

java android memory-leaks react-native react-native-android

9
推荐指数
1
解决办法
859
查看次数

React Native Android Release Build失败 - Gradle

我有一个相当复杂的项目,其中一些是过去一年左右的旧代码,在React Native时间是永远的.常规调试版本工作正常,但发布版本有错误.我拼凑了其他地方的答案,尽我所能,但我不知道如何通过这最后一点.

我一直收到捆绑错误,其中aapt会失败,因为它没有正确地捆绑资源.

错误代码示例:

> Task :app:bundleReleaseJsAndAssets 
Scanning folders for symlinks in /media/user/1546c7ef-f386-4baa-90d5-cbd87092d3e31/home/user/Code/React-Native/timesavr/node_modules (9ms)
Scanning folders for symlinks in /media/user/1546c7ef-f386-4baa-90d5-cbd87092d3e31/home/user/Code/React-Native/timesavr/node_modules (6ms)
warning: the transform cache was reset.
Loading dependency graph, done.
bundle: Writing bundle output to: /media/user/1546c7ef-f386-4baa-90d5-cbd87092d3e31/home/user/Code/React-Native/timesavr/android/app/build/intermediates/assets/release/index.android.bundle
bundle: Done writing bundle output

error: resource android:style/TextAppearance.Material.Widget.Button.Borderless.Colored not found.
error: resource android:style/TextAppearance.Material.Widget.Button.Colored not found.
/home/user/.gradle/caches/transforms-1/files-1.1/appcompat-v7-26.0.2.aar/28fa7b5f2db0b5e014559f7cf36ab4c7/res/values-v26/values-v26.xml:9:5-12:13: AAPT: error: resource android:attr/colorError not found.

/home/user/.gradle/caches/transforms-1/files-1.1/appcompat-v7-26.0.2.aar/28fa7b5f2db0b5e014559f7cf36ab4c7/res/values-v26/values-v26.xml:13:5-16:13: AAPT: error: resource android:attr/colorError not found.

/home/user/.gradle/caches/transforms-1/files-1.1/appcompat-v7-26.0.2.aar/28fa7b5f2db0b5e014559f7cf36ab4c7/res/values-v26/values-v26.xml:17:5-93: AAPT: error: style attribute 'android:attr/keyboardNavigationCluster' not found.

error: failed linking references.

FAILURE: Build …
Run Code Online (Sandbox Code Playgroud)

android build.gradle android-gradle-plugin react-native-android

9
推荐指数
2
解决办法
9476
查看次数

axios和android模拟器的网络错误

我有一个React-Native应用程序使用NodeJS后端,它提供API.

我的React-Native前端正在使用Expo和Axios来点击我的NodeJS API路径(使用Hapi,Joi,Knex),这将(例如)更新我的数据库(MySQL).

一切都适用于我的iOS模拟器.但是,在Android模拟器上,我的一些路由""的命中不起作用"",并出现以下错误消息:( Network Error - node_modules/axios/lib/core/createError.js:16:24 in createError实际上,它有效,但前端没有检测到它......)

这很奇怪,因为就像我说的那样,这只适用于我的一些路线.我更改了http://localhost:8000/api以http://10.0.2.2:8000/api确保Android模拟器访问我的API,这部分也没问题.

有缺陷的路线在iOS上正常工作,并且在Insomnia/Postman(localhost:8000/api/sendMail)上正常工作.它正在Android Emulator上工作,但应用程序没有检测到它.

这是我的代码示例:

FRONT - 按下我的按钮"SendEmail":

/* Button.js */
const sendAndEmailPromise = await sendEmail(this.state.email);

console.log(sendAndEmailPromise); // Output : NOTHING (not undefined, not null, N O T H I N G).

if (sendAndEmailPromise.status === 200) {
    // handle it
} else (sendAndEmailPromise.status === 403) {
    // etc. for each of my codeStatus that can be returned by my API 
}

/* MyAPI.js */ …
Run Code Online (Sandbox Code Playgroud)

react-native axios react-native-android expo

9
推荐指数
1
解决办法
4231
查看次数

react-native开始给出无效的正则表达式无效的错误

我按照以下链接开始使用react-native

React Native入门

我试图创建没有expo的本机应用程序,所以按照文档,我遵循以下命令

npm install -g react-native-cli
react-native init AwesomeProject
Run Code Online (Sandbox Code Playgroud)

运行android命令后

react-native run-android
Run Code Online (Sandbox Code Playgroud)

它给我以下模拟器错误

在此处输入图片说明

所以我用启动命令来运行Metro服务器

react-native start
Run Code Online (Sandbox Code Playgroud)

这个命令给了我控制台另一个错误

在此处输入图片说明

reactjs react-native react-native-android react-native-cli metro-bundler

9
推荐指数
2
解决办法
3555
查看次数

Android 资源链接失败 - AAPT:错误:找不到资源 android:attr/dialogCornerRadius

我在尝试为 react-native 项目捆绑 android 版本时收到错误。此项目应转换为 AndroidX 作为注释。

错误信息

尝试为 Android 构建发布版本时,我收到以下错误:

    * What went wrong:
Execution failed for task ':react-native-vector-icons:verifyReleaseResources'.
> A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade
   > 1 exception was raised by workers:
     com.android.builder.internal.aapt.v2.Aapt2Exception: Android resource linking failed
     /Users/.../.gradle/caches/transforms-2/files-2.1/5c74eb36d229b35abeeb690f5d3b91a3/appcompat-1.0.0/res/values-v28/values-v28.xml:5:5-8:13: AAPT: error: resource android:attr/dialogCornerRadius not found.

     /Users/.../.gradle/caches/transforms-2/files-2.1/5c74eb36d229b35abeeb690f5d3b91a3/appcompat-1.0.0/res/values-v28/values-v28.xml:9:5-12:13: AAPT: error: resource android:attr/dialogCornerRadius not found.

     /Users/.../.gradle/caches/transforms-2/files-2.1/f54ae08833e39bf2b75fd420ffea65b9/core-1.0.0/res/values/values.xml:57:5-88:25: AAPT: error: resource android:attr/fontVariationSettings not found.

     /Users/.../.gradle/caches/transforms-2/files-2.1/f54ae08833e39bf2b75fd420ffea65b9/core-1.0.0/res/values/values.xml:57:5-88:25: AAPT: error: resource android:attr/ttcIndex not found.
Run Code Online (Sandbox Code Playgroud)

根 Build.gradle 文件

buildscript {
  ext {
    buildToolsVersion = "28.0.3"
    minSdkVersion = 16 …
Run Code Online (Sandbox Code Playgroud)

gradle aapt build.gradle react-native react-native-android

9
推荐指数
1
解决办法
5323
查看次数