Friday, September 30, 2011

Exploiting Android GPS Capabilities

I still remember those times when the first smart phones came to be part of our everyday life. At first they were just simple devices used to communicate with people that were physically separated. That was fabulous, communicate with someone that was miles and miles away from you was just a dream. Time passed and those devices came to revolutionize the way we would use them. A built-in camera, microphones, games, SMS, Multimedia Messaging, Instant Messaging sounded like a good deal. I thought that was all we could come up with. Smart phones we part of our more intimate moments. Things kept changing as time had passed and mobile technology was not the exception. Now our mobile devices are capable of connecting to satellites out there in the space. How cool is that? Well, in reality Android phones can do much more than that; they can localize a user not only using the Global Positioning System but a combination of technologies such as GPS, mobile networks, and radio communication in order to locate a user. In this post, I will be giving the basics on GPS localization in our android devices. As a developer I have found this interesting since having the ability to know where a user is, there is a big variety of services that can benefit smart phone users. 

Let's get to our main task: learn how to use GPS features in Android.

Before we start, make sure you have the following already installed:

          1) Eclipse (freely available on-line)
          2) Android SDK (freely available on-line)

Now lets create a Android Project:


Once you have created the project, it is time to create our first Java class and add it to the project:


Now that you have created a Java class make sure you override the onCreate() method:


Make sure to import the following classes:

import android.location.Criteria;
import android.location.LocationListener;
import android.location.LocationManager;

These contain all that is needed to request user location from your Android device. Now it is time to instantiate some objects that will request for the user location:

As a matter of better programming practices, I have created the following protected variables in my class:

protected LocationListener locationListener;
protected LocationManager locationManager;

It is up to you if you follow this tip or you can directly implement those in the onCreate() method. They have to be instantiated:

locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
locationListener = new MyLocationListener(getApplicationContext()); 

Note: locationListener is a class that I implemented in order to keep things organized. If you want to follow the same practice, make sure you create a class MyLocationListener that implement LocationListener like this:

public class MyLocationListener implements LocationListener
{
       //Methods that will be helpful to implement
      /*
     * Called when a new location is found by the network location provider. This overrides.           
     */
    public void onLocationChanged(Location location)
    {
          /*
           * Make use of location obtained by device 
           */
           if(location != null)
          {
          
               //display location in latitude and longitud
               text = "Lat: "+ location.getLatitude() 
               + "\nLon: " + location.getLongitude() + "\n\n";
  
           }
    }

    // You will have to override the 
    public void onStatusChanged(String provider, int status, Bundle extras)
    {
          /can be left blank
    }
    //and also
    public void onProviderEnabled(String provider)
    {
           //can be left blank
    }
    //as well as 
    public void onProviderDisabled(String provider)
    {
         Toast toast = Toast.makeText(context, provider + " is disabled!", Toast.LENGTH_LONG);
          toast.show();
    }
}

Note: the text variable that is being used in the onLocationChanged above is a CharSequence variable that can be displayed using an EditText object or any other way you want to display your gps data.

You can also implement the following code that is used to START the service, this code goes in your class that contains the onCreate() method. 

GPS_PROVIDER is used to get location just from GPS.


Or if you wish to get you location from the network you can use the following code:


Now that you have your locationManager running, you will need to stop the service at some point. This can be done anywhere you want but it has to be called once you do not want to continue collecting GPS data. The code looks like this:

This is pretty much what has to be done in order to obtain user location at any given time. The imports that we have used can be accessed on-line if you need more information on the parameters used in each instantiation. 
For more information regarding this please refer to: Android API

There is one last IMPORTANT detail that you need to take care if you don't want to find surprises. If you run that code as it is, you may notice that you get errors, and that is because you need to make a simple modification to the Manifest file. This file can be seen from Eclipse IDE as follows:


This is located in the "Package Explorer" in Eclipse. Open the AndroidManifest.xml and add the following code to the xml file:


<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

This code is needed by the device in order to add the necessary permissions to use the GPS or Network.

Now you are ready to deploy your application to your device and start collecting GPS data that can be used to create location-based services. This coded is intended to give a brief introduction that will give you a push in your journey to the futuristic location-based services. 





Uninstalling MySQL from Mac

Have you ever wanted to get rid of mysql from your Mac and discovered how tedious in may become to get rid of it? As a Windows user, we are used to install and uninstall any piece of software with just a click of a button. The robustness of a Mac as well as the power of the Mac Computers sometimes may be a burden, fortunately there is always ways to overcome the difficulties we find when using a Mac. This little post may help developers spend more time in their task instead of figuring out how to get rid of a piece of software.


Just execute the following commands o the Terminal in order to have MySQL completely removed from your Mac Computer:

shell> sudo rm /usr/local/mysql
shell> sudo rm -rf /usr/local/mysql*
shell> sudo rm -rf /Library/StartupItems/MySQLCOM
shell> sudo rm -rf /Library/PreferencePanes/My*
shell> sudo rm -rf /Library/Receipts/mysql*
shell> sudo rm -rf /Library/Receipts/MySQL*



Thursday, August 5, 2010

Next Generation Surgical Robots: Where's the Doctor?

Next Generation Surgical Robots: Where's the Doctor? (Link to an article in ScienceDaily)

As new and more innovative technologies keep emerging some sectors of our society will take different forms. We have witnessed how machines have replaced men in many important areas of our lives: machines used in agriculture, robots being used in factories, answer machines taking messages just to mention a few. In this article, a new generation of surgical robots at its early stage can soon replace our doctors. A profession that has been around for a long time may soon come to an end. This article mentions that a robot "can locate a man-made, or phantom, lesion in simulated human organs." What makes it impressive? Well, these robots are not assisted by humans. This means that the robots are autonomous and can take their own decisions. This robot is not used in practice but it might replace our doctors soon. In my opinion, a smart machine should not replace a doctor especially when the machine is not supervised by a human. Machines should have the turn on/off feature because men should be able to control these smart machines. Imagine what would happen if this machines fail in the middle of a surgery? Having these advances in artificial intelligence is an area of opportunity for scientist and so we need to understand the problem that we are trying to solve with these technologies. We cannot give total trust to a machine. Having technologies that make it cheaper and  easier for us to get a surgery is a good idea but they have to be operated and supervised by a human in case it fails. The operation of these robots is believed to be at an early stage because the lack of efficient algorithms and faster processors are on their way. There is more research to be done. One of the greatest challenges they found is the speed of data acquisition and processing. These are fields of great research around the world and we hope to have faster algorithms and processors so that we can see these robots operating at their full very soon. The development of these technologies is very important but researchers have to keep in mind that we cannot give total trust on decisions that can only be made by humans. We need to include the turn on/off feature so that we can control the technologies we create. 

Tuesday, July 13, 2010

Scientists Worry Machines May Outsmart Man

Scientists Worry Machines May Outsmart Man (Link to an article in NYTimes)

Can you imagine living in a place where machines are more intelligent than humans? According to John Markoff, some concerns have been raised in the community of Computer Scientists and Artificial Intelligence researchers around the globe. Some of the researchers involved are alarmed by the constant improvements in technologies, and so are debating whether we should put limits to the creation of smart machines. One of the main reasons for having limits on these new technologies is the fact that "further advances could create profound social disruptions and even have dangerous consequences." We have to set limits because we need to have all these technological advancements under our control. It is ethically wrong to create machines that are totally autonomous and cannot be controlled by humans. Technologies in general, but specially smart machines must benefit humans not destroy or cause disruption in our daily lives. This raises an ethical question: Are humans being forced to "learn to live" with machines and computers? With the new technological advances humans have to find a way to interact with computers. Older people feel that society is trying to force them to interact somehow with computers. They feel left out of their own natural environment just because they have no idea on how to use a computer. This should not be the idea when designing new technologies. The interaction should be natural where any individual, no matter what his/her condition is, should be able to interact with a smart environment. Another thing designers and researchers need to keep in mind is the "turn on/off feature." Users should be able to control the machines. Another important aspect is the exploitation of artificial intelligence systems. Many of the benefits we get with the newly developed and researched technologies can be badly used against our human race. "What could a criminal do with a speech synthesis system that could masquerade as a human being? What happens if artificial intelligence technology is used to mine personal information from smart phones?" As we can see, advancements in Artificial Intelligence can bring a prosperous future but as new technologies are created, new ways of exploiting the vulnerabilities come along. After the conference that took place in California, USA, many experiments and projects around the the world have been halted. There is a need for ethical researchers and scientists that care about the future of humanity. Humans are more important than any technology. There is a need for a world-wide organization that regulates and sets some guidelines that protect the integrity of humans. In 1965 Good proposed that smart machines  would design even smarter machines. This may sound sci-fi but if we do not set limits in the design of smart machines Good's proposal can become an uncomfortable reality. Some of the problems cause by the rise of these smart machines can bring "socioeconomic, legal and ethical issues." Human-computer relationship will probably change because as the author of the article says: "How would it be, for example, to relate to a machine that is as intelligent as your spouse?" This is very unfortunate but we need to be optimistic that Artificial Intelligence research will benefit humans and will improve the way we live. It is up to us, and so we need to participate in the development of future AI technologies. 

Monday, July 12, 2010

Visual System Interprets Sign Languages

Visual System Interprets Sign Language (Link to an article in ScienceDaily)

Amazing article on how the development of new technologies can benefit people with different disabilities.  This time students from the European Union in conjunction with the "Catalan Federation of Deaf People" developed a visual system that will help deaf people that use Spanish sign language make consultations in their language. What is interesting in this research is the fact that researchers are taking into consideration that signs can vary depending on each user. Another aspect that is very notorious is the ability of this system to translate sign language to real words in real-time. This feature allows deaf users to communicate using the simplest signs of the collection of sign language to establish a simple conversation with people that knows nothing about sign language. It makes use of very simple artifacts that we use in our daily lives such as a video camera. It captures images that are interpreted and matched with a sign. It is worth mentioning that this system can be scalable and adaptable to other sign languages. Its architecture allows other users to train the system to work with different sign languages. According to the author of the article, this system is designed with peculiar care due to the different contexts in which the system can be used. The researchers have worked hard to find a harmony between the environment that surrounds the system: light, shadows, speed at which the sign is made, etc. Even though this is a very promising project, designers of the visual system assured that it can not handle many signs yet. The reason is that it can confuse some signs but development is on its way. They are trying to implement the system using two cameras two recognize more complex signs. In conclusion, projects that make life easier for those that are unable to participate in our communities  or have a special need are exceptional ways to show that we can reach a harmony between humans and the environment that surround us. These types of projects create an environment where humans can be sure that their dignity will be protected. Technologies that want to make humans less human are worthless. We need to focus on creating technologies that will make members of our society more human instead of degrading human nature. This is a good example of technologies that make good use of information contained in the context. This system responds to the presence of a deaf person and it is worth mentioning that this will allow those members with special needs to integrate in a more natural and human way to our society.

Friday, June 25, 2010

Could humans be infected by 'computer viruses?'


This article was published about 2 months ago. Dr. Mark Gasson is the first person to have a computer chip (RFID) implanted in his left hand. It is inredible how new advances in the micro-technologies is helping researchers to accomplish better results in the area of Artificial Intelligence. An ethical question can be raised in opposition to the studies being done in the University of Reading. Implanting devices into te human body is not very ethical. If we read towards the end of the article we notice that this scientist provides very anti-human comments when he says "I believe it is necessary to acknowledge that our next evolutionary step may well mean that we all become part machine as we look to enhance ourselves." This is just ridiculous how we are going against human dignity. This is a serious problem that has to be approached with singular attention. There are many other ways that a smart building or any other smart environment can recognize a user. Implants are not the solution. Humans can not be transformed into machines, we have to protect the human righ of being fully human. I never thought a human was ever going to be infected y a computer virus. This sudy is a reflection of human stupidity. We have many issues affecting us and now we want to become vulnerable to computer viruses? This is a serious threat against human dignity. Let us take care of our current problems, we have enough, we do not need more problems.