Srishti Singhal
Srishti Singhal

Reputation: 181

React native image picker is not functioning properly

I have used react-native-image-picker and sometimes as soon I take picture from camera, app gets restarted in android? Can anyone help me with that issue?

Upvotes: 1

Views: 6978

Answers (7)

Amit
Amit

Reputation: 2715

There is a privacy change in Android 10 and above by introducing Scoped Storage.

To opt-out of that feature by using requestLegacyExternalStorage manifest attribute:

<application
      android:name=".MainApplication"
      android:requestLegacyExternalStorage="true"  ...

Note: This flag allows apps to temporarily opt-out of the changes associated with scoped storage, such as granting access to different directories and different types of media files. After you update your app to target Android 11, the system ignores the requestLegacyExternalStorage flag.

It's a best practice to use scoped storage unless your app needs access to a file that doesn't reside in the app-specific directory.

Upvotes: 1

Dawood Shahid
Dawood Shahid

Reputation: 41

This issue will only be on the android X or any latest android version. In order to resolve the issue you need to add the following line in the AndroidManifest.xml file.

android:requestLegacyExternalStorage="true"

I hope it will resolve your issue.

Upvotes: 4

Elijah Murray
Elijah Murray

Reputation: 2172

Adding on to what @subhash posted, you'll want to edit the the AndroidManifest.xml which is located here:

/projectfolder/android/app/src/main/AndroidManifest.xml, right after the opening <manifest> tag. So it should look like this:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
  package="com.projectname">

    <uses-permission android:name="android.permission.CAMERA" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

Upvotes: 0

anjaneyulubatta505
anjaneyulubatta505

Reputation: 11665

It might be problem with your permissions or node modules

1. Try adding permissions

<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

2. Remove all node modules and install again like below

npm install
react-native link

Upvotes: 0

Subhash Patel
Subhash Patel

Reputation: 674

I solve this issue by add permission in AndroidManifest.xml.

<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

Upvotes: 3

chiquyet
chiquyet

Reputation: 537

Have you done this step? http://prntscr.com/hftojg I was having trouble with that, and turned out it was permission was not provided.

One more advice when you install react-native-image-picker . You should install it manually. I don't see that automatically work well.

Hope it can help you.

Upvotes: -2

Sumanth U
Sumanth U

Reputation: 144

It might be the camera permission issue. Make sure that you have given permissions for camera, microphone and gallery and this might solve your issue.

Upvotes: 1

Related Questions