The component canicompet-file-camera replace the classic .
The problem with the classic is with Android :
- When you use it on ios or on the web browser, a prompt ask the user if he wish to select a file or take a photo.
- On Android, the prompt does not exists and Android directly open the media manager to select a file.
I have written this component to add a prompt on Android. The component act like a classic .
Feel free to copy it and modify it as your convenient.
I have created it in part of my projects : https://canicompet.com and https://canigps.fr
-
Install Capacitor-Camera : https://capacitorjs.com/docs/apis/camera
-
Clone the repository in your project
-
Import the component in *.module.ts
import { CanicompetFileCameraModule } from '.../component/canicompet-file-camera/canicompet-file-camera-module';
@NgModule({
imports: [
...,
CanicompetFileCameraModule
],
declarations: [...Page]
})
- Use it in place of
<canicompet-file-camera type="file" (ionChange)="onFileChange($event)" accept="image/*" #uploadFile/>
<ion-button slot="end" (click)="uploadFile.click($event)">
<ion-icon name="camera"></ion-icon>
{{ 'Take photo' | translate }}
</ion-button>
- Define the callback
onFileChange(fileChangeEvent: any) {
var file = fileChangeEvent.target.files[0];
}