How to configure a Session to start a specific Lens (Android)
I'm having trouble finding good documentation for how to configure a Session. This sample code snippet doesn't work for me:
cameraKitSession.getLenses().getRepository().get(new Available(LENS_GROUP_ID), available -> { Log.d(TAG, "Available lenses: " + available); Lenses.whenHasFirst(available, lens -> cameraKitSession.getLenses().getProcessor().apply(lens, result -> { Log.d(TAG, "Apply lens [" + lens + "] success: " + result); })); });
because the Lenses class doesn't resolve. But my use case is slightly different anyway - I want to go straight to a specific Lens ID, and I don't need a carousel. How do I achieve that? Thanks.
Comments
-
@Harrison Shapley Thanks for the post. Sharing with our team to get you a response as soon as we can. Hang tight
0 -
Related question / different way of asking the question: How can I get/create a Lens object?
1 -
@Harrison Shapley
One of our sample apps here demos a use case that is very similar to what you are asking1 -
Thanks. I can get it to compile with that code, but it's crashing. The crash logs are obfuscated - the best I get is:
java.lang.NullPointerException: Attempt to invoke interface method 'void t0.a.b(java.lang.String, java.lang.Object[])' on a null object reference
Here is my code:
session.lenses.repository.get(LensesComponent.Repository.QueryCriteria.Available(LENS_GROUP_ID)) { available -> available.whenHasFirst { lens -> session.lenses.processor.apply(lens) } }
It seems to be crashing on the whenHasFirst line.
0 -
But I also have the question: If I have a Lens Group with multiple lenses, but want to apply a specific lens (not the first one), how would I do that?
0 -
I was able to solve both issues after playing around a bit. For others struggling with this, here is what I ended up with:
session.lenses.repository.get(LensesComponent.Repository.QueryCriteria.ById(WATCH_LENS_ID, LENS_GROUP_ID)) { result -> result.whenHasFirst { lens -> session.lenses.processor.apply(lens) } }
2 -
@Harrison Shapley Glad to hear you were able to solve your issue!! (Best feeling). Thanks for closing the loop. Let me know if you have any other open issues related to this topic.
0 -
I'd like to do the same thing on iOS, is there example code for iOS? Right now I can get my app to launch but it starts on the empty filter circle and I have to swipe/tap to get the lens to launch, where I'd prefer if it launched into the lens without the user having to do anything.
2 -
@Jeremy Bailey Looking into this...
0 -
Hi @Jeremy Bailey-- the carousel starts on the empty circle because
CarouselView.selectedItem
is initialized toEmptyItem()
, but you can initialize it to any Lens you like:var selectedItem = CarouselItem(lensId: lensId, groupId: myGroupId)
0 -
ah yes thank you @arashp ! that worked! BUT... it only selects the lens, for some reason it doesn't appear – I have to swipe back to the empty circle and then back again for the filter to appear.
1