The Blog

How to add footer to NavigationView

28 Ago 15

NavigationView was recently added by the Android support team to help developers deliver consistent NavigationDrawer Menu across apps. It’s usage is super simple thanks to its support of native menu’s xml resource files.

Such simplicity comes with a drawback. You can add menu items, an header but not a footer. After investigating a little I saw the NavigationView actually uses a ListView to display the menu and the given header is added through the ListView.addHeaderView method.

Read More

How to avoid Fragments overlapping due to backstack nightmare in android

16 Ago 15

Recognize this mess above?? That WTF moment that happens when you’re trying to do nothing special?

This screenshot was taken after pressing the back button after a specific set of preconditions have occurred:

  • You committed a FragmentTransaction without “addToBackStack”
  • You did not set the background color to the rootview of your fragments (Good boy)
  • you tried to go back just after adding the above mentioned transaction.

Let me explain:

Lets assume we’ve 3 fragments: A, B, C. and you’d like to have the following behavior: User navigates in the following direction A -> B -> C; Suddenly you realize you’d like to skip “B” from the back stack letting the user jump from “C” to “A” when pressing the back button. What would you do?

Read More

Miglior Smartphone Android – Come sceglierlo

03 Giu 15

Rotto il vostro smartphone o è semplicemente  arrivato il momento di cambiarlo? Periodicamente ci si ritrova con il problema di andare a scegliere il miglior smartphone che fa per voi.

Purtroppo online c’è molta confusione a riguardo e moltissime volte vi ritroverete a leggere decine e decine di recensioni per poi non capirci più nulla.

Fortunatamente lo staff di mantiene costantemente una classifica dei migliori smartphone android sul mercato. Questa classifica, anche se non definitiva, vi aiuterà a restringere il campo di ricerca a pochi telefoni invece che continuare a navigare nel buio tra schede tecniche e opinioni personali fatte da diverse persone.

La classifica si presenta in modo chiaro e conciso ed è suddivisa in fasce di prezzo. Avrete così modo di considerare solo i migliori smartphones per fascia di prezzo. Attualmente le fasce proposte dallo staff di androidiani per miglior smartphone android sono:

Buon acquisto!

Android – Validate an email inside an EditText ( and more )

26 Mag 12

Input validation could be very painful. Building forms, in every technology, is a boring and painful job.

Fortunately on the web many libraries have born in order to facilitate this task to web developers. In android there are, built-in, some best practices you can use to facilitate the job but you’ll always have to take care about:

  • in-depth data validation
  • mandatory fields check
  • error presentation

Bored about giving birth another painful form I decided to write an opensource library that does almost everything for me. The library is called FormEditText and you’ll be able to browse/download the sourcecode here in github.

The basic usage of the library will allow the developer to get an edit text validated through xml attributes.

In this snippet of xml code we have a lot of good tech ( both from Android and my library ):

  • line #3:  we define a new namespace. You’ll need to modify the package name ( com.andreabaccega.edittextformexample in the code ) with yours
  • line #9: we provide an hint for the user so that he’ll know what he should write inside the field
  • line #10: we provide a value for the stock android:inputType attribute.
  • line #12: we tell the library that the field should be a valid email address

The last thing we’ll need to do is to ask the library to check the edittext validity:

This piece of code, performed when the user clicks the “submit” button, will ask the library to validate the content. Here two things could happen:

  1. the input is valid: in this case the library will just return true ( obviously )
  2. the input is not valid: in this case the library will return false and will set an error message that will look like the image on the top of the page.

When in the first case the library won’t do anything except returing “true” on line #3 of the previous snippet.

Further readings:

I’ll suggest to take a look at the github project. If you want to try the library I also setted up an example app that you can download from the market.

porting applicazioni iphone android

1,000 - 5,000
Link Android Market

Android: How to execute some code only on first time the application is launched

12 Apr 12

It happens you need to execute some piece of code only on the first time the user start using your app.

Lets say you want to show a quick tutorial to the user just once — Indeed, when the user open your app for the first time.

Well, an easy solution would be to use a SharedPreference to store the info we need to accomplish this “task”.

Below, a snippet with a simple method ( to be included inside your activity class ) that will “solve” the problem.

onChange event on EditText in Android

09 Ott 10

Sooner or later you’ll have to deal with it. If you’re an html developer and you write also in javascript you’ll surely know the onchange event.

Unfortunately it’s a little bit tricky to find the same event on android.

The onChange event is helpful when you’ve to deal with the following things:

  • Let the user know (in realtime) how many characters he typed.
  • Let the user know (in realtime) how many remaining characters he is allowed to type.
  • Make realtime processing of the content ( like sending it online and fetch some partial results of the partial typed edittext )

You’ve to implement your own instance of TextWatcher and let the edittext know that you want to be notified at each change by calling the method EditText.addTextChangedListener.

Below i will give you a simple example ( it’s written on the fly but you’ll understand the idea )

[sourcecode lang=”java”]
((EditText)findViewById( TextWatcher() {

public void afterTextChanged(Editable s) {
((TextView)findViewById(, s.length()));


public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
// TODO Auto-generated method stub


public void onTextChanged(CharSequence s, int start, int before,
int count) {
// TODO Auto-generated method stub




Android Root Certification Authorities List

23 Set 10

Since it was a little hard for me finding it, here you can find the trusted CAs in Android 2.2 Froyo.

In order to get my result on each android device you’ve to download this file and place it on $JAVA_HOME/lib/ext . Plus, you should have $JAVA_HOME/bin in your $PATH

[sourcecode language=”bash”]
adb pull /system/etc/security/cacerts.bks cacerts.bks
keystore cacerts.bks -storetype BKS -provider org.bouncycastle.jce.provider.BouncyCastleProvider -storepass changeit -list -v >> certificates.txt

After the break my certificates.txt.
Read More

Write an SMS without sending it on Android 2.2 Froyo

12 Ago 10

I just figured out how to write an sms without sending it really on android froyo 2.2 using the content provider.

I’ll write only the snippet here. Hope it helps

[sourcecode language=”java”]
* writes an sms on the contentprovider
* @param ctx Context
* @param mobNo mobile number
* @param msg text of the message
private final static void storeMessage(Context ctx,String mobNo, String msg) {
ContentValues values = new ContentValues();
values.put("address", mobNo);
values.put("body", msg);
ctx.getContentResolver().insert(Uri.parse("content://sms/sent"), values);

Obviously you should set the right permissions on the manifest ( Yes the following are all needed for this task ) :

[sourcecode language=”xml”]
<uses-permission android:name="android.permission.WRITE_SMS"></uses-permission>
<uses-permission android:name="android.permission.READ_SMS"></uses-permission>

Add Events on Google Calendar on Android Froyo and above

09 Ago 10

Since i started developing applications for android i noticed there were some undocumented apis. Google does reccomend to not use these apis but since there are no “other nice ways” to achieve some tasks sometimes they are useful ( but still unreccomended)

It’s the case of the Google Calendar Apis. Out there you can find a lot of docs about these undocumented & unsupported apis but you’ll get some troubles if google decides to change them.

For example if you want to add an “event” to the calendar programmatically you can follow the snippet below which is SDK proof. In fact i did ( It’s not refactored for better reading ) write some code that would work on Sdk from 1.5 to 2.2 ( aka Froyo ) solving the provider issue on froyo and above.

Hope it helps to solve the problem about google calendar in froyo :)

Reference to the CP: Xda

Android Usefull Docs

27 Lug 10

Today i surfed the web searching about guidelines and best practices on writing android apps. In this in-depth search i found some useful slides and tips:

1. Android Ui Design Guidelines

A slideshare with some usefull tips about android ui design:

[slideshare id=4827211&doc=uidesigntips-100723230420-phpapp02]

2. Android Ui Stencil and PSDs

I also found a great resource where there are some other stencils and psds to download.


3. Android icon templatepack

I also noticed the Google Android team released the icon template pack so you can easily design you’r own menus and icons using their psd with a lot of presets.