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

Is there a way to limit my app's network connections to a given set of whitelisted domains in Android/iOS?

$
0
0

To improve my app's security I'd like to only accept network connections with a set of whitelisted sites.

My app uses react-native.

I've only found settings to filter non-secure connections (i.e. without tls encryption), but nothing similar to what I mentioned above.


toExpontial is undefined in react native

$
0
0

Always having this error: num.toExponential is not a funtion. num.toExponential is undefined. Why is toExponential() doesn't run on react native? How to replicate this functionality in react native?

let num = 0.00005678;

alert(num.toExponential());

Failed to connect to development server using "adb reverse"

$
0
0

I'm running a react-native app with an android emulator running normal, but when I use the command "react-native run-android" that launch me this error:

warn Failed to connect to development server using "adb reverse": spawnSync C:\Users\HP-Envy\AppData\Local\Android\Sdk;/platform-tools/adb ENOENT

Another question about icons and push notifications

$
0
0

I searched a lot for this question in these last days and any answer that I saw until now it couldn't help.

I'm developing an app with React-Native and after trying with a lot of modules to send push notifications, I decided to use the services of Backendless.

Their system works very fine but I can't find an answer to what or where change to show a custom icon instead of the default white square in the notification.

I inserted the meta-data firebase.messaging.default_notification_icon in AndroidManifest.xml, I tried to make modifications in the function that set icon inside of the backendless module, tried to use Android vector drawable instead of png and some others things, everything I tried not worked.

Has someone any suggestion?

Thanks

How to detect hold and fastforward event in react native TVEventHandler

$
0
0

I am new to React Native. I want to know how can implement press and hold event for seek. I am able to get fastForward and press right events in React native layer by using below code.

_enableTVEventHandler() {
    this._tvEventHandler = new TVEventHandler();
    this._tvEventHandler.enable(this, function(cmp, evt) {
      if (evt && evt.eventType === 'right') {
        cmp.setState({board: cmp.state.board.move(2)});
      } else if(evt && evt.eventType === 'up') {
        cmp.setState({board: cmp.state.board.move(1)});
      } else if(evt && evt.eventType === 'left') {
        cmp.setState({board: cmp.state.board.move(0)});
      } else if(evt && evt.eventType === 'down') {
        cmp.setState({board: cmp.state.board.move(3)});
      } else if(evt && evt.eventType === 'playPause') {
        cmp.restartGame();
      }
    });
  }

Not able to get the hold fastforward or hold and right event to detect seek event. I am not sure it if its possible in RN layer. If not then how can i do the same in Android layer.

Thanks in advance

Download Audio file in react native?

$
0
0

I'm trying to download audio file "mp3" using rn-fetch-blob.

So I have more than one cases :)

When I trying to add a path to RNFetchBlob config like this

const pathFile = RNFetchBlob.fs.dirs.MainBundleDir // Or .DocumentDir // Others is crashed my App 'Android';

The callback "then" get success so i log console.log('The file is saved to ', res.path()) But when I try to explore this file in my real device I can't find them I don't know why!

So there's one faced same issue like this in Android?

startDownload = () => {
    const {url} = this.state;
    const pathFile = RNFetchBlob.fs.dirs.DocumentDir;
    let date = new Date();
    RNFetchBlob.config({
      fileCache: true,
      path:
        pathFile +
        '/me_' +
        Math.floor(date.getTime() + date.getSeconds() / 2),
    })
      .fetch('GET', url)
      .then(res => {
        console.log('The file is save to ', res.path()); // It's log here but i can't see the file :\
      })
      .catch(err => console.log('err', err));
  };

React native bridge - emitting events from an android view class

$
0
0

Currently I am bridging a heremaps sdk on android. I've been looking at the RN documentation for emitting events, and while it is very clear it is not detailed as I'm having trouble figuring how to emit events from a UI View class. The example shows us an example to place in a Module class so I'm a bit confused on the implementation. In below abbreviated example, I initialize a map that attached a listener for navigation events and I planned on sending events to JS on the navigation events. How would I emit the events in the instructListener below?

Would I create a module class for the emitter function? If so, how can I call the sendEvent function from my UI view class?

Apologies in advance as I'm very new to Java/Android dev environment.

MapView.java

imports ...

public class MapView extends MapView {

  public HereMapsNavigationView(Context context) {
  //initialize map logic
  // adds the instructListener

}


//intructListener
  public NavigationManager.NewInstructionEventListener instructListener = new NavigationManager.NewInstructionEventListener() {

    @Override
    public void onNewInstructionEvent() {
      // Interpret and present the Maneuver object as it contains
      // turn by turn navigation instructions for the user.
      m_navigationManager.getNextManeuver();

      Maneuver maneuver = m_navigationManager.getNextManeuver();
      if (maneuver != null) {
        if (maneuver.getAction() == Maneuver.Action.END) {
          // notify the user that the route is complete
        }

        // display current or next road information and emit info to JS
        ---> place emitter here <----
      }
    }
  };

}

React Native screen cut off at top Android

$
0
0

I have an input that is cutt off at the top. Is it possible to have it aligned directly under the black bar without writing specific margins/padding for it? If I take off the padding the element completely dissapears from the screen

Image of input being cut off

import React, { Component } from 'react';
import {View, TextInput, StyleSheet, Dimensions } from 'react-native';

export default function IndoorFOrm() {
  const [value, onChangeText] = React.useState('Useless Placeholder');

  return (
    <View style={styles.container}>
        <TextInput
            style={styles.button}
            onChangeText={text => onChangeText(text)}
            value={value}
        />        
    </View>

  );
}

const styles = StyleSheet.create({
    container: {
      flex: 1,
      alignItems: 'center',
      justifyContent: 'center',
      paddingTop: 35,
      backgroundColor: '#ecf0f1',
    },
    button:{
      borderRadius: 4,
      borderWidth: 2,
      width: 100,
      height: 40,
      borderColor: 'red',
      backgroundColor: "rgb(72, 120, 166)",
    }
  });

React Native is dimming companion component

$
0
0

I am learning React Native while trying to build a simple Android app. I have two components (TextInput and Button) aligned side by side. The TextInput component is wrapped in and the Button component is wrapped in a regular outside of . Yet somehow whenever I click on TextInput, both the Button and the TextInput get dimmed.

How can I make it work so that only TextInput Component gets dimmed but not the button?

Thank you

export default class TodoItem extends React.Component{

    constructor(props)
    {
         super(props);
    }

    render(){
            const todoItem = this.props.todoItem;

            return[
                <TouchableOpacity
                    style={styles.todoItem}
                    onPress = {() => this.props.toggleDone()} >

                    <Text
                        style={(todoItem.done) ? {color: '#AAAAAA'}:{color: '#313131'}}>
                        {todoItem.title}
                    </Text>


                </TouchableOpacity>,


                     <View
                                style={styles.emailButton}
                     >


                           <Button
                               style = {styles.removeButton}
                               title="Remove"
                               color = {(todoItem.done) ? 'rgba(200,0,0,0.5)' : 'rgba(255,0,0,1)'}
                               onPress = {() => this.props.removeTodo()}
                           />

                     </View>,



            ];

        }

}

const styles = StyleSheet.create({
    todoItem: {
        width: '70%',
        height: 40,
        borderBottomColor: '#000000',
        borderBottomWidth: 1,
        flexDirection: 'row',
        flex : 1,
        alignItems: 'center',
        justifyContent: 'flex-start',

        paddingLeft: 15
    },

     removeButton:
    {
        width : '30%',
        flex: 1,
        justifyContent : 'flex-end',
    }

On Windows Linux Subsystem, the Android SDK directory does not exist

$
0
0

I have been running react native for a while on windows 10 but decided to install the ubuntu subsystem to continue my development as I prefer linux for dev work.

After installing ubuntu and trying to build my react native app I get this error.

The SDK directory /mnt/c/Projects/AppName/android/C:\Users\UserName\AppData\Local\Android\Sdk' does not exist.

The path is strange looking as it has my current path concatenated with the actual location of my android sdk on my windows file system (but not the path linux needs as it uses /mnt/c/ instead of C:\). That looks pretty wrong.

Here's some info about my system:

echo $ANDROID_HOME 
/mnt/c/Users/UserName/AppData/Local/Android/sdk/

less android/local.properties
sdk.dir=C\:\\Users\\UserName\\AppData\\Local\\Android\\Sdk

It seems like you should be able to link to the Windows install of the android sdk, if it used my ANDROID_HOME I think it would work. But something tells me I might need to install the sdk separately on ubuntu. I'd like to avoid that for hard disk space reasons.

I'm hoping to be able to keep react native working on windows and in the ubuntu subsystem if possible as I'm not sure if there will be some issue in the future for running react native on ubuntu. It currently works great on windows 10 so... not trying to break that.

Thoughts?

React Native - ERROR point to the same directory in the file system. Each module must have a unique path

$
0
0

enter image description here

I try Sync Gradle in Android studio but i received error ERROR: The modules ['@react-native-community-geolocation-android-@react-native-community_geolocation', '@react-native-community-geolocation-android-react-native-community_geolocation~2'] point to the same directory in the file system. Each module must have a unique path. I check project in Android Studio, i see react-native-community_geolocation create multiple file .iml, what's cause and how to fix it?

Error type 3. Activity class {com.awesome_project/ com.awesome_project.MainActivity} does not exist in react native (Android device)

$
0
0

I've created the project using the following command.

react-native init Awesome_Project

I've started the packager using the following command.

react-native start

I've connected my Android mobile using USB drive.

I've opened another command prompt and run the following adb command to make sure that only one device is connected.

adb devices

I've started the application using the following command.

react-native run-android

I've been confronted with the following error.

open: Permission denied
open: Permission denied
Starting: Intent { com.awesome_project/.MainActivity }
Error type 3
Error: Activity class {com.awesome_project/ com.awesome_project.MainActivity} does not exist.

Thanks in advance.

Expo run on android emulator using windows 10

$
0
0

Can I run android emulator without an android phone? I have installed android studio and I've already installed android virtual device. However, when I try to run it, it gives an error like this :

Couldn't start project on Android: Error running adb: No Android device found. Please connect a device and follow the instructions here to enable USB debugging: https://developer.android.com/studio/run/device.html#developer-device-options. If you are using Genymotion go to Settings -> ADB, select "Use custom Android SDK tools", and point it at your Android SDK directory.

I just want to see the emulator in my pc without usb. I have an iPhone but it just shows up in my phone not in my pc using expo scan barcode. I don't want to do that because in my opinion it's not comfortable for debugging etc. I am using windows in my pc so I can't use iOS for emulator.

how to run expo android emulator on windows?

React native firebase notification sound for call/alarm notification category

$
0
0

I am using react-native-firebase for a voice call app. I tried to create an incoming call notification as below:

const notification = new firebase.notifications.Notification()
    .setTitle("Incoming call")
    .android.setAutoCancel(true)
    .android.setCategory("call")
    .setSound('default')
    .setBody("Test User");


const channel = new firebase.notifications.Android.Channel('test-channel', 'Test Call Channel', firebase.notifications.Android.Importance.Max)
                .setDescription('Test call channel')
                .setSound('default');

firebase.notifications().android.createChannel(channel);

notification.android.setChannelId(channel._channelId)
            .android.setSmallIcon('ic_launcher');

firebase.notifications().displayNotification(notification);

But still, the notification sound is default message notification sound. Also tried changing the category as "alarm". Also tried adding an mp3 file in "res/raw" folder and used setSound("ring.mp3")

package.json details:

{
.
.
"react-native-firebase": "^5.6.0",
"react": "16.9.0",
"react-native": "0.61.5",
.
.
}

Can anyone help with this?

React native map's Heatmap doesn't work when there is a lot of close points on Anroid

$
0
0

I am using "react-native-maps": "^0.26.1" and "react-native": "0.61.5". I have an API that returns points and i noticed that the Heatmap from react-native-maps bugs in some circumstances. It can handle and show a lot of points when they are spread all over the map but when there is a lot of points around one area, on Android, it doesn't show anything but on IOS it works fine (as shown on the pictures below).

On IOS On IOS

On Android On Android

Both are with 85 points. With 80, i don't have the bug on Android so i am guessing the problem is with the algorithm on android when there is a lot of nearest points, and i don't know how to correct it. Any idea or workaround ? any other case ?


install permission in android

$
0
0

I have a RN app runs in android, now I want to update it, because android8 request developer to request REQUEST_INSTALL_PACKAGES in app, so I write some code to request install permision, but the code doestn't work.It throwes some errors.

error:can not find symbol.
symbol: Function canRequestPackageInstalls()
location: Class PackageManager

error:can not find symbol.
symbol: Variable O
location: Class VERSION_CODES

error:can not find symbol.
symbol: Variable ACTION_MANAGE_UNKNOWN_APP_SOURCES
location: Class Settings

code:

public void checkVesion() {
    boolean haveInstallPermission;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        haveInstallPermission = myActivity.getPackageManager().canRequestPackageInstalls();
        if (!haveInstallPermission) {
            new AlertDialog.Builder(myActivity)
                    .setTitle("tips")
                    .setMessage("tips code")
                    .setNegativeButton("exit", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            dialog.cancel();
                            Toast.makeText(myActivity, "ss", Toast.LENGTH_LONG).show();
                            System.exit(0);
                        }
                    })
                    .setPositiveButton("confirm", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
                                Uri packageURI = Uri.parse("package:" + myActivity.getPackageName());
                                Intent intent = new Intent(Settings.ACTION_MANAGE_UNKNOWN_APP_SOURCES, packageURI);
                                (myActivity).startActivityForResult(intent, 2);
                                dialog.cancel();
                            }
                        }
                    }).show()
                    .setCanceledOnTouchOutside(false);
        }else{
            downLoadApk();
        }
    } else {
        downLoadApk();
    }
}

buildToolsVersion is 24.0.0, targetSdkVersion is 26.

Execution failed for task ':app:transformClassesWithDexForDebug' in react native

$
0
0

I am new in react native and I use it in Ubuntu. I would like to run a project on my PC. I use yarn and android emulator. Here is my installed application versions:

yarn: 1.2.0

nmp: 3.10.10

I got the following error while use:

$ react-native run-android

Here is the error:

  * What went wrong:
    Execution failed for task ':app:transformClassesWithDexForDebug'.
    > com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: java.lang.UnsupportedOperationException

I have tested many solutions that exist in stackoverflow but, non of them did't work for me. such as:

Adding google services - Execution failed for task ':app:processDebugResources'

Error:Execution failed for task ':app:transformClassesWithDexForDebug' in android studio

I also use Google play service and I have installed Firebase plugin. Do you have idea that what should I do?

React Native WebView video not playing in iOS

$
0
0

I developed mobile app which has video player in react native.
Then I built both Android and iOS app from the react native project.
But it's working well in Android but not playing in iOS.
If you've ever experienced this problem, please help me.

This is code and package information.

<WebView 
    allowsFullscreenVideo={true} 
    style={{ aspectRatio: 1.6, backgroundColor: "#000000", flex: 1 }}
    source={{ uri: 'https://sample.mp4' }}                    
/>

"react": "16.9.0",
"react-native": "0.61.5",
"react-native-webview": "^8.0.3",

Different behavior when App is sent to Background State using Home or Back physical button

$
0
0

I'm testing in Android a chat app developed in React Native and I'm noticing a strange behavior that only depends on how do you send the app to background.

Two devices are needed to replicate the bug: Device1 with User1 logged in and Device2 with User2 logged in.

Case situation:

  1. Send App from Active to Background state using the Home button.
  2. Send App from Active to Background state using the Back physical button.

Once the App in Device1 is on Background State, wait for 1-2 minutes until de WebSocket connection is closed. Then, send a chat message from User2 to User1. Open the App again in Device1 (changing its state to Active)

In case 1, you will receive the message correctly and you'll see the message sent in the Chats view as well as inside the conversation. In case 2, the reception of the message is inconsistent. You may receive it, but it will not show in the Chats view, and inside the conversation it will appear with the wrong order and/or timestamp.

Everytime I install react-navigation my project stops working

$
0
0

I'm trying to use react-navigation with my react-native project. The project will work up until I install react-navigation. After I install it when I try to run my app using a virtual device I keep getting an error when I try to use the command react-native run-android.

I'm not sure what happened, but it was working just fine before installing react-navigation. Below is the error I'm getting after I try to start it.

react-native start bundler after using react-native run-android

Viewing all 29536 articles
Browse latest View live


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