Archive for July, 2016

29 Jul 2016

using Context in a static environment (simple way)

11:54 | android | 240 views

Goal: find a simple way to reach a usable context in a static method I have found many complicated ways to get a usable context, but I have an easy and simple way. 1. we need a static class, with a global context variable 2. set this variable in the main activity 3. and of […]


29 Jul 2016

get the cpu version

11:45 | android | 218 views

Goal: find out the heart of a device It is easy to find the version of the central unit in my device. Seemingly… 1. the android way Use the Build class like this: 2. get info from the company (as I see they can give what they want…) Read the /proc/cpuinfo file. So in a […]


28 Jul 2016

get the current battery level

18:01 | android | 222 views

Goal: check the device battery level In a static function like this: The result is between 0-100 (0 is not very common 🙂 )


28 Jul 2016

using Context in a static environment

16:33 | android | 233 views

Goal: get Context in a static method Sometimes we need a context in a static method, but we don’t have… Let’s dig one. example: get the device ID (IMEI) in a static function.


28 Jul 2016

get the device id (IMEI)

1:51 | android | 255 views

Goal: get the unique device identifier This is the IMEI/MEID number. We need permission to read this information.


26 Jul 2016

set the font style and size in a SearchView

16:06 | android | 240 views

Goal: let’s customize a SearchView appearance First of all the SearchView is a complex control. We need to find the child TextView to do this changes. Set the following style: here is the code: The findChildrenByClass function like this: public static Collection findChildrenByClass(ViewGroup viewGroup, Class clazz) { return gatherChildrenByClass(viewGroup, clazz, new ArrayList()); } private static […]


23 Jul 2016

generate random numbers

12:25 | android | 218 views

Goal: we need this 🙂 We need to know about this. How we can generate a random number between minimum and a maximum value.


23 Jul 2016

date difference calculation

12:22 | android | 232 views

Goal: get the time difference between two dates The following code gives the difference between two times in this form: 1h 12m The seconds and the days not used. Just good to know how can calculate these values.


23 Jul 2016

date manipulation

12:18 | android | 187 views

Goal: sometimes we need to modify a date… Like in this simple case. Let’s add 5 minutes to the actual time. Easy with the java.util.Calendar class. Nota bene: this class can use years, hours, minutes… as well


21 Jul 2016

scrollable TextView in android

11:09 | android | 197 views

Goal: making a TextView scrollable put two lines to the layout file: plus to the activity:


#sidebar a { color:#fff; } #sidebar ul ul li { color: #DEF585; } #sidebar h2 { color: #fff; } #sidebar ul p, #sidebar ul select { color: #BEDDBE; } #backfly { background: url(images/golfBallWallPaper.jpg) left bottom fixed repeat-x #65a51d; }