On Android 12 or higher Ble cannot scan. My android.manifest is below:
<uses-permission android:name="android.permission.BLUETOOTH" android:maxSdkVersion="30" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" android:maxSdkVersion="30" />
<uses-permission android:name="android.permission.BLUETOOTH_SCAN"/>
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT"/>
<uses-permission android:name="android.permission.BLUETOOTH_ADVERTISE"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
and my run-time ble permission is below:
try {
const granted = await PermissionsAndroid.request(
PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION,
);
if (granted === PermissionsAndroid.RESULTS.GRANTED) {
console.log('You can use location');
SetPermission(true);
osVer > 11 && blePermissionAndroid();
} else {
console.log('Location permission denied');
SetPermission(false);
}
} catch (err) {
console.warn(err);
}
async function blePermissionAndroid() {
try {
const granted = await PermissionsAndroid.request(
PermissionsAndroid.PERMISSIONS.BLUETOOTH_SCAN,
);
if (granted === PermissionsAndroid.RESULTS.GRANTED) {
console.log('You can use ble');
SetPermission(true);
} else {
console.log('ble permission denied');
SetPermission(false);
}
} catch (err) {
console.warn(err);
}
}
Finally i get this error on Android 12 and higher version:
"error XXX BleError: Unknown error occurred. This is probably a bug! Check reason property."
How can i work ble scan on Android 12 and higher.
Below Android 12 ble scan works
Related
I have used react-native-image-picker in my project. It is working fine in android phones that are less than Android 11 but App crashes in android 11 without showing logcat. launchImageLibrary is working as expected but launchCamera is crashing app. I have added the permissions also in android manifest file i.e
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
but still no luck.
I fixed it by adding await in launchImageLibrary/launchCamera
I have added the code for your reference
const openCamera = async () => {
let options = { quality: 5, maxWidth: 500, maxHeight: 500, includeBase64: true, mediaType: 'photo', noData: true, };
await launchCamera(options, response => {
if (response.didCancel) {
console.log('Cancelled');
} else if (response.error) {
console.log('Error', response.errorMessage);
} else {
console.log(response);
setFilePath(response.uri);
setBase64('data:image/png;base64,' + response.base64); } });
};
try to remove
<uses-permission android:name="android.permission.CAMERA" />
Image-picker don't need permission
This is the function that asks for permission and it logs to the console: never_ask_again automatically
requestCameraPermission = async () => {
try {
const granted = await PermissionsAndroid.request(
PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION,
{
title: "Cool Photo App Camera Permission",
message:
"Cool Photo App needs access to your camera " +
"so you can take awesome pictures.",
buttonNeutral: "Ask Me Later",
buttonNegative: "Cancel",
buttonPositive: "OK"
}
);
console.log(await
PermissionsAndroid.request(PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION))
} catch (err) {
console.warn(err);
}
};
this is my androidManifest.xml
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET" />
Can I do something to restrict a user to upload a video of duration more than 300 seconds? Either the bigger videos should be trimmed to 300s or the videos more than 300s should be disabled. I use durationLimit prop which is not working for android. I have used the following versions of this library:
"react-native-image-picker": "^2.3.4"
Then
"react-native-image-picker": "^3.5.0",
Then
"react-native-image-picker": "^4.0.2",
Neither working for me
import ImagePicker from "react-native-image-picker";
const uploadVideo = async () => {
activateKeepAwake();
let options = {
title: "Select video",
takePhotoButtonTitle: null,
mediaType: "video",
path: "video",
quality: 1,
videoQuality: "normal",
durationLimit: 300,
allowsEditing: true,
};
ImagePicker.showImagePicker(options, async (response) => {
if (response.didCancel) {
console.log("User cancelled image picker");
} else if (response.error) {
console.log("ImagePicker Error: ", response.error);
} else if (response.customButton) {
console.log("User tapped custom button: ", response.customButton);
} else {
if (response && response.uri) {
let selectedUri;
let videoFilePath;
let selectedFileUri = response.uri;
setVideoLoader(true);
setModalAddVisible(false);
if (
Platform.OS === "ios" &&
(selectedFileUri.includes(".mov") ||
selectedFileUri.includes(".MOV"))
) {
videoFilePath = await handleConvertToMP4(selectedFileUri);
selectedUri = "file://" + videoFilePath.path;
} else {
selectedUri =
Platform.os === "ios"
? selectedFileUri
: "file://" + response.path;
}
setVideoSource(null);
setVideoSource(selectedUri);
await createThumbnailForVideos(selectedUri, 1);
var filename = selectedUri.substring(
selectedUri.lastIndexOf("/") + 1,
selectedUri.length
);
const file = {
uri: selectedUri,
name: selectedGroup.id + "-dev-" + filename,
};
uploadVideoOnS3(file, "video");
}
}
});
};
Here are my android permissions:
<uses-permission android:name="android.permission.INTERNET" />
<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"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
According to the official documentation, the durationLimit prop works for already recorded video but not for live recording the video. Reference: https://github.com/react-native-image-picker/react-native-image-picker/issues/1738
I'm using react-native-firebase and react-native-document-picker and I'm trying to follow the face detection tutorial.
Currently getting the following error despite having read access through PermissionsAndroid:
Permission Denial: reading com.android.provides.media.MediaDocumentsProvider uri [uri] from pid=4746, uid=10135 requires that you obtain access using ACTION_OPEN_DOCUMENT or related APIs
I am able to display the selected image by the user on the screen but the react-native-firebase functions seems to not be able to have permission. The error happens at this call: const faces = await vision().faceDetectorProcessImage(localPath);.
Any suggestions on how to give the face detection function access or what am I doing wrong?
My AndroidManifest.xml file contains the following:
<uses-permission android:name="android.permission.INTERNET" />
<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" />
Here is all the code in that component for reference:
import React, {useState} from 'react';
import { Button, Text, Image, PermissionsAndroid } from 'react-native';
import vision, { VisionFaceContourType } from '#react-native-firebase/ml-vision';
import DocumentPicker from 'react-native-document-picker';
async function processFaces(localPath) {
console.log(localPath)
const faces = await vision().faceDetectorProcessImage(localPath);
console.log("Got faces")
faces.forEach(face => {
console.log('Head rotation on Y axis: ', face.headEulerAngleY);
console.log('Head rotation on Z axis: ', face.headEulerAngleZ);
console.log('Left eye open probability: ', face.leftEyeOpenProbability);
console.log('Right eye open probability: ', face.rightEyeOpenProbability);
console.log('Smiling probability: ', face.smilingProbability);
face.faceContours.forEach(contour => {
if (contour.type === VisionFaceContourType.FACE) {
console.log('Face outline points: ', contour.points);
}
});
});
}
async function pickFile () {
// Pick a single file
try {
const res = await DocumentPicker.pick({
type: [DocumentPicker.types.images],
});
console.log(
res.uri,
res.type, // mime type
res.name,
res.size
);
return res
} catch (err) {
if (DocumentPicker.isCancel(err)) {
// User cancelled the picker, exit any dialogs or menus and move on
console.log("User cancelled")
} else {
console.log("Error picking file or processing faces")
throw err;
}
}
}
const requestPermission = async () => {
try {
const granted = await PermissionsAndroid.request(
PermissionsAndroid.PERMISSIONS.READ_EXTERNAL_STORAGE,
{
title: "Files Permission",
message:
"App needs access to your files " +
"so you can run face detection.",
buttonNeutral: "Ask Me Later",
buttonNegative: "Cancel",
buttonPositive: "OK"
}
);
if (granted === PermissionsAndroid.RESULTS.GRANTED) {
console.log("We can now read files");
} else {
console.log("File read permission denied");
}
return granted
} catch (err) {
console.warn(err);
}
};
function FaceDetectionScreen ({navigation}) {
const [image, setImage] = useState("");
return (
<>
<Text>This is the Face detection screen.</Text>
<Button title="Select Image to detect faces" onPress={async () => {
const permission = await requestPermission();
if (permission === PermissionsAndroid.RESULTS.GRANTED) {
const pickedImage = await pickFile();
const pickedImageUri = pickedImage.uri
setImage(pickedImageUri);
processFaces(pickedImageUri).then(() => console.log('Finished processing file.'));
}
}}/>
<Image style={{flex: 1}} source={{ uri: image}}/>
</>
);
}
export default FaceDetectionScreen;
Thanks to this comment on a github issue I was able to update my code and get it to work by updating the first three lines of processFaces as:
async function processFaces(contentUri) {
const stat = await RNFetchBlob.fs.stat(contentUri)
const faces = await vision().faceDetectorProcessImage(stat.path);
after importing import RNFetchBlob from 'rn-fetch-blob'.
rn-fetch-blob
Error: Looks like the app doesn't have the permission to access location. Add the following line to your app's AndroidManifest.xml
Even though I have added the permissions in manifest.xml and asking for runtime permissions I cannot access GPS.
My AndroidManifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.location">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
.....
.....
complete code:
import React, { Component } from 'react';
import { Platform, StyleSheet, Text, View,
PermissionsAndroid } from 'react-native';
export default class App extends Component {
async requestLocationPermission() {
try {
const granted = await PermissionsAndroid.request(
PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION,
{
'title': 'Location Access Permission',
'message': 'Expensify would like to use your location ' +
'so you we track you.'
}
)
if (granted === PermissionsAndroid.RESULTS.GRANTED) {
console.log("You can use the location")
} else {
console.log("Location permission denied")
}
} catch (err) {
console.warn(err)
}
}
componentDidMount() {
console.log("compdidmount");
this.requestLocationPermission();
//Crashes here on getCurrentPosition
navigator.geolocation.getCurrentPosition(
(position) => {
console.log(position.coords.latitude);
},
(error) => {
console.log(error)
},
{enableHighAccuracy: true, timeout: 20000, maximumAge: 10000}
);
}
render() {
return (
<View style>
<Text style>
Tracking App
</Text>
</View>
);
}
}
I got the same issue with the CameraRoll. I fixed this asking for permission when the app starts. You should use this :
import { PermissionsAndroid } from 'react-native';
async function requestCameraPermission() {
try {
const granted = await PermissionsAndroid.request(
PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION,
{
'title': 'Location Permission',
'message': 'Location Permission' +
'so you can use GPS location.'
}
)
if (granted === PermissionsAndroid.RESULTS.GRANTED) {
console.log("You can use GPS")
} else {
console.log("GPS location denied")
}
} catch (err) {
console.warn(err)
}
}
I solved this problem by deleting and reinstalling the application.