I have a QR code scanner function that does not open the camera. The scanner screen appears but I do not see the box with the line inside for scanning.
I have also added camera permissions in the Android manifest
Android Manifest Permissions
<uses-permission android:name="android.permission.CAMERA"/>
<uses-feature android:name="android.hardware.camera"
android:required="false"/>
<uses-feature android:name="android.hardware.camera.autofocus" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
The Scanner Function is below
Future <void> scanqr() async {
final qrCode = await scanner.scan();
setState(() {
this.qrCode = qrCode;
});
}
Related
I have created below method to check the location permission status in my flutter application:
Future<void> checkLocationPermission(
BuildContext context, UserCredential userCredential) async {
locationPermissionStatus = await permission_status.Permission.location
.request()
.then((value) async {
if (locationPermissionStatus.isGranted) {
displayToast("granted");
await getCurrentLocation(context, userCredential);
} else {
displayToast("not granted");
}
return locationPermissionStatus;
});
}
Where, PermissionStatus is declared as below:
permission_status.PermissionStatus locationPermissionStatus =
permission_status.PermissionStatus.denied;
Imports as below:
import 'package:location/location.dart';
import 'package:permission_handler/permission_handler.dart' as permission_status;
Used below plugins:
permission_handler: ^10.2.0
location: ^4.4.0
But In App, When Location Permission pops up, I am tapping on option "While Using the App"
But I am always getting the toast display as "not granted"
What might be the issue? Thanks in Advance.
EDIT:
Already added below permissions for Android:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mypackage">
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.CAMERA"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
</manifest>
Adding to the #Romil Mavani answer, you first have to add permissions in AndroidManifest:
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
But it also seems that you are using async/await with the combination of then which is very error-prone. You should either use one or the other.
Future<void> checkLocationPermission(
BuildContext context, UserCredential userCredential) async {
locationPermissionStatus =
await permission_status.Permission.location.request();
if (locationPermissionStatus.isGranted) {
displayToast("granted");
await getCurrentLocation(context, userCredential);
} else {
displayToast("not granted");
}
}
You have to add permission in manifest.
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
Like this : https://i.stack.imgur.com/PgdNF.png
Also permission status is not working correctly for only location permission so you have check and request permission using location package and it will works fine.
I Hope this things are solve your issue.
If you're using a Windows Emulator
I've faced the same issue before, but when I opened the application setting of my mobile's emulator to confirm, the location permission was not granted (off).
So, I granted it manually from the app settings.
Emulator: Setting/apps/allApps/myApp/permisson
This solution works for me.
i was trying to make upload features, so users can upload file into firebase account
in the past, it run well, but yesterday, it wont show the files
there is the code
uploadImage() async {
final storage = FirebaseStorage.instance;
final picker = ImagePicker();
PickedFile? image;
//Check Permissions
await Permission.photos.request();
var permissionStatus = await Permission.photos.status;
if (permissionStatus.isGranted) {
//Select Image
image = await picker.getImage(source: ImageSource.gallery);
var file = File(image!.path);
final fileName = basename(file.path);
final destination = 'user/$emaila/identitas/$fileName';
if (image != null) {
//Upload to Firebase
var snapshot = await storage
.ref()
.child(destination)
.putFile(file)
.whenComplete(() => null);
var downloadUrl = await snapshot.ref.getDownloadURL();
setState(() {
imageUrlidentitas = downloadUrl;
});
} else {
print('No Path Received');
}
} else {
print('Grant Permissions and try again');
}
}
here is android manifest
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.rekammedis">
<uses-permission android:name="android.permission.INTERNET"/>
<!-- Permissions options for the `storage` group -->
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_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" />
<!-- Permissions options for the `camera` group -->
<uses-permission android:name="android.permission.CAMERA"/>
<application
android:label="rekammedis"
android:name="${applicationName}"
android:icon="#mipmap/ic_launcher">
<activity
android:name=".MainActivity"
android:exported="true"
android:launchMode="singleTop"
android:theme="#style/LaunchTheme"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
android:hardwareAccelerated="true"
android:windowSoftInputMode="adjustResize">
<!-- Specifies an Android theme to apply to this Activity as soon as
the Android process has started. This theme is visible to the user
while the Flutter UI initializes. After that, this theme continues
to determine the Window background behind the Flutter UI. -->
<meta-data
android:name="io.flutter.embedding.android.NormalTheme"
android:resource="#style/NormalTheme"
/>
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<!-- Don't delete the meta-data below.
This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
<meta-data
android:name="flutterEmbedding"
android:value="2" />
</application>
</manifest>
and the compiler says
D/permissions_handler( 9318): No permissions found in manifest for: []9
D/permissions_handler( 9318): No permissions found in manifest for: []9
I/flutter ( 9318): Grant Permissions and try again
how to solve this ? anyone know ?
i try looking in stackoverflow, but none of them are explain the answer
This is a recent bug which was introduced by the new version of the permissionhandler in 10.2.0. It is discussed here https://github.com/Baseflow/flutter-permission-handler/issues/944 and I will copy the answer to this question as well. This solution was also working for me.
I've fixed this by checking for Permissions.storage.status when the device is Android 12.0 or below, else I use the Permissions.photos.status. I use the device_info_plus plugin to check the Android version:
I added the following to my AndroidManifest.kt
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"
android:maxSdkVersion="32"/>
<uses-permission android:name="android.permission.READ_MEDIA_IMAGES"/>
and in flutter:
if (Platform.isAndroid) {
final androidInfo = await DeviceInfoPlugin().androidInfo;
if (androidInfo.version.sdkInt <= 32) {
/// use [Permissions.storage.status]
} else {
/// use [Permissions.photos.status]
}
}
all credits belong to HinrikHelga on github
Check your targetSdkVersion in build.gradle file.
If you are using targetSdkVersion = 30, you will need to write storage permission in a different way. I think you can try the solution discussed in this post
I use network_info_plus plug -in to obtain WIFI information. The models of the 12th -pm can be obtained. The SSID obtained by the 12 and above models is NULL. Please help me tell me how to solve this problem.
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
Future<void> setNetwork() async {
final info = NetworkInfo();
var locationStatus = await Permission.location.status;
if (locationStatus.isDenied) {
await Permission.locationWhenInUse.request();
}
if (await Permission.location.isRestricted) {
openAppSettings();
}
if (await Permission.location.isGranted) {
var wifiName = await info.getWifiName();
log('wifiName $wifiName');
}
}
What method needs to be implemented
You can use the network_info_plus package to get all the network info wi-fi-related information.
just install it with
flutter pub add network_info_plus
And use below code snippet to get SSID 👍
var wifiBSSID = await info.getWifiBSSID(); // 11:22:33:44:55:66
Flutter/ This is my code for creating folder using pathProdiver package
note: i have set the permission in manifest file as a
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
I do not what is the real problem here, the compiler says permission is denied but i set all the permissions.
Future<String> askForPermission() async {
final folderName = "newcreatefoldr";
final path = Directory("storage/emulated/0/$folderName");
var status=await Permission.storage.status;
if(!status.isGranted){
await Permission.storage.request();
}
if(await path.exists()){
return path.path;
}else{
path.create();
return path.path;
}
}
and the error saying ....
E/flutter (24174): [ERROR:flutter/lib/ui/ui_dart_state.cc(198)] Unhandled Exception: FileSystemException: Creation failed, path = 'storage/emulated/0/newcreatefoldr' (OS Error: Operation not permitted, errno = 1)
for more detailed this is my manifest file
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.cameraapp">
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<application
android:label="cameraapp"
android:name="${applicationName}"
android:icon="#mipmap/ic_launcher">
<activity
android:name=".MainActivity"
android:exported="true"
android:launchMode="singleTop"
android:theme="#style/LaunchTheme"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
android:hardwareAccelerated="true"
android:windowSoftInputMode="adjustResize">
<!-- Specifies an Android theme to apply to this Activity as soon as
the Android process has started. This theme is visible to the user
while the Flutter UI initializes. After that, this theme continues
to determine the Window background behind the Flutter UI. -->
<meta-data
android:name="io.flutter.embedding.android.NormalTheme"
android:resource="#style/NormalTheme"
/>
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<!-- Don't delete the meta-data below.
This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
<meta-data
android:name="flutterEmbedding"
android:value="2" />
</application>
</manifest>
I solved this problem with the following solutions: For android 10/Q, I have added this permission in the androidManifest.xml:
<uses-permission android:name="android.permission.ACCESS_MEDIA_LOCATION"/>
and add this line in application tag:
android:requestLegacyExternalStorage="true"
like this:
<application
...
android:requestLegacyExternalStorage="true">
For android 11/R, add this permission:
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE"
tools:ignore="ScopedStorage" />
In app-user permission handler I'm checking permissions with the following function:
Future<bool> _hasAcceptedPermissions() async {
if (Platform.isAndroid) {
if (await _requestPermission(Permission.storage) &&
// access media location needed for android 10/Q
await _requestPermission(Permission.accessMediaLocation) &&
// manage external storage needed for android 11/R
await _requestPermission(Permission.manageExternalStorage)) {
return true;
} else {
return false;
}
}
if (Platform.isIOS) {
if (await _requestPermission(Permission.photos)) {
return true;
} else {
return false;
}
} else {
// not android or ios
return false;
}}
im using permission_handle to take permission for location.
and it always saying "No permissions found in manifest"
even i tried "flutter clean"
import 'package:permission_handler/permission_handler.dart';
class PermissionsService {
final PermissionHandler _permissionHandler = PermissionHandler();
Future<bool> _requestPermission(PermissionGroup permission) async {
var result = await _permissionHandler.requestPermissions([permission]);
if (result[permission] == PermissionStatus.granted) {
print('innnn');
return true;
}
return false;
}
Future<bool> requestLocationPermission({Function onPermissionDenied} ) async {
// return _requestPermission(PermissionGroup.locationWhenInUse);
var granted = await _requestPermission(PermissionGroup.location );
if(!granted){
onPermissionDenied();
}
return granted;
}
}
my Manifest.xml file
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.artistry">
<!-- Flutter needs it to communicate with the running application
to allow setting breakpoints, to provide hot reload, etc.
-->
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.INTERNET"/>
</manifest>
You added permission in the Wrong Manifest File, You have to add location permission inside Android Manifest of this Directory android\app\src\main\AndroidManifest
You need to set permissions in main AndroidManifest.xml.
There are three folders debug, main and profile.
Run flutter clean.
See my example:
.../main/AndoridManifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="test.packange.name">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<!-- io.flutter.app.FlutterApplication is an android.app.Application that
calls FlutterMain.startInitialization(this); in its onCreate method.
In most cases you can leave this as-is, but you if you want to provide
additional functionality it is fine to subclass or reimplement
FlutterApplication and put your custom class here. -->
<application
android:name="io.flutter.app.FlutterApplication"
android:label="Test app"
android:icon="#mipmap/ic_launcher"
android:roundIcon="#mipmap/ic_launcher_round">
<activity
android:name="test.packange.name.MainActivity"
android:launchMode="singleTop"
android:theme="#style/LaunchTheme"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
android:hardwareAccelerated="true"
android:windowSoftInputMode="adjustResize">
<!-- This keeps the window background of the activity showing
until Flutter renders its first frame. It can be removed if
there is no splash screen (such as the default splash screen
defined in #style/LaunchTheme). -->
<meta-data
android:name="io.flutter.app.android.SplashScreenUntilFirstFrame"
android:value="true" />
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
</manifest>
main.dart
Future<void> requestPermission(PermissionGroup permission) async {
final List<PermissionGroup> permissions = <PermissionGroup>[permission];
final Map<PermissionGroup, PermissionStatus> permissionRequestResult =
await PermissionHandler().requestPermissions(permissions);
print(permissionRequestResult);
_permissionStatus = permissionRequestResult[permission];
if (_permissionStatus == PermissionStatus.granted) {
initLocationStreamer();
}
print(_permissionStatus);
}
Update plugin https://github.com/Baseflow/flutter-permission-handler. See example and issues.