We are migrating from an Ionic Cordova app to an Ionic Capacitor app. While I know that Capacitor still supports Cordova plugins, we try to migrate as much as possible.
Our app relies on the device UUID provided by the Cordova device plugin. Is this the same as the device UUID provided by Capacitor? I tried to compare both repositories, but I am not completely sure if the Android is actually the same (what is the first argument in the method given below)?
[[device identifierForVendor] UUIDString]
Settings.Secure.getString(this.cordova.getActivity().getContentResolver(), android.provider.Settings.Secure.ANDROID_ID);
UIDevice.current.identifierForVendor!.uuidString
Settings.Secure.getString(this.context.getContentResolver(), android.provider.Settings.Secure.ANDROID_ID);
Its the same. The only difference in the case of iOS is the way uuidString
is accessed. The Cordova plugin was written in Objective-C while the Capacitor plugin is Swift. The same value should be returned for both though.
The Android plugins also seems to be referencing the same value, just in different ways. Both pass a content resolver from the app Activity context as the first parameter to Settings.Secure.getString()
. The difference between: this.context.getContentResolver()
and this.cordova.getActivity().getContentResolver()
is how Context is accessed (a big topic on Android development).
From the Cordova plugin guidelines,
getContext() and getActivity() can return the required Context object
If you go through the code of the Capacitor plugin, the file that is the main entry point calls getContext()
and directly passed it to the Device()
constructor.
In short both refer to the same Activity Context. this.context
is the same as this.cordova.getActivity()