maitrungduc1410 / react-native-video-trim

Video trimmer for React Native App
MIT License
37 stars 14 forks source link

Android Permission issue #10

Closed sanketappsimity closed 5 months ago

sanketappsimity commented 8 months ago

Hi Team

i am getting Android Permission issue

[Error: Camera permission denied]

Even all permission are granted

here is my project version info pls check and suggest me some solution

System: OS: macOS 13.4 CPU: (8) arm64 Apple M1 Pro Memory: 307.36 MB / 16.00 GB Shell: 5.9 - /bin/zsh Binaries: Node: 16.15.0 - ~/.nvm/versions/node/v16.15.0/bin/node Yarn: 1.22.18 - /opt/homebrew/bin/yarn npm: 8.5.5 - ~/.nvm/versions/node/v16.15.0/bin/npm Watchman: 2023.07.03.00 - /opt/homebrew/bin/watchman Managers: CocoaPods: 1.12.1 - /opt/homebrew/bin/pod SDKs: iOS SDK: Platforms: DriverKit 22.2, iOS 16.2, macOS 13.1, tvOS 16.1, watchOS 9.1 Android SDK: API Levels: 29, 30, 31, 32, 33 Build Tools: 29.0.2, 30.0.0, 30.0.1, 30.0.2, 30.0.3, 33.0.1 System Images: android-30 | Google Play ARM 64 v8a, android-32 | Google APIs ARM 64 v8a Android NDK: Not Found IDEs: Android Studio: 2021.1 AI-211.7628.21.2111.8309675 Xcode: 14.2/14C18 - /usr/bin/xcodebuild Languages: Java: 11.0.14.1 - /usr/bin/javac npmPackages: @react-native-community/cli: Not Found react: 16.11.0 => 16.11.0 react-native: 0.62.1 => 0.62.1 react-native-macos: Not Found npmGlobalPackages: react-native: Not Found

Looking for resolution Thanks
maitrungduc1410 commented 8 months ago

Can you try remove the app, run-android again, and when it pops up to ask for permission, you need to press Yes (Agree)

sanketappsimity commented 8 months ago

i already did it couple of times i am using Android One Plus Nord 2T Android 13

and i searched about it And as Google is saying no need for permission So i am confuse What to do with It

Thank You So much!!

maitrungduc1410 commented 8 months ago

do you have <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> in android/app/src/main/AndroidManifest.xml?

shiyansiva commented 8 months ago

@maitrungduc1410 Already I have added that line in manifest still facing that issue , I believe Android 13 doesn't require that permission. Please verify by checking this Link

sanketappsimity commented 8 months ago

do you have <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> in android/app/src/main/AndroidManifest.xml?

Yes i already checked let me past my AndroidManifest here

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

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />

<uses-permission-sdk-23 android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission-sdk-23 android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_MEDIA_IMAGES" />
<uses-permission android:name="android.permission.READ_MEDIA_VIDEO" />
<uses-permission android:name="android.permission.READ_MEDIA_AUDIO" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"  tools:node="replace"/>
 <!-- <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> -->
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<application
    android:largeHeap="true" 
    android:hardwareAccelerated="true"
    android:requestLegacyExternalStorage="true"
    android:extractNativeLibs="true"
    android:usesCleartextTraffic="true"
    android:name="com.realityapp.MainApplication"
    android:label="@string/app_name"
    android:icon="@mipmap/ic_launcher"
    android:roundIcon="@mipmap/ic_launcher"
    android:allowBackup="false"
    android:exported="true"
    android:theme="@style/AppTheme">
     <meta-data
        android:name="com.google.android.geo.API_KEY"
        android:value="AIzaSyB9IxJZ5hBu9jPEnIbViSgei8K1o-0NIKQ"/>
     <meta-data android:name="com.facebook.sdk.AutoLogAppEventsEnabled" android:value="true"/>

    <meta-data
        android:name="com.facebook.sdk.ApplicationId"
        android:value="@string/facebook_app_id" />
    <!-- <meta-data
        android:name="com.google.android.geo.API_KEY"
        android:value="@string/google_maps_api" /> -->

    <activity
        android:name=".MainActivity"
        android:exported="true"
        android:label="@string/app_name"
        android:screenOrientation="portrait"
        android:configChanges="keyboard|keyboardHidden|orientation|screenSize|uiMode"
        android:launchMode="standard"
        android:windowSoftInputMode="adjustPan"
        >

        <tools:validation testUrl="https://smartapp.onelink.me/profile" />

        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.LAUNCHER" />
            <data android:host="https://realityapp.page.link" android:scheme="http"/>
            <data android:host="https://realityapp.page.link" android:scheme="https"/>
        </intent-filter>

         <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.LAUNCHER" />
            <data android:host="smartrealty.page.link" android:scheme="http"/>
            <data android:host="smartrealty.page.link" android:scheme="https"/>
        </intent-filter>
          <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.LAUNCHER" />
            <data android:host="smartsuperapplication.page.link" android:scheme="http"/>
            <data android:host="smartsuperapplication.page.link" android:scheme="https"/>
             <data android:host="smartsuperapplication.com" android:scheme="http"/>
            <data android:host="smartsuperapplication.com" android:scheme="https"/>
        </intent-filter>

         <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
       </intent-filter>
        <intent-filter android:autoVerify="true">
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE" />
            <data android:scheme="http" android:host="smartapp.onelink.me" android:pathPrefix="/profile" />
            <data android:scheme="https" android:host="smartapp.onelink.me" />
        </intent-filter>

         <intent-filter>
        <action android:name="android.intent.action.MAIN" />

        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
    <intent-filter>
        <action android:name="android.intent.action.VIEW" />

        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.BROWSABLE" />

        <!-- <data
            android:host="smartsuperapplication.com"
            android:scheme="http" />
        <data
            android:host="smartsuperapplication.com"
            android:scheme="https" /> -->
            <data android:host="smartsuperapplication.com"/>
            <data android:scheme="http"/>
            <data android:scheme="https"/>
    </intent-filter>
    </activity>
    <activity android:name="com.facebook.react.devsupport.DevSettingsActivity" android:exported="false" />

    </receiver>

    <service
        android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationListenerService"
        android:exported="false">
        <intent-filter>
            <action android:name="com.google.firebase.MESSAGING_EVENT" />
        </intent-filter>
    </service>

</application>

maitrungduc1410 commented 8 months ago

The error is thrown from here: https://github.com/maitrungduc1410/react-native-video-trim/blob/master/src/index.tsx#L51

You can verify by create a test function which does same as what my code does:

async function test() {
  const granted = await PermissionsAndroid.request(
    PermissionsAndroid.PERMISSIONS.WRITE_EXTERNAL_STORAGE!,
    {
      title: 'Video Trimmer Photos Access Required',
      message: 'Grant access to your Photos to write output Video',
      buttonNeutral: 'Ask Me Later',
      buttonNegative: 'Cancel',
      buttonPositive: 'OK',
    }
  );
  if (granted === PermissionsAndroid.RESULTS.GRANTED) {
    console.log('granted')
  } else {
    console.log('Camera permission denied')
  }
}

Call it and see if you're able to see 'granted', if you still see 'Camera permission denied', then definitely you miss something, because here I'm using PermissionsAndroid from react native itself

sanketappsimity commented 8 months ago

The error is thrown from here: https://github.com/maitrungduc1410/react-native-video-trim/blob/master/src/index.tsx#L51

You can verify by create a test function which does same as what my code does:

async function test() {
  const granted = await PermissionsAndroid.request(
    PermissionsAndroid.PERMISSIONS.WRITE_EXTERNAL_STORAGE!,
    {
      title: 'Video Trimmer Photos Access Required',
      message: 'Grant access to your Photos to write output Video',
      buttonNeutral: 'Ask Me Later',
      buttonNegative: 'Cancel',
      buttonPositive: 'OK',
    }
  );
  if (granted === PermissionsAndroid.RESULTS.GRANTED) {
    console.log('granted')
  } else {
    console.log('Camera permission denied')
  }
}

Call it and see if you're able to see 'granted', if you still see 'Camera permission denied', then definitely you miss something, because here I'm using PermissionsAndroid from react native itself

Yes i am also using same like that and i provided Permission Code in AndroidManifest but still its giving me permission issue and in ios i am getting file is invalid issue here is the url i am checkoing is it valid or not

ios {"extension": "video/mp4", "iosUri": "ph://189074D4-6E38-44A9-8F82-D776AECF112E/L0/001", "ischecked": false, "mainExt": "mp4", "vidType": "video", "vidUri": "assets-library://asset/asset.mp4?id=189074D4-6E38-44A9-8F82-D776AECF112E&ext=mp4", "vidfilename": "12395393_MotionElements_jungle-animals_preview.mp4"}

i am checking both :- vidUri and iosUri

that iosUri is playing in react-native-video but not working at all in my ios

And in android Permission issue is same

pls have a look on my ios Url as well why its showing video invalid i am just validating video from simulator video i know video editor will not work in. Simulator but i think video validation we can check from Simulator videos

my react-native version is 62.1 so is not it hapening due to version ??

Looking for your replay and Thanks for Support

maitrungduc1410 commented 8 months ago

Yes i am also using same like that and i provided Permission Code in AndroidManifest but still its giving me permission issue

  1. That means something is already wrong from your end, not about this lib
  2. the vidUri and iosUri look incorrect.

What I recommend you is, try to use this library: https://github.com/react-native-image-picker/react-native-image-picker. It should work, and you can also compare the filepath return from react-native-image-picker with your vidUri and iosUri

shiyansiva commented 8 months ago

@maitrungduc1410 I've been using a different image picker called "react-native-image-crop-picker": "^0.36.2" which provides file paths like 'file:///data/user/0/com.app.rtmobile/cache/react-native-image-crop-picker/1649159591.mp4.' However, when I attempted to use the image picker plugin you referred to, I encountered an error: "TypeError: null is not an object (evaluating 'nativeImagePicler.launchImageLibrary')"

sanketappsimity commented 8 months ago

@shiyansiva This is coming due to version issue as you are using 63.0 so thats the issue you are facing and i tried with new project its working but after generating video its giving 0:0 which is showing only in Gallery

so still having issue in Android to get video working after trim

shiyansiva commented 8 months ago

@sanketappsimity Yes I am using "react-native": "~0.63.4"

sanketappsimity commented 8 months ago

@shiyansiva Use this version "react-native-image-picker": "^4.0.5",

u will get fixed that issue and after that you will be able to get correct video path Thanks

shiyansiva commented 8 months ago

@sanketappsimity May I know your targetSdkVersion an compileSdkVersion

sanketappsimity commented 8 months ago

Yes its compileSdkVersion = 33 targetSdkVersion = 33

shiyansiva commented 8 months ago

Thanks @sanketappsimity will try and let you know

sanketappsimity commented 8 months ago

Yes Sure if you get working video after trim pls let me know

Thanks

shiyansiva commented 8 months ago

@sanketappsimity I'm experiencing a crash when I pass the following source URL to the showEditor() function: "content://media/picker/0/com.android.providers.media.photopicker/media/1000030916." The app crashes when attempting to handle this URL.

{"assets": [{"bitrate": 573879, "duration": 125, "fileName": "1000030916", "fileSize": 9036693, "height": 720, "type": "video/mp4", "uri": "content://media/picker/0/com.android.providers.media.photopicker/media/1000030916", "width": 960}]}

sanketappsimity commented 8 months ago

@shiyansiva Actually this is incorrect path given by this library old version and unfortunately updated version (react-native-image-picker) is not working bellow React-native 68 So you can create a New project and check But

@maitrungduc1410 There is an issue in Library which is permission issue and its not working in Android i writen native modules for permission only ref :- https://stackoverflow.com/questions/63392170/write-files-to-the-android-external-storage-using-react-native-fs But still having permission issue everything working perfectly but while trim process getting end video is not getting save in directory if change condition then its saving broken video which is useless @maitrungduc1410 This the things i found Please suggest me if i am doing something wrong it would be really helpfull

Thanks

shiyansiva commented 8 months ago

@sanketappsimity @maitrungduc1410 I'm receiving a logcat message that looks like the one below. After investigating, I verified that the video file was saved in my app's cache folder(PFA). It's possible that this 'null' value in the console output is related to our issue.

D/VideoTrimmerUtil: FFmpeg process exited with state COMPLETED and rc 0.null D/MediaScannerConnection: Scanned /storage/emulated/0/Android/data/com.example.app/cache/trimmedVideo_20230919_184537.mp4 to null

Screenshot 2023-09-19 at 6 54 47 PM

@sanketappsimity I haven't observed any console messages when I open the "showEditor." Is it functioning correctly on your end?

case 'onShow': { console.log('onShowListener', event); break; }

maitrungduc1410 commented 8 months ago

Wow, thanks guys for your active comments, you're my first-class passengers :)

I'll check all of your issues today.

In the meantime can you guys try running the Example app?

https://github.com/maitrungduc1410/react-native-video-trim/tree/master/example

It's the most basic app that I've been using to develop this lib, and it's functioning well on my end

shiyansiva commented 8 months ago

@maitrungduc1410 🙌 The example app is working good. But My personal react native app v is 0.63.4.

maitrungduc1410 commented 8 months ago

@shiyansiva is it possible for you to push your code, (simplified version, no personal/private info). With same packages you have to github and share me repo for testing?

shiyansiva commented 7 months ago

Hi @sanketappsimity Have you resolved this issue on the Android platform?

sanketappsimity commented 7 months ago

@shiyansiva Not yet bro What about your implementation ??

shiyansiva commented 7 months ago

@sanketappsimity Same issue in Android bro

sanketappsimity commented 7 months ago

@shiyansiva infact i am not able to run Example but i will look into it on Oct first week and if i got some solution i will defenetally let you know Thanks !!

shiyansiva commented 7 months ago

@shiyansiva infact i am not able to run Example but i will look into it on Oct first week and if i got some solution i will defenetally let you know Thanks !!

Thanks, bro

maitrungduc1410 commented 5 months ago

Hi Guys, found the issue: https://github.com/facebook/react-native/issues/36714

from Android SDK >= 33, we don't need to request for permission to write to external storage on android.

Please upgrade to v1.0.7. Thanks @yanghun0070 for figuring out this

shiyansiva commented 3 months ago

Hi @sanketappsimity , Have you resolved this issue on the Android?