-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(Android): Don't show camera options for a file upload when they c…
…an not be used (#1210) * Don't show camera options for a file upload that would result in nothing happening for the user. On Android, if the application declares the camera permission, then even intents that use the camera require permission to be granted. This is a problem for apps that combine an in-app camera with a WebView that has file uploading and the user has not given permission for the camera. Note, this will not request permission for camera. This will simply prevent showing the camera options that would be a no-op action for users. It does this by checking if the camera permission is declared, and if so, checks that the user has granted permission. More information: https://blog.egorand.me/taking-photos-not-so-simply-how-i-got-bitten-by-action_image_capture/ * Add example and documentation about camera option availability in file uploads for Android.
- Loading branch information
Showing
5 changed files
with
118 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import React, {Component} from 'react'; | ||
import {Button, Linking, Text, View} from 'react-native'; | ||
|
||
import WebView from 'react-native-webview'; | ||
|
||
const HTML = ` | ||
<!DOCTYPE html>\n | ||
<html> | ||
<head> | ||
<title>Uploads</title> | ||
<meta http-equiv="content-type" content="text/html; charset=utf-8"> | ||
<meta name="viewport" content="width=320, user-scalable=no"> | ||
<style type="text/css"> | ||
body { | ||
margin: 0; | ||
padding: 0; | ||
font: 62.5% arial, sans-serif; | ||
background: #ccc; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<p> | ||
<label for="images-only">Images only file upload</label> | ||
<input name="images-only" type="file" accept="image/*"> | ||
</p> | ||
<p> | ||
<label for="video-only">Video only file upload</label> | ||
<input name="video-only" type="file" accept="video/*"> | ||
</p> | ||
<p> | ||
<label for="any-file">Any file upload</label> | ||
<input name="any-file" type="file"> | ||
</p> | ||
</body> | ||
</html> | ||
`; | ||
|
||
type Props = {}; | ||
type State = {}; | ||
|
||
export default class Uploads extends Component<Props, State> { | ||
state = {}; | ||
|
||
render() { | ||
return ( | ||
<View> | ||
<View style={{ height: 120 }}> | ||
<WebView | ||
source={{html: HTML}} | ||
automaticallyAdjustContentInsets={false} | ||
/> | ||
</View> | ||
<Text> | ||
Android limitation: If the file input should show camera options for the user, | ||
and the app has the ability to request the camera permission, then the user must | ||
grant permission first in order to see the options. Since this example app does | ||
have the permission declared, you must allow it in settings to be able to see | ||
camera options. If your app does not have the camera permission declared, then | ||
there is no restriction to showing the camera options. | ||
</Text> | ||
<Button | ||
title="Open settings" | ||
onPress={() => Linking.openSettings()} | ||
/> | ||
</View> | ||
); | ||
} | ||
} |