New Gluon Charm Down Services (Part I)


The Gluon engineering team has over the past few weeks been working on enhancing the already crowded list of services in Charm Down with a few more plugins. These services will be released in the coming days (or, depending on when you read this, might already be available).

In this blog post, we’ll talk about two of these: Video and Share services, and new common functionality included in all the services: runtime permissions check on Android and a debug flag.

You can find the latest code in the Charm Down repository.

Charm Down

Charm Down is the library that addresses the integration with low-level platform APIs. Using Charm Down, you write code that accesses device and hardware features using a uniform, platform-independent API. At runtime, the appropriate implementation (desktop, android, ios, etc) transparently makes sure the platform specific code is used to deliver the functionality.

Gluon Charm Down is another Gluon open source project, available in our gluon-oss repo. It is also bundled as part of our Gluon Mobile offering, for building high-quality, cross-device applications for Android and iOS. Developers interested in understanding the API can review the Charm Down documentation or the full Charm Down Javadoc.

Video Service

With the video service you can play media files (both video and audio) on your device. The media files can be provided from the resources folders or from valid URLs.

The video service displays videos on top of the UI layer. This means that the developer should take care of disabling view switching and any other UI interaction that could lead to overlapping nodes while the video is playing. If the user calls hide() or the playlist finishes, the media layer will be removed, and the user will be able to resume normal interaction.

Video files can be displayed with or without native embedded controls, and its maximum size and position on the screen can be defined.

The following code snippet shows how you can display video in your mobile app, providing the file BigBuckBunny_320x180.mp4 (downloaded from here, licensed under the Creative Commons Attribution 3.0 license) is added to the assets folder:

Once the media player is visible, you can use the embedded controls to play or fast forward the video file.

Full screen mode is enabled and can be accessed/exited with a pinch gesture. Also orientation changes are taken into account, so padding in normal screen mode has to be applied accordingly.

The following is all the code required to create an app that can play video files from the local folder (place the file “BigBuckBunny_320x180.mp4” under /src/main/resources/) and from the Internet, using the Gluon IDE plugin and the Single View project template, providing buttons to interact with the playlist in this case.

Share Service

The share service provides a way to share content (text and/or files) from the current mobile app by using other suitable apps existing on the user device.

This one-line snippet shows how you can easily share text from your app through the suitable apps, social media accounts, and other services installed in the user’s device.

To share files, it is convenient to make use of the Storage Service to create or read them in either private or public storage folders. Note that for sharing files on Android, those files have to be accessible from public storage folders.

The following is all the code required to create an app that can share text and files, using the Gluon IDE plugin and the Single View project template.

It doesn’t require any extra configuration, but on Android, since we are using the Storage service, we need to add the PermissionRequest activity to the manifest, as below, if we are targeting Android 23+:

And on iOS, if we want to share the image to the local gallery, we need to add this key to the info file:

Deploying and running the app on Android and iOS will let us share the text and image with our installed apps:

Runtime permissions request on Android

Since Android 6.0 (API level 23), users can grant permissions to apps while the app is running, not when they install the app, so including the required permissions in the AndroidManifest file is not enough. The user has more control over the app’s functionality as any or all the permissions can be granted or revoked at any time.

So far, the Charm Down plugins were not able to request permissions at runtime, and when targeting Android SDK 23+ the only way to grant dangerous permissions was via the app’s Settings screen.

As for the Android documentation, these permissions are those where the app wants data or resources that involve the user’s private information, or could potentially affect the user’s stored data or the operation of other apps. Examples of plugins that require these type of permissions are the DialerService (phone), the PicturesService (camera), the PositionService (location), and the StorageService (storage).

Since this release, all the plugins that require those type of permissions include an activity: the PermissionRequestActivity, that will manage these cases. All that is required is adding the activity to the Android manifest, when using barcode scan, dialer, pictures, position or the storage services.

For instance, in case you are targeting Android 23+, and you want to take a picture:

by adding the required permission and the mentioned activity to the manifest:

you will get a dialog the first time you run the app to grant permission or if later on the user revokes this permission in the app’s Settings screen.

Debug flag

Starting from this release, setting the system property "com.gluonhq.charm.down.debug" to true, right before initializing the service, will enable a more verbose console output.

Conclusion

Two more services and common features have been added to Charm Down. Give them a try by running any of the samples available, or adding your own implementation.

Stay tuned, as in future posts we’ll talk about more services: bluetooth low energy for devices, audio recording, advertising, and in-app billing.

If you need extra features, new plugins or commercial support, you can get in touch with us at support@gluonhq.com.