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

React Native notification badge icon with counting in Android

$
0
0

I'm new to React Native and I'd like to display notification badge with counting number icon on home screen in Android, please see example result image below:

Image

In iOS I'm experimenting on PushNotificationIOS extension but in Android seems to be deadened, I've tried to research for 2 days and still looking for a solution in Android.


how to implement camera scan to detect distance between two red color lines from image?

$
0
0

i am working on app in react native to scan testing strip as shown in images.i have to find C,G,M point if they contain red lines using camera.i have to scan and get reading where the redlines shown after test using mobile camera.any solutions or flow how to do it in react native?even in android or ios?

i am using nativemodules for native code implementation.

here is the code. i have logic that first turn image into grayscale then black and white then get corodinates of the line.

here is the code .

public class ConverttoBitmap extends ReactContextBaseJavaModule {public Context context;public ConverttoBitmap(ReactApplicationContext reactContext) {    super(reactContext);    this.context = reactContext;}@Overridepublic String getName() {    return "Bitmap";}@ReactMethodpublic void getPixels(String filePath, final Promise promise) {    try {        WritableNativeMap result = new WritableNativeMap();        WritableNativeArray pixels = new WritableNativeArray();Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(),                R.drawable.singleline);        Log.i("ssssss", bitmap+","+filePath);        if (bitmap == null) {            promise.reject("Failed to decode. Path is incorrect or image is corrupted");            return;        }        Bitmap imgnew;        imgnew = toGrayscale(bitmap);        imgnew = convertBitmap(imgnew);        saveImageToStorage(imgnew);        promise.resolve(imgnew);    } catch (Exception e) {        promise.reject(e);    }}public Bitmap convertBitmap(Bitmap input) {    Bitmap output =  Bitmap.createBitmap(input.getWidth(), input.getHeight(), Bitmap.Config.ARGB_8888);    Canvas canvas = new Canvas(output);    Paint colorFilterMatrixPaint = new Paint(Paint.ANTI_ALIAS_FLAG);    colorFilterMatrixPaint.setColorFilter(new ColorMatrixColorFilter(new float[] {            90.f, 90.f, 90.f, 0.f, -255.f * 128,            90.f, 90.f, 90.f, 0.f, -255.f * 128,            90.f, 90.f, 90.f, 0.f, -255.f * 128,            0f, 0f, 0f, 1f, 0f    }));    canvas.drawBitmap(input, 0, 0, colorFilterMatrixPaint);    return output;}private void saveImageToStorage(Bitmap bitmap) throws IOException {    OutputStream imageOutStream;    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {        ContentValues values = new ContentValues();        values.put(MediaStore.Images.Media.DISPLAY_NAME,"image_screenshot.jpg");        values.put(MediaStore.Images.Media.MIME_TYPE, "image/jpeg");        values.put(MediaStore.Images.Media.RELATIVE_PATH,Environment.DIRECTORY_PICTURES + File.pathSeparator +"AppName");        Uri uri =                context.getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,                        values);        Log.i("output", String.valueOf(uri));        imageOutStream = context.getContentResolver().openOutputStream(uri);    } else {        String imagesDir =                Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES). toString() +"/AppName";        File image = new File(imagesDir, "image_screenshot.jpg");        Log.i("output", String.valueOf(image));        imageOutStream = new FileOutputStream(image);    }    bitmap.compress(Bitmap.CompressFormat.JPEG, 100, imageOutStream);    imageOutStream.close();}public Bitmap toGrayscale(Bitmap bitmap) {    int width, height;    height = bitmap.getHeight();    width = bitmap.getWidth();    Log.i("GrayScale", width+"x"+height);    Bitmap bmpGrayscale = Bitmap.createBitmap(width, height, Bitmap.Config.RGB_565);    Canvas c = new Canvas(bmpGrayscale);    Paint paint = new Paint();    ColorMatrix cm = new ColorMatrix();    cm.setSaturation(0);    ColorMatrixColorFilter f = new ColorMatrixColorFilter(cm);    paint.setColorFilter(f);    c.drawBitmap(bitmap, 0, 0, paint);    Log.i("GrayScale", String.valueOf(bmpGrayscale));    return bmpGrayscale;}

}

please solution to find text point C,G,M who has red line.

please any solution how to scan red lines and get text that shows reading that has redline?first image

React Native Error: Attempted to use a firebase module that is not installed on your Andrid project by calling firebase.firestore()

$
0
0

I am not sure what else to do. I have this erros when trying to login into a application:

React Native Error: Attempted to use a firebase module that is not installed on your Andrid project by calling firebase.firestore()

I read documentation and everything looks good according to it.

MainApplication.java:

>     import io.invertase.firebase.auth.RNFirebaseAuthPackage;>     import io.invertase.firebase.RNFirebasePackage;>     import io.invertase.firebase.storage.RNFirebaseStoragePackage;>     import com.facebook.soloader.SoLoader;    @Override    protected List<ReactPackage> getPackages() {      @SuppressWarnings("UnnecessaryLocalVariable")      List<ReactPackage> packages = new PackageList(this).getPackages();      // Packages that cannot be autolinked yet can be added manually here, for example:      // packages.add(new MyReactNativePackage());      packages.add(new RNFirebaseAuthPackage());      packages.add(new RNFirebaseStoragePackage());      return packages;    }

build.gradle in android/:

buildscript {    ext {        buildToolsVersion = "28.0.3"        minSdkVersion = 16        compileSdkVersion = 28        targetSdkVersion = 28        supportLibVersion = "28.0.0"    }    repositories {        google()        jcenter()        mavenCentral()    }    dependencies {        classpath 'com.google.gms:google-services:4.3.3'        classpath("com.android.tools.build:gradle:3.4.1")

build.gradle in android/app

    implementation project(':react-native-firebase')    implementation "com.google.firebase:firebase-auth:19.2.0"    implementation "com.google.firebase:firebase-storage:19.1.1"    implementation "com.google.firebase:firebase-database:19.2.1"    implementation "com.google.firebase:firebase-firestore:21.2.1"

Already clean e nothing works. I still getting the same error. According to the documentation, all the files are right configured.

Android/iOS native build doesn't include the latest react-native-code-push bundle and always shows an update being available

$
0
0

I have integrated react-native-code-push and have created a custom UI for update downloading, installing and reacting. I have also done the native Android changes as mentioned in the docs. It works perfectly, except, when doing a native build, I am always seeing Task :app:bundleReleaseJsAndAssets being carried out. This creates a default bundle and embeds it in the native build, both in Android and iOS and not the latest build created by CodePush.

How do I get this done? I wanted a more Expo like experience, with the latest bundle embedded.

Unable to launch logbox because react was unable to create the root view in Google Pixel 8.0

$
0
0

APK installed in device but when i open showing error (Only for android 8.1)

Device: Google PixelOperating System: Android 8.0Screen size: 5.0 in - 2.5 x 4.4 inViewport: 411 x 731 dpAspect Ratio: 16 : 9
07-22 12:57:46.668 E/unknown:ReactNative( 6529): Unable to launch logbox because react was unable to create the root view 

Complete log file

getInitialNotification of React Native Firebase returns notification object only for first push notification

$
0
0

I have a weird problem with @react-native-firebase/messaging. I recently updated to v6 and everything works well on iOS and on Android everything works well except for one thing.

When getting multiple push notifications the following is the case:

  1. Clicking on one notification opens the app and getInitialNotification() gives me the clicked notification, so I can handle it
  2. When closing the app completely and then clicking on one of the other notifications the app opens again, but getInitialNotification() returns null

It seems like opening the app with one notification eats the data of all the other notifications as well.I guess I'm doing something wrong, but I have no clue where I can search for the issue.

Some information about the setup

  • I removed react-native-splash-screen (didn't change anything)
  • I am on the most recent versions of @react-native-firebase/app and /messaging ("@react-native-firebase/app": "8.2.0", "@react-native-firebase/messaging": "7.4.2")
  • React Native is on version 0.62.2
  • The app is calling getInitialNotification() in a useEffect, so after the first render of the navigation tree

React native fbsdk user change issue on both IOS and Android

$
0
0

I use this (https://github.com/facebook/react-native-fbsdk) component in attempts to setup authentication to my app using Facebook. I've successfully configured it so login button gives me a valid token on both platforms.

Problem is that application records successfully logged user and it is pretty tricky to get rid of it (only reinstall can help). Moreover, when you try to change logged a user in facebook application on android - it gives an error:

'User logged in as different Facebook user'

I always receive this screen instead of a login form, where I can enter other credentials or at least change the account.

I use provided LoginManager.logInWithReadPermissions for login and LoginManager.logOut seems to do nothing.

So, is it possible for me to make application to give a user a choice if the login was not correct or main-fb-app account has changed?

React-native vector icons shown as question mark

$
0
0

I have installed react-native v0.46 and installed NativeBase along with but after using tag in components, no icon displayed instead question mark is displayed (Android and not tested in iOS).

To solve this issue I did lots of modifications listed as follow:

  1. rnpm link
  2. react-native link react-native-vector-icons
  3. NativeBase installation guide: https://nativebase.io/docs/v0.3.0/getting-started
  4. https://github.com/oblador/react-native-vector-icons
  5. My json package file:{"name": "Magazine","version": "0.0.1","private": true,"scripts": {"start": "node node_modules/react-native/local-cli/cli.js start","test": "jest" },"dependencies": {"native-base": "^2.3.1","react": "16.0.0-alpha.12","react-native": "0.46.4","react-native-image-slider": "^1.1.5" },"devDependencies": {"babel-jest": "20.0.3","babel-preset-react-native": "2.1.0","jest": "20.0.4","react-test-renderer": "16.0.0-alpha.12" },"jest": {"preset": "react-native" }}
  6. And the component where i used these icons: ios-arrow-left & navicon

I am using Windows 10, Node v8.1.4, React-native-CLI v2.0.1

code:

import React, { Component } from 'react';import {  AppRegistry,} from 'react-native';import {Container, Header, Title, Button, Icon} from 'native-base';export default class CityMagazine extends Component {  render() {    return (<Container><Header><Button transparent><Icon name="ios-arrow-left" /></Button><Title>Header</Title><Button transparent><Icon name="navicon"/></Button></Header></Container>    );  }}AppRegistry.registerComponent('CityMagazine', () => CityMagazine);

Failed to install the app in react-native

$
0
0

Android

My application was running perfectly before and after some changes in some js files this error appeared

FAILURE: Build failed with an exception.* What went wrong:Execution failed for task ':app:installDebug'.> com.android.builder.testing.api.DeviceException: com.android.ddmlib.InstallException: INSTALL_FAILED_INSUFFICIENT_STORAGE* Try:Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.* Get more help at https://help.gradle.orgBUILD FAILED in 1m 0serror Failed to install the app. Make sure you have the Android development environment set up: https://reactnative.dev/docs/environment-setup. Run CLI with --verbose flag for more details.Error: Command failed: gradlew.bat app:installDebug -PreactNativeDevServerPort=8081Unable to install C:\projects\Maheema\android\app\build\outputs\apk\debug\app-debug.apk

React Native - Random ReferenceErrors (Can't find variable)

$
0
0

When running our app I'm seeing some ReferenceErrors. They seem to be on and off because there are builds where the app works fine and in the next build it crashes on a ReferenceError. For example:

ReferenceError: Can't find variable: interpolatedCircleColorReferenceError: Can't find variable: _careItem (this comes from a component I created)ReferenceError: Can't find variable: stateReferenceError: Can't find variable: style

Each build I get one of these errors. It never seems to be missing more than one variable. There are four components where the errors come from. Other screens/components work just fine. These components don't work together in any way. They all just display data passed on as a prop. The errors are now visible in both development and release builds. On development builds the errors are shown, when I fix them everything seems to be OK. But after a release build it needs different variables and the app shows a white screen.

I used to overcome this problem by defining the missing variables as an empty string in the component that needed it. But this is just a hack to get it to work (sometimes). But with some 'variables' it expected a function this is where I decided the problem needed to be fixed for good.

Example. I would pass these variables in the render function of the component:

const interpolatedCircleColor = '';const interpolatedTranslateX = '';const handlerAnimation = '';const height = '';const style = '';const state = '';const opacityStyle = '';const substitutionStyle = '';const containerStyles = '';const tintColor = '';

I suspect the problem is with bundling the app as this is where I can find the missing variables.

To build the app in release mode I use the following process:

  1. rm -rf $TMPDIR/react-* && watchman watch-del-all && yarn cache clean
  2. cd android && ./gradlew clean && cd ..
  3. react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res --sourcemap-output android/app/src/main/assets/index.android.bundle.map
  4. npx react-native run-android --variant=release

This would then give me one of the errors I mentioned above. In one of the four components.

Additional information:

"react-native": "0.63.1","react": "16.13.1",
node v14.5.0npm 6.14.5

Any help would be greatly appreciated!

How to share App link using react native Share API?

$
0
0

I am trying to share my app installation link to others from my app settings in react native.

I used the react native share api for this.

But using the below code the output only shows the message(code and screenshot below).

const shareAppOptions = {  title: 'App link',  message: 'Please install this app and stay safe',   url: 'https://play.google.com/store/apps/details?id=nic.goi.aarogyasetu&hl=en'};

enter image description here

What is the problem ?, I searched everywhere and no one has a proper example.

React Native: 'android.bluetooth.bluetoothadapter.isEnabled()' on a null reference

$
0
0

I am working on a React-Native app that relies on Bluetooth for some of its functionality and as far as I understand, Android Studio's emulator does not support Bluetooth. The package I am using is react-native-eddystone which is used to work with Bluetooth low energy devices. When I start the app on my phone it prompts me to allow the usage of Bluetooth and works fine but when I use the emulator it crashes from the start. Here is the AndroidManifets.xml:

<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:tools="http://schemas.android.com/tools"><uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/><uses-permission android:name="android.permission.BLUETOOTH"/><uses-permission android:name="android.permission.BLUETOOTH_ADMIN" /><uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /><application android:usesCleartextTraffic="true" tools:targetApi="28" tools:ignore="GoogleAppIndexingWarning" /></manifest>

And here is a screenshot of the error:enter image description here

react native metro server

$
0
0

I have an error with React Native apk it works fine in android studio with different emulator versions but when I copy the apk from (android\app\build\outputs\apk\debug) to my real device it doesn't work

enter image description here

Add Wifi Printers to React Native

$
0
0

I am developing a React Native app and as a part of functionality the app needs to scan for printers connected in the same WiFi network as app is connected.As a part of the research i could find only one library react-native-printer but this does not gives full flexibility so i thought of integrating this module as a Native Module(Java and Swift) as a first step i started to look for Android support but could not find any proper documentation or example for the same.Any working example or documentation will be helpful.

Currently i tried WifiManager API from Android to scan for printers but then once i get scan result how do i configure the printer for the app to print jobs.

Note: i need to identify any generic printers that is connected to the same WiFi network.

Expo standalone apk bug

$
0
0

I am a little bit new to React Native and Expo. I've created app for practicing and I have strange behaviour. Since I cannot show you with some media I'll try to explain step by step, if anyone knows how to fix I'll appriciate that.

Okay, so I have an app with 4 tabs at the bottom tab navigation, the problem happens only in 2nd tab (explore screen). In this screen app is fetching users location and filters posts based on it. At this screen I have header button for filters which navigates to filters screen. On the filters screen user can filter posts by category and by location. If location permission is granted location filter is preset to user's current location, although he can change it in filters screen to explore posts on different location. There comes problem, when I navigate to filters screen from explore on some android phones my app just refreshes (Shows splash screen and restarts to home page). On my android phone I can open filters screen but when I change the location filter to nothing (match any location) same behaviour happens.

Sorry if this is confused but I hope you get me. I've built android apk just to test it on my devices and I dont know how to fix this, can it be caused by memory leak or something?

(In development mode using expo client everything behaves fine)

Thanks a lot!

Forgot to say that I am using redux for state managment and filter settings are stored there.


React Native running in background

$
0
0

I need create an app who run an WebView components ever after closing the app. I'am using React Native for developing the app.

Which is the best way to distribute react-native bridges for IOS and Android

$
0
0

I have developed 2 bridges using react-native bridge modules for each mobile operating system (Android, iOS). Both of them include Layout files (Android) and Storyboards (iOS) and they are using the native capabilities of the phone like camera etc. Is there a way to distribute these modules as libraries. For example, .aar for Android and .framework for iOS so the code of them cannot be visible (compiled to bytecode).

How to create an Intent in React-Native and pass Data to it?

$
0
0

I was wondering how does one start up a React-Native application and have the data in the intent when the application is launched, so that I can reference it in one of my React-Native components?

I put this intent-filter under my MainActivity in the mainfest:

<intent-filter><action android:name="android.intent.action.SEND" /><category android:name="android.intent.category.DEFAULT" /><data android:mimeType="text/*" /></intent-filter>

and then in MainActivity.java:

@Override    protected ReactActivityDelegate createReactActivityDelegate() {        return new ReactActivityDelegate(this, getMainComponentName()) {            @Override            protected Bundle getLaunchOptions() {                Intent intent = MainActivity.this.getIntent();                Bundle bundle = new Bundle();                bundle.putString("test", "Test Data");                return bundle;            }        };    }

and then I tried referencing the "test" field in my app.js of my React Native:

componentDidMount() {  console.log(this.props.test);}

However, the this.props.test is undefined, but it's supposed to say "Test Data" since I put that in the bundle of the MainActivity.java.

Android app built for release still trying to connect to localhost:8081

$
0
0

I'm trying to get an alpha build of my React Native app on my Android phone, but when I open it, it immediately crashes. Fortunately, it's instrumented so I can see that the errors are all because it's still trying to connect to the metro server, which I would expect from a debug build, but I can't figure out how to prevent these calls in a release build. Here are the errors:

Cannot connect to host http://localhost:8081/inspector/deviceCannot connect to host http://localhost:8081/message

Steps taken:

  • I'm generating a signed APK via Android Studio, then sending it to myself and installing on my phone.
  • Even though I choose a release build in the "Generate signed Bundle or APK" dialog, I also set the default build variant to "release". This oddly changed the connection attempts from "10.0.0.22" to "localhost" but didn't fix my problem.
  • I've tried cleaning the project.
  • I've searched the project for any references to localhost or 10.0.0.22 and found nothing that should relate to an Android build.

Possibly pertinent information:

  • I began this as an Expo project and ejected a few weeks ago, but Expo seems to have left some cruft behind.

Admob banner ad displaying white, expo on Android

$
0
0

I can't seem to get Admob banners to display anything except a white box. I can confirm that the adUnitID is correct and the ad unit is enabled. My app.json android part:

"android": {"config": {"googleMobileAdsAppId": "xxx"  },"package": "xxx","versionCode": 1},

And here is the Admob banner component within my app.js:

<View style={styles.container}>    {Platform.OS === 'ios'&& <StatusBar barStyle="default" />}<AppNavigator /><View style={styles.adContainer}><AdMobBanner        bannerSize='fullBanner'        adUnitId='xxx'        onDidFailToReceiveAdWithError={() => console.log('error')}        servePersonalizedAds      /></View> </View> const styles = StyleSheet.create({   container: {     flex: 1,     backgroundColor: '#fff',   },   adContainer: {     borderColor: 'red',     borderWidth: 1,   }, });

Looking at the logs, it never actually prints out "error." I put the border around the ad container to confirm that it is being displayed, if I change the bannerSize prop I can see it changing size so it is allocating the space for the banner correctly. This is Expo SDK version 37.0.10 and I've only tested on an Android physical device. When I create an apk it similarly shows the banner as only white.

Viewing all 29709 articles
Browse latest View live


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