My code working in the desktop browser(chrome) but gives the error I mentioned in the Android webview(chrome). (File chooser dialog can only be shown with a user activation. Debugging click error)
It was working in Angular version 14, but this problem occurred after upgrading to 15. Current material version "@angular/material": "^15.2.9",
<input
id="hiddenInputAcquire"
class="hidden-input-acquire"
hidden
type="file"
accept="image/*"
capture="environment"
onclick="this.value = null"
(change)="onUploadPicture($event)" />
<button
mat-icon-button
color="accent"
matTooltip="{{ 'COMMON.PICTURE_TOOLTIP_ACQUIRE' | translate }}"
(click)="acquireImage()">
<mat-icon>photo_camera</mat-icon>
</button>
acquireImage() {
if (this.isCaptureSupported()) {
const inputAcquire = document.getElementById('hiddenInputAcquire') as HTMLInputElement;
if (inputAcquire) {
//error appears here
inputAcquire.click();
}
return;
}
const dialogRef = this.dialog.open(AcquireImageDialogComponent);
dialogRef.componentInstance.useToCropExistingImage = undefined;
dialogRef.componentInstance.interactiveCropping = this.useCropper;
this.acquireDialogSub?.unsubscribe();
this.acquireDialogSub = dialogRef.afterClosed().subscribe((res: AcquireImageDialogResult) => {
if (res.isImageProvided) {
this.assignPicture(res.fileId);
}
});
}
private isCaptureSupported() {
const ele = document.createElement('input');
return 'capture' in ele;
}
- I tried
this.hiddenInputAcquire.nativeElement.click();
New contributor
volki tolki is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.