I’m continuing my educational coding exercise, developing a new photo sharing app. Recently, I completed my user authentication and registration process and I’m now quite happy with it, so I moved on to taking photographs. I’ve got an activity with a toolbar and a floating action button:
In the MainActivity, I’ve set up an onClickListener as follows:
The question before me is this: How do I ask for permissions on Android?
Declare the permissions you want in your AndroidManifest.xml file.
Use ContextCompat.checkSelfPermission() to see if you have the permission.
If you don’t have the permission, show the rationale, and request permissions.
Define a callback to receive the result of the request permissions.
It’s actually a lot of boiler plate code, which I won’t show here because the android.developer.com has already done it.
The easy way
This left me searching for an alternate way, and I found it in a small library called Dexter - contributed to open source (Apache 2.0 licensed) by Karumi. Basically, it simplifies the way you ask for permissions.
In my case, I need to ask for multiple permissions, so let’s go through the process. First, we declare the permissions in the AndroidManifest.xml file:
Next, add the library to the app-level build.gradle:
Don’t forget to sync.
Finally, call Dexter in your app to check for licenses:
We declare the list of permissions we want in the .withPermissions() and then add a callback that is called when it wants something. In this case, once I’ve got all the permissions approved, I call launchCamera(). If the permissions failed, then it drops through and returns - nothing actually happens.
There is another version of this that provides an onFailure callback for checking an individual permission. This allows you, for example, to disable the camera button when you get a declined to prevent the user from clicking the button in the future.
I’ve been working on my UI developer skills recently (and I’ve done a few other posts about this as well). If you look at any of the recent design trends on Dribbble or UPLabs, you will see plenty of rounded corners. SwiftUI makes it simple to create rounded corners on all the corners - just add .cornerRadius(radius) as a modifier to the view.
What happens when you only want a couple of corners rounded? For this, you need to dive into custom shapes and masks.
Let’s set up a view to exper...
I’ve got to the point with my template where I am thinking about deployment options. There is already a great option (the gh-pages module) for deploying to a github.io site. However, I am going to be running most of my services on Microsoft Azure. I want to deploy my service automatically and copy the web application to a web site on Azure.
Just like AWS, you can deploy a website directly to Azure Storage. This is a great option if you just want cheap web hosting plus the option of consu...
Thus far, in my journey to produce a customized toolchain for my React development, I’ve covered a lot of ground. See part 1 and part 2 for that coverage. I’ve come to the point where I need to discuss testing, which is a complex area.
First, there are at least four types of testing you need to do:
Unit testing is something you should be running on a regular basis - a series of tests that test each component to ensure that the functionality is correct from the outside.
In my last article, I started a React app from scratch, then integrated Parcel as the bundler, TypeScript for language support, SASS, ESLint for linting the code, and Stylelint for linting the style sheets. I didn’t include any testing capabilities, so that is next on my agenda.
Let’s write a simple component to get started with testing. The component takes an “isBusy” flag. If it is true, then one icon is displayed. If false, a different icon is displayed. I’ll use text nodes in this v...