I am attempting to do something very simple yet it is causing me much pain.
I have an Ionic v5 Angular 12 application and have installed the Ionic-Native/PhotoLibrary plugin
I am using the Ionic-Native version as recommended by the plugin itself
Here is my code
import { PhotoLibrary } from '@ionic-native/photo-library/ngx';
constructor(private photoLibrary: PhotoLibrary) { }
const blob = new Blob(binaryData, { type: dataType });
this.file.writeFile(this.file.dataDirectory, attachment.name, blob, { replace: true }).then(() => {
console.log('file should be saved');
let libraryItem = this.photoLibrary.saveImage(this.file.dataDirectory + attachment.name, "RaceApp");
console.log('photo should be saved to album');
});
When running in android studio I see the following in the console
I/Capacitor/Console: File: https://localhost/main.js - Line 3687 - Msg: file should be saved
D/MediaScannerConnection: Scanned /storage/emulated/0/Pictures/RaceApp/2022-2-9-6.jpeg to content://media/external_primary/images/media/9512
E/AndroidRuntime: FATAL EXCEPTION: android.bg
Process: com.pyrix.racechat, PID: 10114
java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String org.json.JSONObject.toString()' on a null object reference
at org.apache.cordova.PluginResult.<init>(PluginResult.java:55)
at org.apache.cordova.CallbackContext.success(CallbackContext.java:70)
at com.terikon.cordova.photolibrary.PhotoLibrary$5$1.run(PhotoLibrary.java:212)
at com.terikon.cordova.photolibrary.PhotoLibraryService$2.run(PhotoLibraryService.java:214)
at com.terikon.cordova.photolibrary.PhotoLibraryService$5.onScanCompleted(PhotoLibraryService.java:579)
at android.media.MediaScannerConnection.runCallBack(MediaScannerConnection.java:211)
at android.media.MediaScannerConnection.lambda$scanFile$1(MediaScannerConnection.java:188)
at android.media.MediaScannerConnection$$ExternalSyntheticLambda0.run(Unknown Source:6)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loopOnce(Looper.java:226)
at android.os.Looper.loop(Looper.java:313)
at android.os.HandlerThread.run(HandlerThread.java:67)
I do see that the RaceApp Album has been created and the photo is saved to that album. What I do not understand is why the application is crashing and that error is being shown.
1 post - 1 participant