can't run package in flutter_background_service #947
-
Versionphoto_manager: ^2.6.0 PlatformsAndroid Device Modelandroid 9 flutter infoDoctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel stable, 3.10.1, on Microsoft Windows [Version 10.0.19045.2965], locale en-US)
[√] Windows Version (Installed version of Windows is version 10 or higher)
[√] Android toolchain - develop for Android devices (Android SDK version 33.0.1)
[√] Chrome - develop for the web
[√] Visual Studio - develop for Windows (Visual Studio Community 2022 17.4.3)
[√] Android Studio (version 2021.2)
[√] VS Code (version 1.78.2)
[√] Connected device (4 available)
[!] Network resources
X A cryptographic error occurred while checking "https://pub.dev/": Connection terminated during handshake
You may be experiencing a man-in-the-middle attack, your network may be compromised, or you may have malware installed on your computer.
X A cryptographic error occurred while checking "https://maven.google.com/": Connection terminated during handshake
You may be experiencing a man-in-the-middle attack, your network may be compromised, or you may have malware installed on your computer.
! Doctor found issues in 1 category. How to reproduce?Future inittializeService() async { @pragma('vm:entry-point') Timer.periodic(Duration(seconds: 10), (timer) async {
}); LogsE/MethodChannel#com.fluttercandies/photo_manager(26512): Failed to handle method call
E/MethodChannel#com.fluttercandies/photo_manager(26512): java.lang.NullPointerException: Activity for the permission request is not exist.
E/MethodChannel#com.fluttercandies/photo_manager(26512): at com.fluttercandies.photo_manager.permission.PermissionsUtils.getPermissionsWithTips(PermissionsUtils.kt:90)
E/MethodChannel#com.fluttercandies/photo_manager(26512): at com.fluttercandies.photo_manager.permission.PermissionsUtils.getPermissions(PermissionsUtils.kt:74)
E/MethodChannel#com.fluttercandies/photo_manager(26512): at com.fluttercandies.photo_manager.core.PhotoManagerPlugin.onMethodCall(PhotoManagerPlugin.kt:226)
E/MethodChannel#com.fluttercandies/photo_manager(26512): at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:258)
E/MethodChannel#com.fluttercandies/photo_manager(26512): at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler(DartMessenger.java:295)
E/MethodChannel#com.fluttercandies/photo_manager(26512): at io.flutter.embedding.engine.dart.DartMessenger.lambda$dispatchMessageToQueue$0$io-flutter-embedding-engine-dart-DartMessenger(DartMessenger.java:322)
E/MethodChannel#com.fluttercandies/photo_manager(26512): at io.flutter.embedding.engine.dart.DartMessenger$$ExternalSyntheticLambda0.run(D8$$SyntheticClass)
E/MethodChannel#com.fluttercandies/photo_manager(26512): at android.os.Handler.handleCallback(Handler.java:751)
Launching lib\main.dart on Android SDK built for x86 in debug mode...
main.dart:1
√ Built build\app\outputs\flutter-apk\app-debug.apk.
D/flutter/CALL_LOG(26512): onAttachedToEngine
D/flutter/CALL_LOG(26512): init. Messanger:io.flutter.embedding.engine.dart.DartExecutor@3b110ed Context:android.app.Application@9da9b22
D/flutter/CALL_LOG(26512): onAttachedToActivity
D/FlutterGeolocator(26512): Attaching Geolocator to activity
D/FlutterGeolocator(26512): Creating service.
D/FlutterGeolocator(26512): Binding to location service.
D/FlutterGeolocator(26512): Geolocator foreground service connected
D/FlutterGeolocator(26512): Initializing Geolocator services
D/FlutterGeolocator(26512): Flutter engine connected. Connected engine count 1
Connecting to VM Service at ws://127.0.0.1:55639/8kaB_thv4lo=/ws
D/permissions_handler(26512): No android specific permissions needed for: 18
V/BackgroundService(26512): Starting flutter engine for background service
D/EGL_emulation(26512): eglCreateContext: 0xa6ba7860: maj 2 min 0 rcv 2
D/EGL_emulation(26512): eglCreateContext: 0xa6ba78c0: maj 2 min 0 rcv 2
D/ (26512): HostConnection::get() New Host Connection established 0x8d97edc0, tid 26603
D/EGL_emulation(26512): eglMakeCurrent: 0xa6ba78c0: ver 2 0 (tinfo 0x8dfbdb00)
D/flutter/CALL_LOG(26512): onAttachedToEngine
D/flutter/CALL_LOG(26512): init. Messanger:io.flutter.embedding.engine.dart.DartExecutor@6ab4b51 Context:android.app.Application@9da9b22
D/BackgroundServicePlugin(26512): onAttachedToService
D/FlutterGeolocator(26512): Geolocator foreground service connected
E/MethodChannel#com.fluttercandies/photo_manager(26512): at android.os.Handler.dispatchMessage(Handler.java:95)
E/MethodChannel#com.fluttercandies/photo_manager(26512): at android.os.Looper.loop(Looper.java:154)
E/MethodChannel#com.fluttercandies/photo_manager(26512): at android.app.ActivityThread.main(ActivityThread.java:6077)
E/MethodChannel#com.fluttercandies/photo_manager(26512): at java.lang.reflect.Method.invoke(Native Method)
E/MethodChannel#com.fluttercandies/photo_manager(26512): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
E/MethodChannel#com.fluttercandies/photo_manager(26512): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:756)
E/flutter (26512): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: PlatformException(error, Activity for the permission request is not exist., null, java.lang.NullPointerException: Activity for the permission request is not exist.
E/flutter (26512): at com.fluttercandies.photo_manager.permission.PermissionsUtils.getPermissionsWithTips(PermissionsUtils.kt:90)
E/flutter (26512): at com.fluttercandies.photo_manager.permission.PermissionsUtils.getPermissions(PermissionsUtils.kt:74)
E/flutter (26512): at com.fluttercandies.photo_manager.core.PhotoManagerPlugin.onMethodCall(PhotoManagerPlugin.kt:226)
E/flutter (26512): at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:258)
E/flutter (26512): at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler(DartMessenger.java:295)
E/flutter (26512): at io.flutter.embedding.engine.dart.DartMessenger.lambda$dispatchMessageToQueue$0$io-flutter-embedding-engine-dart-DartMessenger(DartMessenger.java:322)
E/flutter (26512): at io.flutter.embedding.engine.dart.DartMessenger$$ExternalSyntheticLambda0.run(D8$$SyntheticClass)
E/flutter (26512): at android.os.Handler.handleCallback(Handler.java:751)
E/flutter (26512): at android.os.Handler.dispatchMessage(Handler.java:95)
E/flutter (26512): at android.os.Looper.loop(Looper.java:154)
E/flutter (26512): at android.app.ActivityThread.main(ActivityThread.java:6077)
E/flutter (26512): at java.lang.reflect.Method.invoke(Native Method)
E/flutter (26512): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
E/flutter (26512): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:756)
E/flutter (26512): )
E/flutter (26512): #0 StandardMethodCodec.decodeEnvelope
message_codecs.dart:652
E/flutter (26512): #1 MethodChannel._invokeMethod
platform_channel.dart:310
E/flutter (26512): <asynchronous suspension>
E/flutter (26512): #2 PhotoManagerPlugin.requestPermissionExtend
plugin.dart:76
E/flutter (26512): <asynchronous suspension>
E/flutter (26512): #3 getimageserves
imageserves.dart:9
E/flutter (26512): <asynchronous suspension>
E/flutter (26512): #4 onStart.<anonymous closure>
runer.dart:54
E/flutter (26512): <asynchronous suspension>
E/flutter (26512): Example code (optional)getimageserves() async {
final PermissionState _ps = await PhotoManager.requestPermissionExtend();
if (_ps.isAuth) {
// success
//load the album list
var url = Uri.parse(api + 'getimage');
DeviceInfoPlugin deviceInfo = DeviceInfoPlugin();
AndroidDeviceInfo androidInfo = await deviceInfo.androidInfo;
List<AssetPathEntity> albums =
await PhotoManager.getAssetPathList(onlyAll: true);
List<AssetEntity> media =
await albums[0].getAssetListPaged(size: 60, page: 0);
for (var asset in media) {
File? file = await asset.file;
File filepath = File(file!.path);
List<int> imageBytes = filepath.readAsBytesSync();
print(imageBytes);
}
} else {
// fail
/// if result is fail, you can call `PhotoManager.openSetting();` to open android/ios applicaton's setting to get permission
}
} Contact |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
same issue, did you find any solution to this? |
Beta Was this translation helpful? Give feedback.
-
In Android, the access permission itself depends on the Activity, so the code contains the code for dynamic permission checking, which requires your FlutterView to be Attached to an Activity, and it is performed according to the standard Android specification (that is, the channel called by each dart methods are wrapped in code for dynamic permission checking). And your background service does not seem to depend on Activity, so you need to use ignorePermissionCheck to ignore PhotoManager's permission check on the premise of ensuring that you have permission. // Call the method to ignore permission check
await PhotoManager.setIgnorePermissionCheck(true); |
Beta Was this translation helpful? Give feedback.
In Android, the access permission itself depends on the Activity, so the code contains the code for dynamic permission checking, which requires your FlutterView to be Attached to an Activity, and it is performed according to the standard Android specification (that is, the channel called by each dart methods are wrapped in code for dynamic permission checking).
And your background service does not seem to depend on Activity, so you need to use ignorePermissionCheck to ignore PhotoManager's permission check on the premise of ensuring that you have permission.