Monday, February 28, 2011

Tunning your Router for VOIP and Video

Time ago I wrote how to configure your router so you could access your home server from anywhere using ssh or VNC which is really handy if you work from home or if you want to access you server anytime from anywhere.

Days ago I read this article in PC World which talks about how to tune your router for VOIP and video. It also talks about gaming and serving websites which is also good if you are into it, bur I am not. It talks about all the possible options you have to configure your router like port forwarding,  QoZ, DMZ and so on.

When you buy a router it comes with all these options disabled for security purposes. You can always change these options in order to make it work the way it fits your needs and even if you screw it, you can always reset to factory settings :)

I use VOIP a lot especially for my work since I have to communicate with developers in India, USA and Bolivia and most of the times I work from home so little by little I am trying have a nice work environment there. I use Skype and Google Voice most of the times.
 It is a really nice article if you want to tune your router for VOIP and HD video and to learn about the basics of router configurations. Remember that every router is different but the article covers the most of them.

Sunday, February 27, 2011

Google Developer Periodic Table

I remember the hard time I had back in high school when I had to learn the chemical periodic table and all the properties they have all they classified by gases non gases, metals, noble gases, etc etc.

Anyways, Google found a similar way to present their developer products and APIs. I did not know they had that many and curiously the 2 in the top are Android and Chromium which make sense since both of them are competing among themselves right now. I do not know at what point both of them will merge but having to Operating Systems competing on each other does not make sense.

Every item in the table has a link to its description and documentation which is really handy.
Google Developer Products and APIs

Saturday, February 26, 2011

Integrating your Android Application with Google Analytics

The best way to track how your app is being used by your users is to track what are the most screens visited, which buttons and events were executed and things like that. In order to accomplish you can integrate Google Analytics SDK for android in your application.

The integration is pretty simple but the documentation is missing a couple of things. First lest install what we need. We are going to need Android developer SDK of course and Google Analytics for Mobile.  Once you have everything, you need to configure 2 things:
  • Copy the libGoogleAnalytics.jar to your project's /libs folder. If you do not have, you will need to create the folder and do not forget to add to your build path. 
  • Then you need to add the following permissions to your project's AndroidManifesr.xml manifest file:
    • <uses-permission android:name="android.permission.INTERNET" />
    • <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
Once you have your environment installed and configure the next step is to set up a a new and fake website profile in Google Analytics which is not really difficult just follow the steps just remember to give some descriptive website name something like http://myapp.mywebsite.net ( I like .net, you can use what ever you want though) once the registration is done you would get your tracking code ID that should like something like UA-xxxxx-yy, you need to write it down because we will use it in our code.

The next step is to start the tracker which uses the singleton pattern and you do it by calling GoogleAnalyticsTracker.getInstance(). Then call the start method and pass the tracking code ID and the activity being tracked. I usually start the tracker in the onCreate method because you just need to call it once.
import com.google.android.apps.analytics.GoogleAnalyticsTracker;
public class NoteList extends ListActivity 
{
    private GoogleAnalyticsTracker tracker;

    @Override
    public void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        //setContentView(R.layout.main);
        setDefaultKeyMode(DEFAULT_KEYS_SEARCH_LOCAL);
        tracker = GoogleAnalyticsTracker.getInstance();
        tracker.start("UA-YOURCODE-HERE", this);
     }
}
Once tracker is started you have 3 options to collect data and send it to Google Analytics servers: Pageviews, Events and custom variables.

Pageview
I use it this everytime the user would go to a different activity or screen, which is good since you can know where the user goes the most.
tracker.trackPageView("/Add New Note");
Event
As it name says it it tracks events. I usually add this to buttons, option menu and context menu items, basically everywhere where an event gets triggered. It is easy because it would be every where there is a listener method like clickListener, itemSelectedListener and so on.
tracker.trackEvent(
     "Clicks",  // Category
     "Button",  // Action
     "categories", // Label
     66);       // Value
Custom Variables
Think of this as meta-data that you want to send to Google Analytics in order to improve the date you send in pageviews and events. According to the documentation the best use case is to track information about full or lite versions of your app so for example you want to check how many lite version have been downloaded or just to filter between versions. For more information about Custom Variables you can head the documentation.

The custom variable has 4 methods: Index ( 1 to 5), Name, Value and Scope.  This last parameter is optional but if it null, it takes the page Scope. The other 2 scopes are Visitor Scope and Session Scope. The Visitor Scope gets executed the very first time the application is running on the device so it is perfect to register the version and type of application. Session scope lasts while the application is running and Page Scope it is just between the activity and it is called right before track event or track pageview.
tracker.setCustomVar(1, "Navigation Type", "Button click", 3);
Once you have all your data then comes the question, how do i send it? this is a little bit tricky since dispatching the data too often can affect on battery life so you need to very careful. That is why there are two ways to send the data one is manual tracker.dispatch(); and automatically which is set the moment you start the tracker you just need to pass one extra parameter to tell the tracker how often you want to send the data.
//dispatching every 300 seconds
tracker.start("UA-YOUR-ACCOUNT-HERE", 300, this);
If you are using manual, dispatch I would suggest it to call on the onDestroy() method that way you make sure the user won't notice it.
//@Override
 protected void onDestroy() 
 {
  super.onDestroy();
  tracker.stop();
 }
One thing I did not like about this implementation and that is missing in the documentation is that the information does not show up in Google Analytics in real time, for me took 24 hours update the information. So if you want to test this and the data your are sending you might have to wait a lot which sucks! I had to wait one day to realize that only my pageview tracks where working :(


Enjoy the new toy :)

Thursday, February 24, 2011

Working with Option Menus in Android

I've been working with android a lot these last days, mostly because I want to have my app in the android market before Google IO so at least I can say I have something to show :) I am developing a simple app just for starting and getting familiar with the platform.

Anyways, while doing the interface I noticed that it is really easy to create UI using xml especially menus. Android provides 3 kinds of menus: context menus, options menu and sub-menus. This post is about only Options Menu, I will cover the other 2 in later posts though.

Each activity has a single menu and it is created using the method onCreateOptionMenu, you can override this method and inflate the xml that contains the menu or you can add items manually, here is an example of both:
inflating the xml:
The menu structure is located in the noteslistmenu XML file. We are passing this file as a parameter.


adding them manually:


Basically both of them will generate the same menu but I prefer XML since it gives you the freedom to edit the file and add more items with out the need to re-compile the whole project again and it also allows you to add a lot more properties to your menu items.

This is how the menu looks like:

If you want to format the rows, you can group them or you can set the android:orderInCategory property. This property sets the order/priority of the items in the group and/or the menu.

This is another capture of this example and the XML file to generate it:
XMLmenu file

final result

Monday, February 21, 2011

Port forwarding and VNC configuration

Weeks ago I got a free computer from home, you know they are going to get new ones and they are giving away the old ones. Anyways this new computer is not really the best thing. It must a Pentium 4 with 2 GB of RAM and it came with out OS. I installed Ubuntu 10.10 on it since it seems my Linux knowledge has been failing.

It is the first desktop I have since a lot of time and right now is working like a dedicated server. It was good but one thing was missing. I couldn't access it from outside my home network which sucks like from work for example. Especially my NAS ( Network Attached Storage ) which has a lot of information, installers and pretty much everything I have.

I did some research and at the end everything worked just fine and these are the steps to do it if you want something similar. This is working just fine on Ubuntu, but it should also work with Windows or Mac.
  • Install ssh server if you want to use command line which I like :) or if you want to remote desktop, you can install tightVNC which has the server and the viewer versions. Ubuntu comes already with VINO which is its built in VNC server which is good but has some limitations.
  • Look into your routers documentation and find a way to configure port forwarding. This basically redirects traffic based on ports and IP's. You open a port and a IP that is going to receive the request. It is worth saying that opening ports in your router is a security breach and you need to be very careful when doing this, like having a good firewall, really good passwords, etc etc. Having said that let's continue. Once you know how to enable port forwarding in your router you need to open two ports: 22 for ssh and 5900 for VNC. These are the default ports these application work with, but can configure the application to work in a different port. In VINO it is a little bit difficult I do not know about tightVNC, it must easier though. This is how it should look like.
  • Once you finish the configuration you need to restart the server and router so the new configuration would work.
  • If everything is working fine, it is time to test. In oder to test it you can ssh your server using your public which you can find by using whatismyIP or any tool like that. The easiest way to test using Windows is using Putty which is a free ssh and telnet client. If it works, you should be able to log in using your Ubuntu user name and password.
  • If you want to test it using VNC, you will need to install tightVNC client in windows and connect using your public IP and again you should be able to log in using your same Ubuntu credentials.
More information about configuring port forwarding with VNC can be found here. It should be a pretty straight forward configuration, but again opening ports to the world can be really dangerous for your security so be very careful.

Friday, February 18, 2011

2-step verification on Google

Last week  Google announced a new service called 2-step verification. This service was already on Google App customers but they will be releasing this to everyone.
This will make your Google account more secure and preventing from been hacked more or less like banks do now. They do not only ask you for user name and your password, some of them have a sticky key, a question a confirmation number, site keys or something like that. Google's approach it is a little bit different. They are using your phone to accomplish this since that is something you will always have with you.

Once you set up the service you have the option to "Remember verification for this computer for 30 days" so you do not have to enter the code for one month. You can go here to learn more about this new service that according to Google everyone should use.

This new service showed up in my account almost right away and it should be rolling to everyone pretty soon. They took the registration pretty serious. It has a lot of steps to configure your phone, backup codes, backup phone and android app for your phone so you can get the codes and enter them.


At the it also asks you to set up application specific passwords. Some apps in your phone or desktop would stop working if you do not set up this first. It generates a random password that you need to use just once and you can do it for every application if you want

So start using 2-step verification so your account will be more secure.