Share
Embed
No Play Service? No Worries!
Lots of our applications depends on the technical bricks provided by the Play Services such as Google Maps, the push notifications by Firebase or even the Play Store for deploying our apps all around the world.
What if you are building apps for a device that does not implement the Play Services. With this talk you will have a glimpse of the tools you can use to build your Android applications without the Play Services such as OpenStreetMap, OpenPush or alternative ways to deploy an APK.
Julien Salvi
November 21, 2020
Transcript
50 slides
-
No Play Services? No Worries! Julien Salvi Senior Android Engineer,
Aircall devfest Egypt 2020 -
How you can end up developing apps without the Play
Services? • Supporting a larger set of devices • Build apps for devices that don’t have the Play Services (Huawei, Hardware for B2B...) • Company’s choice • Trying something new, open-source… Let’s see how we can deal with it -
Meet Happy! Happy is a… happy dev! • Using good
practices • Building apps with Kotlin • Testing his apps • Doing crazy animations! Hi I’m Happy! -
Happy has built a new app! • Using Google Map
SDK for displaying routes • Going for Firebase messaging to send nice notifications • CI/CD for deploying on the Play Store • So far so good! Let’s do this! -
After a while, app got a lot of crashes! Hum…
Something’s wrong! GooglePlayServicesRepairableException GooglePlayServicesNotAvailableExceptio n -
OMG! Happy learns that the app has been deployed on
a lot of devices that don’t have the Play Services installed Sometimes because the app is distributed outside the Play Store or for B2B devices without the Play Services -
Woop woop! But no worries Happy! Let see what tools
and libraries we can use for developing applications without using the Play Services -
Firebase libraries • Firestore, • Storage • Crashlytics • InAppMessaging
Now lots of Firebase libraries works without the Play Services • ML libs • Ads • Push messaging (FCM) • Database • Config • Authentication ✅ ⛔ -
Push Notifications • FCM is tied up to the Play
Services for receiving messages • There are many alternatives for push messages • Let see how Pushy, OpenPush or RabbitMQ can a good replacement tool! -
Push Notifications • Reliable push service • Cross-platform solution •
Free plan at first, the premium • Similar implementation to FCM • Based on MQTT protocol -
override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) if (getToken() != null)
{ viewModel.registerPushy() } else { Pushy.listen(context) } } -
scope.launch(Dispatchers.IO) { val token = Pushy.register(context) // Save in the
shared preferences for example saveToken() // send token to your backend sendToken() } -
class PushReceiver : BroadcastReceiver() { override fun onReceive(context: Context, intent:
Intent) { val msg = intent.getStringExtra("message") // Do amazing stuff here! (Notification, routing...) } } -
OpenPush • Open-source and free alternative to FCM • Decentralized
and self-hosted • No developer key required • A lot of code on server and client side • More complex than FCM or Pushy -
OpenPush OpenPush - A Free, Decentralized Push Messaging Framework for
Android by Marcus Hoffmann https://f-droid.org/en/2020/02/03/openpush-talk.html -
RabbitMQ for Android • Open-source message broker • Based on
AMQP protocol but now support STOMP or MQTT • Receive AND send data • Might be a good solution if your app is always on like a kiosk app -
RabbitMQ Consumer/ Subscriber RabbitMQ Server publish publish subscribe subscribe Queue
Queue Consumer/ Subscriber -
// publishing messages private val queue = LinkedBlockingDeque>String>() fun publishMessage(message:
String) { try { queue.putLast(message) } catch (e: InterruptedException) { e.printStackTrace() } } -
// create and setup a connection val factory = ConnectionFactory()
factory.setUsername(config.getUsername()) factory.setPassword(config.getPassword()) factory.setVirtualHost(config.getVhost()) factory.setHost(config.getHost()) factory.setPort(config.getPort()) factory.setAutomaticRecoveryEnabled(true) -
// Create publish channel val connection = factory.newConnection() val channel
= connection.createChannel() channel.confirmSelect() // Publish messages added to the queue transactionsQueue.add(Message(comment)) while (!transactionsQueue.isEmpty()) { val message = transactionsQueue.get() val exchange = "amqp.direct.app.messages" val routingKey = "comment_v1" channel.basicPublish(exchange, routingKey, null, message.getBytes()) channel.waitForConfirms() } -
// Create subscriber/consumer val connection = factory.newConnection() val channel =
connection.createChannel() val q = channel.queueDeclare() channel.queueBind(q.getQueue(), "amqp.direct.app.messages", "chat") val consumer = QueueingConsumer(channel) channel.basicConsume(q.getQueue(), true, consumer) while (true) { val delivery = consumer.nextDelivery() val message = new String(delivery.getBody()) // Handle the data received } -
Google Maps replacement... ...may be Google Maps itself! • Starting
with v3.0.0, Maps SDK is now a standalone library • This SDK is still in BETA • Might not work in countries where Google services are blocked -
OpenStreetMap SDK • Free, open-source and collaborative map project •
Many features: routes, geocoding, markers but not as rich as Google Maps • Used by Microsoft, Uber, FB… • Huge dependency in your app -
<org.osmdroid.views.MapView android:id="@+id/map" android:layout_width="match_parent" android:layout_height="match_parent" /> binding.map.setTileSource(TileSourceFactory.MAPNIK) binding.map.zoomController.setVisibility(Visibility. SHOW_AND_FADEOUT) binding.map.setMultiTouchControls(true) //
Enable pinch-to-zoom and set center to our city binding.map.controller.apply { setZoom(10.0) setCenter(GeoPoint(-26.2041028, 28.0473051)) } -
HERE map SDK • Map SDK backed by Nokia •
Many features: vector maps, navigation, 3D buildings • API very similar to Google Maps with good documentation • Huge dependency in your app -
<com.here.sdk.mapview.MapView android:id="@+id/map" android:layout_width="match_parent" android:layout_height="match_parent"/> binding.map.setOnReadyListener { binding.map.setCenter(GeoCoordinate(-26.2041028, 28.0473051, 0.0), Map.Animation.NONE)
binding.map.setZoomLevel(8); val mapImage = MapImageFactory.fromResource(resources, R.drawable.pin) val anchor2D = new Anchor2D(0.5f, 1) val mapMarker = new MapMarker(geoCoordinates, mapImage, anchor2D) binding.map.getMapScene().addMapMarker(mapMarker) } -
F-Droid or APK Mirror • F-Droid for distributing your free
and open-source apps to the market • Community maintained since 2010 • APK Mirror for common apps, very similar to the Play Store without all pain points -
Mobile Device Management • Build your own solution or use
existing (AppCenter, TinyMDM…) • Mostly for enterprise apps or B2B • Let see how we can be build our own MDM! -
When choosing a store or a MDM? Your app target
mass maker, or is open-source and you want something similar to the Play Store go for… You target enterprise apps or you want to have the control of the device fleet go for… -
MDM Conception SDK Web Service Yes! Have a new version?
Download and install the new version Database Storage -
<uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" /> <application> <provider android:name="androidx.core.content.FileProvider" android:authorities="${applicationId}.myapp.provider"
android:exported="false" android:grantUriPermissions="true"> <meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/iostore_provider_path" /> </provider> <receiver android:name=".InstallReceiver" /> </application> -
val packageInstaller = context.packageManager.packageInstaller val apkUri = uriFromFile(context, file) context.contentResolver.openInputStream(apkUri)?.use
{ src -> val length = DocumentFile.fromSingleUri(context, apkUri)?.length() ?: -1 val params = PackageInstaller.SessionParams(PackageInstaller.SessionParams.MODE_FULL_INSTALL) val sessionId = packageInstaller.createSession(params) val session = packageInstaller.openSession(sessionId) session.openWrite("app", 0, length).use { dest -> src.copyTo(dest) session.fsync(dest) } val intent = Intent(context, InstallReceiver::class.java) val pendingIntent = PendingIntent.getBroadcast(context, INSTALL_CODE, intent, PendingIntent.FLAG_UPDATE_CURRENT) session.commit(pendingIntent.intentSender) session.close() } -
val packageInstaller = context.packageManager.packageInstaller val apkUri = uriFromFile(context, file) context.contentResolver.openInputStream(apkUri)?.use
{ src -> val length = DocumentFile.fromSingleUri(context, apkUri)?.length() ?: -1 val params = PackageInstaller.SessionParams(PackageInstaller.SessionParams.MODE_FULL_INSTALL) val sessionId = packageInstaller.createSession(params) val session = packageInstaller.openSession(sessionId) session.openWrite("app", 0, length).use { dest -> src.copyTo(dest) session.fsync(dest) } val intent = Intent(context, InstallReceiver::class.java) val pendingIntent = PendingIntent.getBroadcast(context, INSTALL_CODE, intent, PendingIntent.FLAG_UPDATE_CURRENT) session.commit(pendingIntent.intentSender) session.close() } -
val packageInstaller = context.packageManager.packageInstaller val apkUri = uriFromFile(context, file) context.contentResolver.openInputStream(apkUri)?.use
{ src -> val length = DocumentFile.fromSingleUri(context, apkUri)?.length() ?: -1 val params = PackageInstaller.SessionParams(PackageInstaller.SessionParams.MODE_FULL_INSTALL) val sessionId = packageInstaller.createSession(params) val session = packageInstaller.openSession(sessionId) session.openWrite("app", 0, length).use { dest -> src.copyTo(dest) session.fsync(dest) } val intent = Intent(context, InstallReceiver::class.java) val pendingIntent = PendingIntent.getBroadcast(context, INSTALL_CODE, intent, PendingIntent.FLAG_UPDATE_CURRENT) session.commit(pendingIntent.intentSender) session.close() } -
GeckoView • Developed by Firefox • Displaying web content in
your app or build your own browser • Standalone library, huge dependency! • Standards compliant, excellent support for modern web -
val session = GeckoSession().apply { progressDelegate = progressDelegate() settings.useTrackingProtection =
true } geckoRuntime = GeckoRuntime.create(requireContext()) session.open(geckoRuntime) binding.geckoView.setSession(session) session.loadUri("https://devfestegypt2020.sessionize.com") -
Sample application • Let’s build our first app without the
Play Services • Showcasing OpenStreetMap and GeckoView • Spotting the similarities between Google Map and OSM