How to solve the image picker crash app error? - dart

I have a app crash when i'm picking a image. i'm using image_picker:0.5.0+7
with any ImageSource it's crash the app.
File _fileState;
Future getImage(ImageSource imageSource) async{
// using your method of getting an image
final File image = await ImagePicker.pickImage(source: imageSource);
print("path:: ");
setState(() {
// print("path:: "+image.path);
_fileState = image;
});
}
Shutting down VM
E/AndroidRuntime(16049): FATAL EXCEPTION: main
E/AndroidRuntime(16049): Process: com.grain.test_camera, PID: 16049
E/AndroidRuntime(16049): java.lang.RuntimeException: Unable to resume activity
{com.grain.test_camera/com.grain.test_camera.MainActivity}:
java.lang.RuntimeException: Failure deliver
ing result ResultInfo{who=null, request=2342, result=-1, data=Intent {
dat=content://com.android.providers.media.documents/document/image:25272
flg=0x1 }} to activity {com.grain.test
_camera/com.grain.test_camera.MainActivity}: java.lang.IllegalStateException: Received image from picker that was
not requested
E/AndroidRuntime(16049): at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3506)
E/AndroidRuntime(16049): at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3546)
E/AndroidRuntime(16049): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2795)
E/AndroidRuntime(16049): at android.app.ActivityThread.-wrap12(ActivityThread.java)
E/AndroidRuntime(16049): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1527)
E/AndroidRuntime(16049): at android.os.Handler.dispatchMessage(Handler.java:110)
E/AndroidRuntime(16049): at android.os.Looper.loop(Looper.java:203)
E/AndroidRuntime(16049): at android.app.ActivityThread.main(ActivityThread.java:6251)
E/AndroidRuntime(16049): at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime(16049): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1063)
E/AndroidRuntime(16049): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:924)
E/AndroidRuntime(16049): Caused by: java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=2342,
result=-1, data=Intent { dat=content://com.android.provid
ers.media.documents/document/image:25272 flg=0x1 }} to activity {com.grain.test_camera/com.grain.test_camera.MainActivity}:
java.lang.IllegalStateException: Received image from picke
r that was not requested
I do not know what I can do please help me

It may be related to AndroidX compability. You have to avoid AndroidX or migrate your project to AndroidX.
There were a breaking change after version 0.5.0

image_picker plugin does not support camera permission condition anymore. For instance, when we try to access camera from an app, the app asks us for permission.
Now, since image_picker plugin has removed that condition, we need to ask the permission manually using permission_handler plugin. Read more details about this change here
Use this plugin to add the request manually ie runtime and you should be able to get rid of this crash.

I found out that in developer mode, phone close main activity of flutter because of an option in developer options this comment from author of package is
On Android, the MainActivity can be killed and restarted after launching the image picker for various of reasons. this can be tested by selecting `don't keep activities alive' option in the developer options in phone's setting app.
then when I disable this option I get result in every device that I checked. link of this description is here. I hope it works for you.

i had the same error
image picker crash on selecting an image
i solved this by using images_picker this will work instead of image_picker

I had problems with the IOS simulator.
For anyone having the same problem, I needed to set the permissions messages in Info.plist
<key>NSPhotoLibraryUsageDescription</key>
<string>This app needs to access your photo galery.</string>
<key>NSCameraUsageDescription</key>
<string>This app needs to access your camera.</string>

It seems image_picker documentation has been updated.
You would have to use retrieveLostData when the app restarts (migrate to AndroidX else you may get a force close error)
Future<void> retrieveLostData() async {
final LostDataResponse response = await ImagePicker.retrieveLostData();
if (response == null) {
return;
}
if (response.file != null) {
setState(() {
if (response.type == RetrieveType.video) {
_handleVideo(response.file);
} else {
_handleImage(response.file);
}
});
} else {
_handleError(response.exception);
}
}

Related

Ionic 4 IOS FIRESTORE INTERNAL ASSERTION FAILED: AsyncQueue is already failed: An internal error was encountered in the Indexed Database server [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 3 years ago.
Improve this question
I am developing an Ionic application, I am using Firestore as a database, using offline mode.
import {AngularFirestoreModule} from '# angular / fire / Firestore';
AngularFirestoreModule.enablePersistence (),
When I open the application everything works very well, even on offline mode.
However, if the application stays open in the background mode on re-opening it always tells this error:
FIRESTORE (6.2.4) INTERNAL ASSERTION FAILED: AsyncQueue is already
failed: An internal error was encountered in the Indexed Database
server.
And I can no longer navigate anywhere in the application because I have the condition that the subscription is alive until the component is destroyed (that happens when I change the page)
takeUntil (componentDestroyed (this)):
I get the following error:
"1 errors occurred during unsubscription: 1) Error: FIRESTORE (6.2.4)
INTERNAL ASSERTION FAILED: AsyncQueue is already failed: An internal
error was encountered in the Indexed Database server"
And the full application stops working and it is very annoying to have to close it and reopen.
Is there any different way of doing? I already looked at StackOverflow, Github, all google and I can't find any solution.
What I have seen the other applications like Netflix, HBO, etc. do. is that when you reopen the application does not start exactly where it stayed, it warns you that it is loading, and when it finishes loading it leaves you very close to where you were before leaving the application without activity. I imagine it has a background and foreground change detector and a function for each event.
I was thinking that with ionic cycles I could solve that problem, like:
-detect the change to the background and unsubscribe and re-subscribe if any change to the foreground.
Do you know in any other way of doing?
That error I solved with:
window.onerror = function(error) {
if (error.indexOf("An internal error was encountered in the Indexed Database server") >= 0) {
// Refresh the page to restore IndexedDb to a working state.
window.location.reload();
}
};
and about how to observe the state changes of background and foreground:
import { Platform } from 'ionic-angular';
#Component({
template: `OK`
})
constructor(public platform: Platform) {
platform.ready().then(() => {
if (platform.is('cordova')){
//Subscribe on pause
this.platform.pause.subscribe(() => {
//Hello pause
});
//Subscribe on resume
this.platform.resume.subscribe(() => {
window['paused'] = 0;
});
}
});
}
I hope they serve you greetings.

SensorStreamViewer, HoloLensForCV : "Failed to initialized media capture: Access is denied."

I tried to get sensor stream from HoloLens, so I used the HoloLensForCV.
(https://github.com/Microsoft/HoloLensForCV)
First, I checked that SensorStreamViewer project works, but few days later, I updated HoloLens and then it doesn't work. The error I receive is Access is Denied
HoloLens Camera view capture
HoloLens Privacy Camera capture
The Webcam capability in VS capture
And, I guess the error occurs in this part(SensorStreamViewer.xaml.cpp).
// Initialize MediaCapture with the specified group.
// This must occur on the UI thread because some device families
// (such as Xbox) will prompt the user to grant consent for the
// app to access cameras.
// This can raise an exception if the source no longer exists,
// or if the source could not be initialized.
return create_task(m_mediaCapture->InitializeAsync(settings))
.then([this](task<void> initializeMediaCaptureTask)
{
try
{
// Get the result of the initialization. This call will throw if initialization failed
// This pattern is docuemnted at https://msdn.microsoft.com/en-us/library/dd997692.aspx
initializeMediaCaptureTask.get();
m_logger->Log("MediaCapture is successfully initialized in shared mode.");
return true;
}
catch (Exception^ exception)
{
m_logger->Log("Failed to initialize media capture: " + exception->Message);
return false;
}
});
When I start others project like 'ComputeOnDevice', I can see an alert message window asking me allow to access camera. However, when I start 'SensorStreamViewer', I didn't see any alert message asking about camera access.
I started debugging, and confronted this error message.
Exception thrown at 0x772C3332 in SensorStreamViewer.exe: Microsoft C++ exception: Platform::AccessDeniedException ^ at memory location 0x0180E680. HRESULT:0x80070005 Access is denied.
WinRT information: The required device capability has not been declared in the manifest.
How can I solve this problem?
In your Package.appxmanifest file, you need to add the following capability.
<rescap:Capability Name="perceptionSensorsExperimental" />

Apple iOS ARKit: "A sensor failed to deliver the required input" error and stops working

I am developing an application that uses both ARKit and hardware video decoder. As soon as the decoder start to decode, the following error message appears in console and prevent tracking from working properly.
Occasionally, this error do not show up and the app works normally. After some debugging, I found out this error only happens at the "beginning" (shortly after launching the app). Once it passes that point, it works fine for the rest of the time.
Does anyone know what the problem is or how to go around it?
2017-08-11 20:48:02.550228-0700 PortalMetal[4037:893878] [] <<<<
AVCaptureSession >>>> -[AVCaptureSession
_handleServerConnectionDiedNotification]: (0x1c0007eb0)(pthread:0x170387000) ServerConnectionDied 2017-08-11
20:48:02.564053-0700 PortalMetal[4037:893747] [Session] Session did
fail with error: Error Domain=com.apple.arkit.error Code=102 "Required
sensor failed." UserInfo={NSLocalizedFailureReason=A sensor failed to
deliver the required input., NSUnderlyingError=0x1c4c51280 {Error
Domain=AVFoundationErrorDomain Code=-11819 "Cannot Complete Action"
UserInfo={NSLocalizedDescription=Cannot Complete Action,
NSLocalizedRecoverySuggestion=Try again later.}},
NSLocalizedRecoverySuggestion=Make sure that the application has the
required privacy settings., NSLocalizedDescription=Required sensor
failed.}
Update
The solution is to do with compass calibration being set in the phone settings. Credit to this answer.
Go to Settings > Privacy > Location Services > System Services, and set Compass Calibration to ON.
How to prevent Crashing
Declare your config at the top of your class e.g:
var configuration = ARWorldTrackingConfiguration() and make sure you setup and add your config in the viewWillAppear method.
Then add this method to handle the error.
func session(_ session: ARSession, didFailWithError error: Error) {
// Present an error message to the user
print("Session failed. Changing worldAlignment property.")
print(error.localizedDescription)
if let arError = error as? ARError {
switch arError.errorCode {
case 102:
configuration.worldAlignment = .gravity
restartSessionWithoutDelete()
default:
restartSessionWithoutDelete()
}
}
}
It just handles the error that you've noticed.
Next, add this function to reset the session with a new config worldAlignment:
func restartSessionWithoutDelete() {
// Restart session with a different worldAlignment - prevents bug from crashing app
self.sceneView.session.pause()
self.sceneView.session.run(configuration, options: [
.resetTracking,
.removeExistingAnchors])
}
Hope it helps, and I also hope to find an actual fix to this apparent bug.
Setting worldAlignment to gravityAndHeading needs the location service to be enabled:
check if your device has location service turned on.
Check if Info.plist has set Privacy - Photo Library Additions Usage Description
If the compass orientation is crucial for your app, you should consider to guide the user to do turn the location service on and implement a fallback.

Xamarin / iOS SharedAccessoryManager.ShowBluetoothAccessoryPicker Fails

I'm porting working Swift code to Xamarin for my project. Every time I call this function, it fails and the accessory picker dialog doesn't show.
EAAccessoryManager.SharedAccessoryManager.ShowBluetoothAccessoryPicker(predicate, completion)
Here's some things I've confirmed:
BT Radio is on
Info.plist has Supported external accessory protocols
Tried ensuring call is done on UI thread
Tried calling directly from Button click event
The same basic code in Swift / Xcode works fine
Made sure that ARMv7 and ARM64 were selected in build options per this article: iPad Air - CoreBluetooth[ERROR] Cancelling picker as we couldn't communicate with Bluetooth
Xamarin:
EAAccessoryManager.SharedAccessoryManager.ShowBluetoothAccessoryPicker(null, completion: ((Foundation.NSError error) => {
Console.WriteLine("My callback");
if (error != null) {
Console.WriteLine(String.Format("Error code: {0} Desc: {1}", error.Code, error.DebugDescription));
Console.WriteLine("Failed? " + EABluetoothAccessoryPickerError.Failed.ToString());
Console.WriteLine("Failed? " + Convert.ToInt64(EABluetoothAccessoryPickerError.Failed));
}
}));
Xcode / Swift:
EAAccessoryManager.sharedAccessoryManager().showBluetoothAccessoryPickerWithNameFilter(nil) { (error) -> Void in
if error != nil {
NSLog("Error code: \(error!.code) \(error.debugDescription)")
}
}
The Xamarin code doesn't show the picker and will always fail.
2016-04-05 19:54:02.136 ASGDemo.iOS[6383:2146384] Connect Clicked
2016-04-05 19:54:06.139 ASGDemo.iOS[6383:2146384] BTM: attaching to BTServer
2016-04-05 19:54:09.157 ASGDemo.iOS[6383:2146384] BTM: session attach called back with BT_SESSION_ATTACHED (fffffed0)
2016-04-05 19:54:09.158 ASGDemo.iOS[6383:2146384] BTM: attemping to re-attach in 1 seconds
2016-04-05 19:54:09.242 ASGDemo.iOS[6383:2146384] My callback
2016-04-05 19:54:09.250 ASGDemo.iOS[6383:2146384] Error code: 3 Desc: Error Domain=EABluetoothAccessoryPickerErrorDomain Code=3 "(null)"
2016-04-05 19:54:09.253 ASGDemo.iOS[6383:2146384] Failed? Failed
2016-04-05 19:54:09.254 ASGDemo.iOS[6383:2146384] Failed? 3
The nice folks at Xamarin helped me directly, so I'm posting the solution here. They said it was a bug that has already been fixed. The update should ship later this month via automatic updates (if you have that enabled).
For now, they provided a workaround that I've verified to work for me and my co-workers on our project. Below are the steps of the workaround:
Clean the project
Uncheck the Enable device-specific builds in the project options under iOS-Build section.
Remove old app from the device
Now, rebuild / redeploy and it should work.
Thank you everyone for your suggestions and help. Also, thanks to the folks at Xamarin for their prompt response.

Cordova shows an warning as " THREAD WARNING: [Your function] took [n] ms. " in iOS

"THREAD WARNING: ['Console'] took '81.661865' ms. Plugin should use a background thread."
While running iOS Phonegap project. Similarly for some of the remaining plugins like geolocation and filesystem.
As I am new to Phonegap ,can please anyone tell me how can I run the plugin on background thread.
I have checked this also.
Can we ignore this thread warning or is it related to memory issue in iOS Phone-gap
thanks
As per this. solved my warning issue
I found warning can be ignored .But this can be solved by adding background thread using this loop:(In CDVLogger.m)
[self.commandDelegate runInBackground:^{
//add your code here
}
Now this looks as below for console warning:
- (void)logLevel:(CDVInvokedUrlCommand*)command
{
[self.commandDelegate runInBackground:^{
id level = [command argumentAtIndex:0];
id message = [command argumentAtIndex:1];
if ([level isEqualToString:#"LOG"]) {
NSLog(#"%#", message);
} else {
NSLog(#"%#: %#", level, message);
}
}];
}
Also to add,
If someone is looking for a way to run sepcifically the Geolocation plugin as a background thread with iOS Cordova there is a fix on GitHub.
It removes the Xcode output warning: "THREAD WARNING: ['Geolocation'] took 'X' ms. Plugin should use a background thread."
Download the plugin from here:
https://github.com/guillaumedev/cordova-plugin-geolocation
Heres whats changed (runInBackground added):
https://github.com/guillaumedev/cordova-plugin-geolocation/commit/8fbceca845441f4f421548f243d2f05573d11225
More information about Cordova Threading:
https://cordova.apache.org/docs/en/dev/guide/platforms/ios/plugin.html#threading

Resources