id: 161 View:category
Tutorials  Android Things
Electricity Monitor

Introducing “Electricity Monitor"

For those who may not know, I live in beautiful sunny South Africa (see my tweets for lots of awesome pictures). A few years ago we battled with a lack of electricity. While “load-shedding” is not so common these days, we have numerous unplanned outages. We even have a few of apps that give out schedules when the electricity is scheduled to go off in your area (see here and here).

While these apps serve a purpose, they are not so good when we have unplanned outages.

Which often leaves me asking myself the following questions:

Do I have electricity at home right now?
If not, how long has the electricity been out for?
Is it okay to eat the contents of my freezer?

Full article


Tutorials  Language  RxJava
RxJava

ReactiveX corner cases

Whether you’re new to RxJava, or have used it for a while, there’s always something new to learn. While using the framework, I learned 5 not so obvious things about RxJava that helped me maximize its potential.

This article references APIs that are available in RxJava 1.2.6

1. When to use map or flatMap

Map and flatMap are two commonly used ReactiveX operators. They’re often the first two operators you learn, and it can be confusing to figure out which one’s the right one to use.
Both map and flatMap apply a transformational function on each item emitted by an Observable. However, map only emits one item, whereas flatMap emits zero or more items.

In this example, the map operator applies the split function to each string and emits one item containing an array of strings. Use this when you want to transform one emitted item into another.

Full article 


Tutorials  DI
Dagger Dependency Injection

An introduction to dependency injection for Android

You might have heard the term "dependency injection" before.

You might have even tried to Google it and stumbled upon a definition that introduced 2 new unknown terms: inversion of control and dependency injection pattern.

Personally, I find the following definition to be the most descriptive - dependency injection for five-year-olds: 

When you go and get things out of the refrigerator for yourself, you can cause problems. You might leave the door open, you might get something Mommy or Daddy doesn’t want you to have. You might even be looking for something we don’t even have or which has expired. What you should be doing is stating a need, "I need something to drink with lunch," and then we will make sure you have something when you sit down to eat.

- StackOverflow answer

Full article


Tutorials  Media  Sharing
Sharing Intents

Nougat and onwards forbids file:///URI beyond your package

Since Android 7.0 Nougat you can’t expose a file:/// URI with an Intent outside your package domain, but don’t worry: here’s how you can fix it.

Android 7.0 Nougat introduced some file system permission changes in order to improve security. If you’ve already updated your app to targetSdkVersion 24 (or higher) and you’re passing a file:/// URI outside your package domain through an Intent, then what you’ll get is a FileUriExposedException.

When you share a file with a file:/// URI, you also modify the file system permission of it and make it available to any app (until you change it again). There’s no need to say that this approach is insecure.

Why is this happening?

According to the official documentation:

In order to improve the security of private files, the private directory of apps targeting Android 7.0 or higher has restricted access (0700). This setting prevents leakage of metadata of private files, such as their size or existence.

Full article 


Tutorials  UI  Layout
Fragments Introduction

The mini-me's of Activities

This tutorial is an introduction to Android Fragments. You will learn the fundamental concepts of Android Fragments while creating an app that displays the rage comics.

Update note: This tutorial has been updated to API 25 and Android Studio 2.2.2 by Huyen Tue Dao. The original tutorial was written by Huyen Tue Dao.

fragmentnoun | /’frag-mənt/
an isolated or incomplete part of something.

A fragment is an Android component that holds part of the behavior and/or UI of an activity. As the name intimates, fragments are not independent entities, but are subservient to a single activity.

In many ways, they resemble and echo the functionality of activities.

Full article