I’m working on a weather app for Android. The data for wind direction that I get from the weather API is in form of degrees (0 to 360). I want to display wind direction in a user-friendly format such as N (North), NNE (North-northeast), NE (Northeast), ENE (East-Northeast), E (East), ESE (East-Southeast), SE (Southeast), SSE […]
Android
Android Maps: Get current location coordinates with Google API Client Builder
To get your current location via Google Map in an Android app, this was how we do it:
|
1 2 3 4 |
@Override public void onMapReady(GoogleMap googleMap) { Location location = googleMap.getMyLocation(); } |
Stop. Don’t use that! The method GoogleMap.getMyLocation() is deprecated. Instead, we need to use FusedLocationApi and the callback onLocationChanged(). Here’s an example code that works for me ( consider copying the contents of onResume() into onStart() […]
Android Studio and the 64K methods limit (DEX error)
Hi! I’ll share a few tips with you on how to find out the number of methods that your Android app has. I’m gonna show you a few tools such as APK file methods counter, and an Android plugin that will show you the number of methods each imported class or dependency has. These will […]
Android ImageView has unwanted padding: layout troubleshooting
If you use ImageView in your android app layout and you get that unwanted padding around the image, here’s an Android XML attribute that helped me solved the layout issue:
|
1 2 3 |
<ImageView (...) android:adjustViewBounds="true" /> |
Add android:adjustViewBounds=”true” attribute to your ImageView XML tag and you’ll probably see the unwanted padding go away. According to the ImageView docs: android:adjustViewBounds Set […]
Android app dev: image sizes for variety of screen sizes
As a mobile app developer, we need to consider various screen sizes for a wide range of Android devices. Here’s a quick note of recommended image sizes for Android app icons: 36×36 for low-density (LDPI) 48×48 for medium-density (MDPI) 72×72 for high-density (HDPI) 96×96 for extra high-density (XHDPI) 180×180 for extra extra high-density (XXHDPI) 192×192 […]
Android: 2-dimensional List String (List of List)
For a web developer who used mostly PHP and JavaScript for several years, plunging into Java can be challenging especially when it comes to data types. PHP and JavaScript are loosely typed languages, while Java is strict about types. I was told that in Android, List<String> is very commonly used, even more than arrays. And […]
Android confirm dialog box with OK and Cancel button
This will probably be one of the Android code snippets that I will need to go back to from time to time. I’m sharing the codes we need to show an Android confirm dialog to prompt the user to click “yes” or “no”, or in my case, “OK” or “Cancel”. The following code for Android […]
Android Studio dark theme (change into Darcula theme)
You might feel more comfortable with a dark theme in Android Studio, but the default theme is light in color. I’m one of the developers who always code in dark screens since it’s less tiring to the eyes. If you’re like me who prefers dark themes while coding, then I’ll show you how to change […]
How to change app name in Android Studio
I’m trying to learn how to build a simple app in Android just to satisfy my curiosity. This will also be a very handy skill because I use Android phones often, and there are times that the apps I download from Google Play Store lack features that I need. This will be a very simple […]
GrabTaxi: I could never successfully book a taxi :(
I always wanted to try the GrabTaxi app. Booking from them is expensive, but security is an important thing that they can give passengers so that’s okay. But my attempts have never been successful. I think it’s a combination of bad signalling from GrabTaxi and bad internet connection in my house.