jiangdongguo / AndroidUSBCamera

🔥🔥🔥Flexible and useful UVC camera engine on Android platform, supporting multi-road cameras!
https://juejin.cn/post/7115229806844706847
Apache License 2.0
2.35k stars 802 forks source link

take picture and record video do not work #343

Closed HM-Houda closed 2 years ago

HM-Houda commented 3 years ago

Hi everyone, I've just cloned the projet and compiled it. I generated a signed apk, however after installation on smartphone with Android 9. I can view camera but the options of take picture and recording don't work.

Any help would be appreciated. Thank you very much

deebashd commented 3 years ago

@HM-Houda I too have the same issue, did you found any solution?

HM-Houda commented 3 years ago

Unfortunately, No


-- Houda MAAMATOU |Ingénieure R&D LOGIROAD 5, rue de l'Enclose 44118 La Chevrolière @.*** Tel: 07 81 53 25 77 vidéo [6]

Le 2021-10-26 14:35, deebashd a écrit :

@HM-Houda [1] I too have the same issue, did you found any solution?

-- You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub [2], or unsubscribe [3]. Triage notifications on the go with GitHub Mobile for iOS [4] or Android [5].

Links:

[1] https://github.com/HM-Houda [2] https://github.com/jiangdongguo/AndroidUSBCamera/issues/343#issuecomment-951894668 [3] https://github.com/notifications/unsubscribe-auth/AL3TWOZ7Q7AL47VQXIKOPH3UI2N7VANCNFSM5CBWBO2Q [4] https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 [5] https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub [6] https://drive.google.com/open?id=1Nysc4E17Qgk2I2h3uATcNr2lFh5pIIV4

deebashd commented 3 years ago

@HM-Houda

I found the solution, import the library as module and edit the file com.serenegiant.usb.common.AbstractUVCCameraHandler > Line No 371

Instead of case MSG_CAPTURE_STILL: //thread.handleCaptureStill((String)msg.obj); thread.handleStillPicture((String) msg.obj); break;

replace with case MSG_CAPTURE_STILL: thread.handleCaptureStill((String)msg.obj); //thread.handleStillPicture((String) msg.obj); break;

ashrafulislamdolon commented 2 years ago

can u please tell me how to work with this code in a higher version(11/12) of android? The app does open on an android 11 device but the screen remains black.

deebashd commented 2 years ago

@ashrafulislamdolon Right now Android 11 and 12 is not supporting requestPermission method, so it won't work when your targetsdk is 30 and above. Set your targetsdk to less than 30, requestPermission will work.

Note: If your targetsdk is less than 30, you can't update or deploy your app in Google Playstore from November 1, 2021. If you really want to give USB camera feature to your users, you have to ask them download from your website not from Playstore.

In Android forum, they mentioned about deploying fix in Android 12, but it's not rolled out yet.

ashrafulislamdolon commented 2 years ago

@deebashd with the current setting, the app opens in android 11 devices and it also connects to the camera but the screen remains black..how to solve this problem?? please help me

ashrafulislamdolon commented 2 years ago

@deebashd hello..can u help me please??

ashrafulislamdolon commented 2 years ago

@HM-Houda the app opens in android 11 but no preview is available..have you faced this problem??

deebashd commented 2 years ago

@ashrafulislamdolon App will open without any problem, but you can't request permission when your app targets SDK 30 and above. Without permission, nothing will work. You can decrease the target SDK but you can't update the app to PlayStore instead you can make your user download APK directly from your website.

ashrafulislamdolon commented 2 years ago

@deebashd this is the current setting- androidXVersion = '1.1.0' versionCompiler = 28 // when target=27, 9.0 is ok versionTarget = 27 // if hope supporting 4.4 // please modify it to 16 minSdkVersion = 16 versionCode = 101 versionNameString = '2.3.6.20211117' javaSourceCompatibility = JavaVersion.VERSION_1_8 javaTargetCompatibility = JavaVersion.VERSION_1_8

I can install and open this app in android 11 device but the camera preview is unavailable..

deebashd commented 2 years ago

When you connect the USB camera to your phone running Android 11, does the phone pops up Permission request dialog automatically? And it should open your app automatically too.

  1. If it is happening and still you're getting black screen after giving permission, there might be problem in your code.
  2. If no permission dialog pops up then that's the same problem I mentioned above.

And also please share your manifest.

ashrafulislamdolon commented 2 years ago

@deebashd yes, a permission request pops up when I connect the camera.

here is the manifest file-

<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.jiangdg.usbcamera">

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

<uses-feature android:name="android.hardware.usb.host"/>

<application
    android:name=".application.MyApplication"
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <activity android:name="com.jiangdg.usbcamera.view.SplashActivity"
        android:screenOrientation="portrait">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

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

    <activity android:name=".view.USBCameraActivity"
        android:screenOrientation="portrait">
        <intent-filter>
            <action android:name="android.intent.action.VIEW"/>
        </intent-filter>
    </activity>
</application>

ashrafulislamdolon commented 2 years ago

I am using the same code given here-

https://github.com/jiangdongguo/AndroidUSBCamera

deebashd commented 2 years ago
<activity android:name=".camera.MainActivity">
            <intent-filter>
                <action android:name="android.hardware.usb.action.USB_ACCESSORY_ATTACHED" />
                <action android:name="android.hardware.usb.action.USB_ACCESSORY_DETACHED" />
            </intent-filter>
            <meta-data
                android:name="android.hardware.usb.action.USB_ACCESSORY_ATTACHED"
                android:resource="@xml/accessory_filter" />
</activity>

Add the above lines in your manifest and replace the activity name. This will open up your app when USB camera is connected to your Phone. Uninstall if any other USB camera apps in your phone.

You can remove meta-data of accessory_filter if you don't know the manufacturer or model related data. accessory_filter.xml

<!--?xml version="1.0" encoding="utf-8"?-->
<resources>
    <usb-accessory manufacturer="vonchenchen" model="android.usbaoa" version="0.1"></usb-accessory>
</resources>
ashrafulislamdolon commented 2 years ago

hello @deebashd

I tried what u said, but still facing the same old problem. the app shows no preview of the camera even though it connects. I've added the screenshots, please have a look PhotoGrid_Site_1638681527849 .

deebashd commented 2 years ago

Sorry, I can't suggest further, the problem might be in the code. For me, it's working good in Android 10 & 11. Please ask this in StackOverflow.

ashrafulislamdolon commented 2 years ago

@deebashd can you share your full code please?

ashrafulislamdolon commented 2 years ago

@deebashd maybe I found the problem..the code works with the devices that have Level 3 camera2 API support can u tell me how to make it work with Full/Limited Camera2 API support?

deebashd commented 2 years ago

@ashrafulislamdolon Sorry, I can't share the code. Please ask code related question in StackOverflow

jiangdongguo commented 2 years ago

Please update to new (3.0), and have a try.