Quantcast
Channel: Active questions tagged react-native+android - Stack Overflow
Viewing all 28463 articles
Browse latest View live

I don't get the result of my promise despite using await

$
0
0

My function looks like this:

async function getPlaceForecast(lat, long) {//var response;var day5forecast = 'http://api.openweathermap.org/data/2.5/forecast?lat='+ lat +'&lon='+ long +'&appid='+ apikey;try {    const request = new Request(tmp2, {        method: 'get'    })    let response = await fetch(request)        .then(value => {            console.log("than", value.json());            return value//.json();        })        .catch(function (error) {            console.error(error);        });}catch{}//return response;

}

This is the result:

'than', { _40: 0, _65: 0, _55: null, _72: null }

And this is the result without using .json() :

'than', { type: 'default',status: 200,ok: true,   statusText: undefined,  headers:   { map:     { 'access-control-allow-methods': 'GET, POST','access-control-allow-credentials': 'true','access-control-allow-origin': '*','x-cache-key': '/data/2.5/forecast?lat=28.35&lon=-14.05',        connection: 'keep-alive','content-length': '14383','content-type': 'application/json; charset=utf-8',         server: 'openresty' } },  url: 'http://api.openweathermap.org/data/2.5/forecast?lat=28.349414&lon=-14.046311&appid=<mykey>',  _bodyInit:    { _data:     { size: 14383,       offset: 0,   blobId: '2dbf82c5-5d28-47db-9034-7f239bf8290a' } },  _bodyBlob:   { _data:      { size: 14383,       offset: 0,        blobId: '2dbf82c5-5d28-47db-9034-7f239bf8290a' } } }

What did I do wrong?


React native TypeError: Network request failed with fetch()

$
0
0

I'm using React native for developing an android application. With this fetch request I'm getting the error TypeError: network request failed:

fetch('https://pixabay.com/api/?key=MY_KEY&q='+ this.props.jsondata.city.name +'&lang=en&image_type=photo&orientation=horizontal&category=travel&safesearch=true')        .then(response => {            console.dir(response);            if (!response.ok) {                throw Error(data.statusText);            }            return response.json();        })        .then(json => {            console.log(json.hits[0].largeImageURL)            this.setState(() => {                return {backImage: json.hits[0].largeImageURL};            });        })        .catch(err => {            console.log('Unable to search image! '+ err);        });

I've already searched online but this problem appears only with localhost addresses or http, that is not my case. The request is inside the componentDidMount() function. I've made a similar request (with the same structure) in an another place of the application but there is no error there. I'm using a real android device to testing the app with the react-native app compiled in android native code.

How to preview files inside an app component using react-native

$
0
0

I'm trying to preview files inside my component. Currently I'm using react-native-file-viewer, which can't open the files inside the component and takes up the whole screen. Is there any way to achieve this in react-native?

<SafeAreaView style={{flex: 1, backgroundColor: 'white'}}><Grid><Col size={30}>      ...</Col><Col size={70} style={{ backgroundColor: '#00CE9F'}}>      //Preview should go here</Col></Grid></SafeAreaView>

The preview should be displayed on the right side.ScreenshotThis is the current preview:Current Preview

Problem receiving compressed (zlib/pako) data in Android / React Native

$
0
0

I've an ExpressJS endpoint that send me an object list's json compressed with pako library (https://github.com/nodeca/pako). This endpoint is consumed by a website client with axios and now I'm writing a mobile app (focused in Android for now) with React Native, I've picked axios as http client in the app too. But when I'm trying to consume same endpoint (that works well in browser with web client) in Android, for some reason, the answer comes incomplete: when I unzip the answer it looks like if only a piece of json was returned.

Looking at the browser request I noticed that it adds some headers to it. I tried to add the same headers to the app request and it didn't work. Also have done the request with Insomnia and it brought me the whole data.

Last, I've tried to request with Fetch. In Android I've obtained incomplete answer then I copied same request, paste in browser console and it gives me the complete one.

Anyone already faced this problem? Any guess to solve it?

Warning: ToastAndroid is not supported on this platform. error with react native

$
0
0

I am getting this error on react native IOS,

- node_modules/expo/build/logs/LogSerialization.js:166:14 in _captureConsoleStackTrace- node_modules/expo/build/logs/LogSerialization.js:41:24 in serializeLogDataAsync- ... 9 more stack frames from framework internals

import { ToastAndroid } from 'react-native'ToastAndroid.show('Somthing!', ToastAndroid.SHORT);

GeneratedAppGlideModuleImpl is implemented incorrectly. If you've manually implemented this class, remove your implementation

$
0
0

I am working on react-native project and trying to integrate custom camera features by using an android code. For that, I have added glide library in my project. But after this integration my app is crashed and giving error as below.

I am using this library

implementation 'com.github.bumptech.glide:glide:4.11.0'

annotationProcessor 'com.github.bumptech.glide:compiler:4.11.0'

This is runtime error :

 java.lang.IllegalStateException: GeneratedAppGlideModuleImpl is implemented incorrectly. If you've manually implemented this class, remove your implementation. The Annotation processor will generate a correct implementation.at com.bumptech.glide.Glide.throwIncorrectGlideModule(Glide.java:344)at com.bumptech.glide.Glide.getAnnotationGeneratedGlideModules(Glide.java:336)at com.bumptech.glide.Glide.get(Glide.java:179)at com.bumptech.glide.Glide.getRetriever(Glide.java:749)at com.bumptech.glide.Glide.with(Glide.java:776)at com.fxn.adapters.InstantImageAdapter.onBindViewHolder(InstantImageAdapter.java:123)at androidx.recyclerview.widget.RecyclerView$Adapter.onBindViewHolder(RecyclerView.java:7065)at androidx.recyclerview.widget.RecyclerView$Adapter.bindViewHolder(RecyclerView.java:7107)at androidx.recyclerview.widget.RecyclerView$Recycler.tryBindViewHolderByDeadline(RecyclerView.java:6012)at androidx.recyclerview.widget.RecyclerView$Recycler.tryGetViewHolderForPositionByDeadline(RecyclerView.java:6279)at androidx.recyclerview.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:6118)at androidx.recyclerview.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:6114)at androidx.recyclerview.widget.LinearLayoutManager$LayoutState.next(LinearLayoutManager.java:2303)at androidx.recyclerview.widget.LinearLayoutManager.layoutChunk(LinearLayoutManager.java:1627)at androidx.recyclerview.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1587)at androidx.recyclerview.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:665)at androidx.recyclerview.widget.RecyclerView.dispatchLayoutStep2(RecyclerView.java:4134)at androidx.recyclerview.widget.RecyclerView.onMeasure(RecyclerView.java:3540)at android.view.View.measure(View.java:23196)at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6753)at androidx.appcompat.widget.LinearLayoutCompat.measureChildBeforeLayout(LinearLayoutCompat.java:1381)at androidx.appcompat.widget.LinearLayoutCompat.measureVertical(LinearLayoutCompat.java:665)at androidx.appcompat.widget.LinearLayoutCompat.onMeasure(LinearLayoutCompat.java:555)at android.view.View.measure(View.java:23196)at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6753)at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)at android.view.View.measure(View.java:23196)at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6753)at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)at android.view.View.measure(View.java:23196)at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6753)at androidx.coordinatorlayout.widget.CoordinatorLayout.onMeasureChild(CoordinatorLayout.java:760)at androidx.coordinatorlayout.widget.CoordinatorLayout.onMeasure(CoordinatorLayout.java:833)at android.view.View.measure(View.java:23196)at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6753)at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)at android.view.View.measure(View.java:23196)at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6753)at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)at android.view.View.measure(View.java:23196)at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6753)at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)at androidx.appcompat.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:143)at android.view.View.measure(View.java:23196)at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6753)at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1535)at android.widget.LinearLayout.measureVertical(LinearLayout.java:825)at android.widget.LinearLayout.onMeasure(LinearLayout.java:704)at android.view.View.measure(View.java:23196)at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6753)at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)at android.view.View.measure(View.java:23196)at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6753)at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1535)at android.widget.LinearLayout.measureVertical(LinearLayout.java:825)at android.widget.LinearLayout.onMeasure(LinearLayout.java:704)at android.view.View.measure(View.java:23196)at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6753)at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)at com.android.internal.policy.DecorView.onMeasure(DecorView.java:720)at android.view.View.measure(View.java:23196)at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2796)at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1644)at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1928)at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1532)at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:7419)at android.view.Choreographer$CallbackRecord.run(Choreographer.java:1092)at android.view.Choreographer.doCallbacks(Choreographer.java:888)at android.view.Choreographer.doFrame(Choreographer.java:819)at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:1078)at android.os.Handler.handleCallback(Handler.java:873)at android.os.Handler.dispatchMessage(Handler.java:99)at android.os.Looper.loop(Looper.java:201)at android.app.ActivityThread.main(ActivityThread.java:6810)at java.lang.reflect.Method.invoke(Native Method)at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547)at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:873)Caused by: java.lang.NoSuchMethodException: <init> [class android.content.Context]at java.lang.Class.getConstructor0(Class.java:2327)at java.lang.Class.getDeclaredConstructor(Class.java:2166)at com.bumptech.glide.Glide.getAnnotationGeneratedGlideModules(Glide.java:320)... 75 more 

my code

Glide.with(context).load(image.getContentUrl()).apply(options).into(imageHolder.preview);

Is there a React Native solution for integrating digital persona finger print scanner

$
0
0

I am working on a react-native project for data capturing which requires me to capture finger prints with digital persona finger print scanner. But I couldn't get a solution yet. Help me with this please..

react-native picker styling custom font

$
0
0

I'm using the Picker component which I have successfully customised within my styles.xml file in res/values/styles.xml:

<resources><style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar"><item name="android:spinnerItemStyle">@style/SpinnerItem</item><item name="android:spinnerDropDownItemStyle">@style/SpinnerDropDownItem</item></style><style name="SpinnerItem"><item name="android:fontFamily">Lato-Bold</item><item name="android:textSize">20dp</item></style><style name="SpinnerDropDownItem"><item name="android:fontFamily">Lato-Bold</item><item name="android:padding">10dp</item><item name="android:textSize">16dp</item><item name="android:textColor">#ffffff</item><item name="android:background">#000000</item></style></resources>

At the moment my custom fontFamily: Lato-Bold is being ignored. Does anyone know how to get a custom Spinner font to work?


error: package com.android.annotations does not exist

$
0
0

I have the following class

import com.android.annotations.NonNullByDefault;@NonNullByDefaultpublic final class Log {    ...}

and here is my build.gradle file (some parts omitted)

apply plugin: 'com.android.application'android {    compileSdkVersion 25    buildToolsVersion '24.0.1'    defaultConfig {        minSdkVersion 16        targetSdkVersion 25        versionCode 2        versionName "0.2"    }    compileOptions {        sourceCompatibility JavaVersion.VERSION_1_7        targetCompatibility JavaVersion.VERSION_1_7    }}dependencies {        compile 'com.android.support:appcompat-v7:25.0.0'    compile 'com.android.support:support-annotations:25.0.0'    compile 'com.android.support:design:25.0.0'}

In Android Studio there is no warning raised for my class

enter image description here

However when I try to build and run my app I get this error from gradle

Information:Gradle tasks [:app:clean, :app:generateDebugSources, :app:generateDebugAndroidTestSources, :app:mockableAndroidJar, :app:prepareDebugUnitTestDependencies, :app:assembleDebug]Warning:[options] bootstrap class path not set in conjunction with -source 1.7/home/puter/git-repos/TaskManager3/app/src/main/java/com/treemetrics/taskmanager3/util/Log.javaError:(3, 31) error: package com.android.annotations does not existError:(7, 2) error: cannot find symbol class NonNullByDefaultError:Execution failed for task ':app:compileDebugJavaWithJavac'.> Compilation failed; see the compiler error output for details.Information:BUILD FAILEDInformation:Total time: 21.021 secsInformation:3 errorsInformation:1 warningInformation:See complete output in console

Problem running React Native code on gennymotion emulator

$
0
0

"Couldn't start project on Android: could not install smartsocket listener: cannot bind to 127.0.0.1:5037: Only one usage of each socket address (protocol/network address/port) is normally permitted. (10048) could not read ok from ADB Server * failed to start daemon * error: cannot connect to daemo"

I'm getting this error when i try to run my React Native code on gennymotion emulator. As i'm new to react native so i don't know much how to solve this problem.I write my code on VScode and run on external device and it works perfectly but as i need to debug by code so i have to run it on simulator(I guess).I've downloaded android studio but I dont know what to do with it.It would be great if I get a detailed answer.

Does react-native optimize JavaScript code?

$
0
0

I read a guide on compilers. They have many optimization techniques like removing redundant code or removing unused variables and none used methods.
But script languages like javascript don't have compiler, so take it will not have optimizations.
I read a article about js optimizer like:

- Google Closure Compiler https://github.com/google/closure-compiler- UglifyJS https://github.com/mishoo/UglifyJS

And the real question is Does platforms like react-native, angular, use code optimizer or should I use it myself?

Why app is not opening on some android devices in react native project

$
0
0

I have apk release from react native project, it opens and works fine on some android emulators like Nexus 6 (Edited) API 22 - android 5.1), and never open on another like (Galaxy Nexus API 29 - android 9.0), it gives error pixel launcher keeps stopping (app info or close app).

And for other emulators like (Nexus 6P (Edited) API 29 - android 10.0), I have list coming from json api call never appears , I tried also to make it static with no difference.

My build.gradle file:

buildscript {    ext {        buildToolsVersion = "28.0.3"        minSdkVersion = 16        compileSdkVersion = 28        targetSdkVersion = 28    }    repositories {        google()        jcenter()    }    dependencies {        classpath("com.android.tools.build:gradle:3.4.2")        // NOTE: Do not place your application dependencies here; they belong        // in the individual module build.gradle files    }}allprojects {    repositories {        mavenLocal()        maven {            // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm            url("$rootDir/../node_modules/react-native/android")        }        maven {            // Android JSC is installed from npm            url("$rootDir/../node_modules/jsc-android/dist")        }        google()        jcenter()        maven { url 'https://www.jitpack.io' }    }}

Styling React Native Picker

$
0
0

I'm attempting to style the text color of the items in a React Native picker. I've only been working in iOS so far, but if I could find a cross-platform solution that'd be awesome.

I've tried the following things:

Styling color on Picker

<Picker style={{color:'white'}} ...etc >

Styling color on Picker Items

<Picker.Item style={{color:'#fff'}} label={'Toronto'} value={'Toronto'} />

I've also seen some examples of adding a color property, so I tried this

<Picker.Item color='white' label={'Toronto'} value={'Toronto'} />

At a total loss here. Thanks for any insight!

EDIT:Here's a solution - use itemStyle prop in the Picker element. I believe this is iOS only.

<Picker itemStyle={{color:'white'}} ><Picker.Item color='white' label={'Toronto'} value={'Toronto'} /><Picker.Item  label={'Calgary'} value={'Calgary'} /></Picker>

Is it possible to capture finger prints using android phone scanner and save the finger prints to local sqlite

$
0
0

I am developing a react-native project for data capturing of farmers and I need to get their finger prints as well. Can I achieve this with the devices' scanner and how..

React Native Developer Menu on Huawei Mate 20 Pro

$
0
0

How to open react-native developer menu on Huawei Mate 20 Pro (connected via USB)?

I run app by react-native run-android

Shaking and this is not working:

 adb shell input keyevent 82

Also i did:

adb reverse tcp:8081 tcp:8081

Passing useState update function to child causes undefined function error

$
0
0

Using expo and react-native I have created a screen called MainStateScreen this screen essentially has two direct children called OptionsComponent and NavigationButton. OptionsComponent has multiple children that when modified, update the state of the MainStateScreen so we can pass that as a prop to the next screen with the NavigationButton. That's how it's supposed to work at least.

Instead, when I try to modify the OptionsComponent's children and use MainStateScreen's update function I get the following error.

Here is pseudo-code of my component composition:

MainStateScreen.js

const MainStateScreen = () => {    const [options, setOptions] = usestate(defaultOptionsObject)    return (<View><ScrollView><OptionsComponent options={options} setOptions={setOptions} /></ScrollView><NavigationButton onPress={() => navigation.push('OtherScreen', { options })} /></View>    )}

OptionsComponent.js

const SingleOptionComponent = ({ index, option, options, setOptions }) => {    const [stateOption, setStateOption] = useState({ ...option })    const updateCount = val => {        const tempOption = { ...stateOption }        if (val) {            tempOption.count += 1        } else if (tempOption.count !== 0) {            tempOption.count -= 1        }        setStateOption(tempOption)    }    useEffect(() => {        const tempOptions = { ...options }        tempOptions[index] = { ...stateOption }        setOptions(tempOptions) // Commenting this out removes the error.    }, [stateOption])    const AddSubtractButton = () => {        return (<View><TouchableHighlight onPress={() => updateCount(true)}><Text>Add</Text></TouchableHighlight><TouchableHighlight onPress={() => updateCount(false)}><Text>Subtract</Text></TouchableHighlight></View>        )    }    return (<ListItem rightElement={AddSubtractButton} />    )}const OptionsComponent = ({ options, setOptions }) => {    return (<View>            {options.map((option, index) => {                return (<SingleOptionComponent                        key={`${option?.value}-${index}`}                        index={index}                        option={option}                        options={options}                        setOptions={setOptions}                    />                )            })}<View/>    )}

The exact error is:

TypeError: undefined is not a function (near '...options.map...')This error is located at:    in OptionsComponent (at MainStateScreen.js)

If I remove the setOptions(tempOptions) call from the useEffect inside the SingleOptionComponent the error goes away but I need something like that to accomplish the pass up to the parent and over to the NavigationButton.

What could I be doing wrong?

Will react native work without Google Services on Huawei phone?

$
0
0

Soon new Huawei phones will stop supporting Google Play and Google Mobile Services.

Huawei is preparing its own ecosystem called HMS https://developer.huawei.com/consumer/en/service/hms/developer.html

Their app store is called "Huawei App Gallery" and has its documentation here: https://developer.huawei.com/consumer/en/doc/30202

They are now sending messages to developers (including me) that encourage them to release an app to their store. They are claiming that they only need an APK file and no changes to the application are needed.

My questions are:

  • Is a react-native app going to work without code changes?
  • Is Firebase SDK going to work?
  • What is the real hidden cost of maintaining an app in another Android ecosystem?

React native can't debug while adding .aar file

$
0
0

I have a React Native ("react-native": "0.62.2", with androidx enabled) project with a simple Android Library .aar. All works fine in debug mode and release mode.

While adding a new .aar file to my React Native project, then the application can't be run in debug mode. I get this Logcat on Android studio

2020-05-15 09:30:02.389 15732-15854/com.awesomeproject E/unknown:ReactNative: Exception in native call    java.lang.RuntimeException: Unable to load script. Make sure you're either running a Metro server (run 'react-native start') or that your bundle 'index.android.bundle' is packaged correctly for release.        at com.facebook.react.bridge.CatalystInstanceImpl.jniLoadScriptFromAssets(Native Method)        at com.facebook.react.bridge.CatalystInstanceImpl.loadScriptFromAssets(CatalystInstanceImpl.java:235)        at com.facebook.react.bridge.JSBundleLoader$1.loadScript(JSBundleLoader.java:29)        at com.facebook.react.bridge.CatalystInstanceImpl.runJSBundle(CatalystInstanceImpl.java:259)        at com.facebook.react.ReactInstanceManager.createReactContext(ReactInstanceManager.java:1243)        at com.facebook.react.ReactInstanceManager.access$1000(ReactInstanceManager.java:132)        at com.facebook.react.ReactInstanceManager$5.run(ReactInstanceManager.java:996)        at java.lang.Thread.run(Thread.java:764)

On device, I get the corresponding message Unable to load script. Make sure you're either running a Metro server (run 'react-native start') or that your bundle 'index.android.bundle' is packaged correctly for release.

However, in release mode

npx react-native run-android --variant=release

the application runs correctly without issues.

Also, the new .aar file works normally when integrated to a native Android application.

Any Ideas?

{"error": {"extra": -2147483648, "what": 1}} error while playing .mpd dash files in react -native Android

$
0
0

I have used react-native-video to play DRM content with .mpd extension. But it is giving me an error {"error": {"extra": -2147483648, "what": 1}}

My video-player is like :

         onBack={this.goBack}         videoInfo={toJS(videoDetails)}         videoUrl={dashUrl}         source={{           uri: url,           drm: {             type: "widevine",             licenseServer: [licence_server]",              headers: {                customdata: xml,              },            },          }}        />

There is not any error or urls as it is being played in DRM test site.The above video player uses RNVideo so there is also not an issue as it plays other normal mp4 files.What can be the error?Is it a library issue or what?

React native Keyboard pushes Bottomsheet out of screen / to top

$
0
0

I am struggling with this issue now for over three weeks.I am using the package osdnk/react-native-reanimated-bottom-sheet and I want to use textinputs inside the bottomsheet. The problem appears when opening the keyboard. The bottomsheet is pushed out of the screen.

There is already a github issue about this but everyone seems to get the problem solved. Except me? Also no one answers my questions there.

Steps I tried:

  • Android.xml: android:windowSoftInputMode="adjustPan"I am using expo and don't want to escape, so please don't provide solutions with the Android.xml file.
  • Replaced all flex:1 with height:100%
  • I tried different variations with wrapping the whole Bottomsheet / Content
  • Tried to create a 3rd snapping point with 100% and snap to this point as soon as an Inputfield is focused. However, this also results in the bottom sheet beeing out of the screen.
  • On IOS its working fine.

My code looks like the following: (simplyfied)

const renderInner = () => (<View><FormTextInput/></View>)return (<BottomSheet        snapPoints={['100%']}        renderContent={renderInner}        renderHeader={renderHeader}        initialSnap={0}    />)

How can I fix this weird behaviour? Please provide an example. Its enough to just use an example provided inside the git-repo, clear everything inside the bottom sheet and add a simple text-input.

enter image description here

Viewing all 28463 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>