Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot use file input to capture image #88

Open
jbennett opened this issue Jan 18, 2025 · 4 comments
Open

Cannot use file input to capture image #88

jbennett opened this issue Jan 18, 2025 · 4 comments

Comments

@jbennett
Copy link

jbennett commented Jan 18, 2025

I'm using <input type="file" accepts="image/*" capture /> which works perfectly on web and iOS, and for the photo gallery on Android, but for camera captures on Android it looks like Hotwire is restarting my MainActivity and I'm loosing state, almost like the page is reloading. Additionally, this works fine on an emulator, just not on device.

For debugging purposes I've tried this on a new project, just adding camera and file writing permissions to the manifest with the same results.

Any suggestions?

Edit: Added a minimal sample repo that demonstrates the issue: https://github.com/jbennett/hotwire-native-file-input

@williamkennedy
Copy link

I was able to replicate your problem, and I updated the file input field to the following:

<input accept="image/*" capture="environment" type="file" >

Try adding capture="environment" and you should get a dialog like so.

Image

Let me know if that works and here is some handy info about media capture that I was able to find.

https://addpipe.com/html-media-capture-demo/

@jbennett
Copy link
Author

Out of curiosity, are you doing this on hardware? In the emulator it is working right.

I've tried the following <input> and I do get the camera option for all of them. The file picker intent is added if you have image/jpg or image/* automatically. It's the relauching of the activity specifically that is causing the issue I think

<input type="file" name="foo" accept="image/*" />
<input type="file" name="foo" accept="image/*" capture />
<input type="file" name="foo" accept="image/*" capture="false" />
<input type="file" name="foo" accept="image/*" capture="user" />
<input type="file" name="foo" accept="image/*" capture="environment" />

@jayohms
Copy link
Contributor

jayohms commented Jan 21, 2025

Does adding a launchMode in your manifest change the behavior:

AndroidManifest.xml

 <activity
     android:name=".MainActivity"
     android:exported="true">
+    android:launchMode="singleTask" 
     <intent-filter>
         <action android:name="android.intent.action.MAIN" />
         <category android:name="android.intent.category.LAUNCHER" />
     </intent-filter> 
 </activity>

This will ensure that a single instance of MainActivity is (re)used if it's already running when an Intent from an image selection

@jbennett
Copy link
Author

Yup, I've tried that too. Are you seeing the same issue if you run the test project on hardware?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants