Showing posts with label android. Show all posts
Showing posts with label android. Show all posts

Monday, August 22, 2011

Android Emulator is not starting showing " invalid command-line parameter"

I was updating my Android/Google Eclipse environment because I wanted to try the new GPE beta which comes with lots of cool new things. I also took the opportunity to update my Eclipse to Indigo. In summary I updated everything, I like to be up to date on these things :)

Anyways, after installing a configuring everything I was ready to launch the emulator but it wouldn't start at all. It was giving me always the same error:


As it turns out Android SDK R12 has this bug that if the path has spaces, it won't locate it. As I have to work in Windows I placed my SDK inside C:/Program Files/Android . So that was causing my emulator to fail every time I was trying.



They are fixing this issue but you can work around it by using C:/PROGRA~1/Android. If you are using 64 bit, you can use C:/PROGRA~2/Android . Or you can just simple install the SDK in a location without spaces.



These are some tricks you get to learn when you work and try new things. Most of the times we think it is a miss-configuration or something wrong with the installation and we spend a lot of time installing and configuring everything again, but sometimes you just need to do some research. I like to find and document these kind of issues because that way you help others and also yourself since the next time you need to upgrade your development environment you just can look at your notes.

Hope it helps someone, happy coding :)

Monday, May 23, 2011

Some Tips to Publish your app in the Android Market

Today is a great day, I finally published my application in the Android Market :) :) even though it is not even version 1 it is pretty stable and has some really cool things. I tried to follow all their best practices in code, UI and resources.

The Android documentation has some links on how to prepare your app for the Android Market, things like a checklist, UI tests, how the versioning works, how to design your application icons and a lot more, but I wanted to add my personal touch :)

If you have everything on those links above, you are almost done. In order to publish an application you need to sign up as a developer and pay a one time only fee of 25$ which is cheap compared to Apple Store and Amazon. Once you sign up and make the payment you can upload as many apps as you want but for each app you need to have  some mandatory images and screenshots. Believe me when I say that it took me more time getting this icons and images right than developing my application. Sadly, I am not a graphics guy, I did what I could though ;)

Once you upload your apk the developer console gives you a summary of the permissions and features your app needs to run properly; this list is based on your Manifest File, minimum API version and code.

Permissions summary
You can save a lot of time by using the aapt (Android Asset Packaging Tool)tool, you just execute this:
$ aapt dump badging <path_to_exported_.apk>
It will dump all the permissions, features, supported screen sizes and everything! really nice tool. Really useful instead of using the Developer console and find out that you missed something and start the whole process again.

Also, I would recommend paying a lot of attention to the <uses-feature> part. Spend sometime reading the documentation and you will understand why this is so important if you wan to get your application in as many devices as you can. Also you can read this blog post about hardware support and this one about future-proofing your app. This is really an important part. The first time I uploaded my app the console told me it was going to available to 13 devices! just 13! I was shocked since my app could run an any device with Froyo or more and according to this that was more than 65% of the current market. Then I did some research and I added these 3 lines to my Android Manifest:
<uses-feature android:name="android.hardware.faketouch" android:required="false"/>
<uses-feature android:name="android.hardware.touchscreen" android:required="false"/>
<uses-feature android:name="android.hardware.telephony" android:required="false"/>


and now my app is available to 355 devices! Basically this is saying that my application requires this hardware but it can work just fine with out it. For example the last line says that my app can work on any device not only cellphones. It would be better to have telephony features but it can work with out it. So pay attention to this part because it does make a huge difference.
Supported Devices
Finally, it gives you the option to advertise your app. I did not enable this, yet but I am thinking about it. My app is really simple right now and I will add more things before starting that.
Advertise using AdMob
Testing your application in the emulator and your own device is easy. Right now my app could be in 355 different devices and that is the real test. I was afraid to publish it because now it is alive so anyone can install it and use it and that scared me for a lot of time. Sometimes users are mean! and they lie, but at the end I wanted to see my end result and see if I reached that point where I can develop real applications and not just personal projects for my own use.
My App :)
So if you have time you can download my app from here and make a comment and review it :)

Saturday, April 23, 2011

Building Android Projects from Command Line

I have been spending a lot of time with Android and I am making really good advantages with my app :) even though it is taking a lot of weekends and nights. It is difficult to make progress when you have a full time job that sometimes looks like a 2 full time jobs.

I think I noticed that sometimes using eclipse to build your project and deploy it into the emulator takes a lot of time and I already talk about how slow the Android Emulator is and some ways to it make less slow. One of them is to use command line to create your apk and then install it into the emulator or device.

First, you need to create the build.xml file so you can use ant. To do this you might need to update your root directory project to do that you can execute:

@chambras:~/AndroidWorkSpace/my-app$ android update project -p .
Updated local.properties
Added file ./build.xml

Once the build file is added you can build your app in debug mode. Just open the command line and write:
ant debug
This will create your debug apk inside your project bin/ folder and looks like [your_project_name]-debug.apk
The next step is to install the apk in the emulator and to do that you just need to do this:

adb install [path_to_your_apk].apk

or if you have multiple emulators or devices running you can execute adb devices so you will see all the devices connected and emulators running and then you can execute:

adb -s emulator [emulatorid] install [path_to_your_apk].apk
If you want to install it in your device:

adb -d install [path_to_your_apk].apk
In order to make this process fast I would recommend adding the platform-tools/ and tools/ folders to your PATH if you are using windows. If you are using Ubuntu or Mac you can do this:

sudo ln -s /path/to/android/tools/android /usr/bin/android
sudo ln -s /path/to/android/platform-tools/adb /usr/bin/adb
These will create symbolic links to those tools so you can execute them form anywhere. Here is more information about building android projects and here on how to use your device.

Happy coding :)

Thursday, April 21, 2011

How to test Google Analytics for Android

Time ago I wrote how to integrate Google Analytics into your Android application. The integration and usage it is pretty simple but the testing part is really terrible. I said that time that you can see the data in your Google Analytics account only after almost a day you posted the events. This was ridiculous, waiting one day to see your results and data just to check it is fine was just a waste of time so started digging and fingig out where these data is stored because it must have some kind of storage so later when you dispatch the data the framework looks for this data and posts it online.

Indeed, my supposition was true. As it turns out when you configure you Google Analytics account in your android application, it creates a new DB in your package folder. Inside this Data Base there are a bunch of tables but the one that stores your page views and events is named events. If you want to test the data you are collecting, these are the steps you need to do:

adb shell
cd data/data/<your.package.name>/databases
sqlite3 google_analytics.db
This last command will open the Google Analytics data base and once there you can see all the tables by executing .schema. So every time you record a page view or event a new row will be inserted in the events table. This table has a lot of columns but you can execute .schema events to see all of them and its data types so you can query the ones that you care about to test your application.

Happy coding.

Sunday, April 10, 2011

How to enable fast scrolling in Android

Fast Scrolling in Android happens when you have a lot of items in your screen and you need to scroll fast. When it is activated you well see an small box coming from the right of the screen and when you drag it up or down it goes really fast. You can see this in your contact list, email or any application that has a lot of data and is sorted alphabetically.

There are 2 ways to enable this functionality in your application:
By adding the property in your XML layout file:


    <ListView
        android:id="@id/android:list"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:fastScrollEnabled="true" />

or by adding it in your java code:

      getListView().setFastScrollEnabled(true);

Both of them work the same the only trick is that you need to have at least 35 items in your ListView in order to see the fast scrolling box. You can see the end result in the image.



Hope it helps some one, happy coding :)

Sunday, March 6, 2011

Android Market Security Update

Yesterday Google announced that over last week they identified malicious applications in the android market. Devices running Android 2.2.2 and up were save of this attack which by now is a good percentage but still there were a lot of devices vulnerable. According to the post he malicious code took of advantage of a known vulnerability and they could have obtained MEI/IMSI, unique codes, and android version of the running devices but giving the nature of the exploit they probably were able to get more than data and information.

Because of the severity of this attack they had to do 4 things:

  1. Remove the malicious applications from the Android Market and suspend the related account.
  2. Using the remote application removal feature in android they are removing all the malicious applications from the users cellphone.
  3. They pushing a Android update Market to all devices affected. If you were affected you will receive an email  and notifications about applications being removed and the security update. All of this should happen in the next days.
  4. They are working  hard to improve security in the android market and prevent this kind of exploits in the future .
For more information and help on this issue you can visit the Android Help Center where they explain in more detail everything about this exploit.

Since Android is moving so far I am not impressive that it is going to get a lot of attacks and malicious exploits. Google says that you mobile is one of the most important things for you and it holds everything about you, like, personal numbers, access to all your data, maybe bank accounts and who else what's more that is why it is a great target. If you are able to get through the security  and get all the users data the price is incredible.

Android needs to change a lot! I know they flexible about publishing your apps but at some point they need to improve the process so this kind of attacks won't happen again. We, the users, trust them but if we get this kind of news, we were no longer trust or at least not the Android Market and competition will gain more space and who knows maybe Amazon Android MarketPlace is better.

Wednesday, March 2, 2011

Android 2.3.3 a.k.a. Gingerbread update for Nexus One

Finally this morning my Nexus One got the official  Android 2.3.3 a.k.a Gingerbread. I think the only two phones getting it are the Nexus S and Nexus One and makes sense since they are their children ;) and what's more the Nexus One is the official android developer.

The update as usual went smooth and in less than 15 minutes got it up and running. It feels a little bi faster than before and the new UI looks fantastic :)

Before this update they released the final SDK, updated eclipse plugin, android tools and the emulator. You can check all the details here. Time ago when they released the preview I also talk about the new functionality packed gingerbread and now it is official and even though is more gaming oriented it really feels more stable and faster. You can check all the highlights here.

You can also check the official video



I read that for some the update broke Google voice text messaging but in my case the only thing weird is that my widgets were gone. I had to add them again and they are working just fine.

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

Saturday, February 5, 2011

Blogger app for Android

I am testing the new blogger app for android and I was expecting more. Actually I am writing this post using it and has a lot of limitations for example you can't see your posts. You can only see the ones that you have written in the app so doesn't sync with your online blogger account which I think it is essential.
Despite the sync functionality this app some really good highlights, like :
  • You can switch between multiple accounts as long as you are the author.
  • You can obviously write and save posts as a draft if you wanna post it later.
  • You can add pictures from from camera or gallery. 
  • You can share your location in your posts if you want to.
  • And blogger is added to one of the sharing options in the sharing menu so you can share photos from your gallery.


The app still has a lot to improve but it is a good start. I wrote this post using it but only the text part since it was difficult to add pictures where I wanted, make links and format the text properly.
Anyways hit the android market and gve it a try.

Wednesday, February 2, 2011

Highlights from Android Event - HoneyComb

Today Google had an Android event to show us their improvements on HoneyComb which by the way are awesome!!! they really invested a lot of time in 2D and 3D and performance.
The couple of things I liked were:

The new android market web page is up and running. I must say it is a really huge improvement from the old one which it did not even have search! it was really bad. Anyways the new portal let's you sign in and register your devices and do over the air installations. We already saw this last year in the Google IO keynote, they should added over the air un-installations though :)

They released more ways for developers to gain more from their apps like in-app billing and currency conversations. They improved their multi touch and drag and drop functionality, a lot of new widgets which make notifications less intrusive and video chat. In fact there are a lot more things but these are the ones that took my attention. I am not really a gamer but it is worth mention that the gaming experience it is a lot better talking about speed, effects and performance.

Here is the event video for the ones who missed it, enjoy it!

Monday, January 31, 2011

Android Emulator Slow

I am playing with Android a lot, specially since they released GingerBread and now they just released the first preview of HoneyComb. I started my first application using Froyo in which the emulator was pretty fast and I could boot and work with it normally. When I first started playing with Gingerbread I noticed it was slower than before but I did not give it too much attention and now that HoneyComb preview is out it has been really a pain to work with the Android Emulator. I do not have the latest and greatest laptop but either way just to boot and launch my application could take like 15 or more minutes and sometimes it wouldn't start at all.

Obviously something was wrong here and started looking at some options to improve it. First I found out that when you create an android virtual device ( AVD ) the default RAM is just 96 MB so you might want to increase it, for example Nexus One has 512 MB of RAM. All the hardware configurations can be found here.

Another thing I found is that starting the AVD from the AVD manager is faster than staring it from eclipse. So you first start he AVD you want to use for your application and once it is up an running you  execute your application. I noticed a huge improvement in boot time and application start by doing this.

The third option is to use command line to start the AVD and once it is started you can install your application. This way is the faster I think. It seems the eclipse integration has some issues still. So if you like command line, you can use this method. The commands for the emulator can be found here and how to install your application from command line can be found here. Basically you have to do this:
  1. open a command line
  2. execute: emulator -avd <avd_name>
  3. once the emulator es up and running then you execute: adb install <path_to_apk>
Just remember both tools need to be added to your PATH variable otherwise you will have to go to the folders that contain them.

Hope this tips help someone :)

happy coding :)

Tuesday, January 11, 2011

Google Goggles

Today Google launched a new version of Google Goggles for android and it seems it is going to be faster and smarter. Before I would say it would have like 90% probability to detect whatever you scan. Now they have improved the speed and added a couple of things.

First, Google Goggles now is able to recognized printed ads although it only works with magazines printed in major U.S. magazines and newspapers after August 2010 which isn't that bad.

Second, they have improved the scan functionality and now it works faster than ever. According to them it takes around a second to find the product ( it used to take like 5 to 10 seconds before ).


And the third one, They have added the ability to solve SUDOKU puzzles by scanning the puzzle as it were a bar code. I like this one a lot. I have no tested properly but so far it works great :)

So start solving sudoku puzzles :) here it is a video of how it works, enjoy it!



I like the slogan at the end, "solving life's problems, one puzzle at a time" :)

Saturday, January 8, 2011

A Sneak Peek of Android 3.0, Honeycomb

Google finally gave us an official review of what it is going to be the next generation of Android a.k.a. Honeycomb. It seems it is going to be Tablet oriented and makes sense since It seems where the market is moving now.



The new UI and Tablet enhanced applications look really nice. It is a remarkable improvement from Froyo and GingerBread.

Enjoy the Video :)

Saturday, January 1, 2011

Switching from iPhone to Android

I found this nice article about jumping from iphone to android. Everyone who knows me knows that I am an android guy :) I have used Iphone and to be honest it has good things but most of them I do not like; maybe because I am a developer and I like openness and apple iOS just simple does not have.



I must say that iOS is much user friendly than Android  also their apps, but I am sure that is something Android will improve eventually and what's more from a developer point of view it is not a deal breaker.

The article mentions the good and the bad of moving from iPhone to Android. Things good like free navigation, voice input commands, notifications, perfect harmony with Google services, storage options and a lot more. And also the bad things like the Android fragmentation. It is true, since it is open you can find a lot of android flavors thanks to the manufactures, low battery life ( Evo from spring ) .


Really it is a nice article to read if you are planning to switch to an Android powered device :)

Wednesday, December 15, 2010

App Inventor for everyone

Like six months ago Google announced this labs project called App Inventor. This Google labs experiment  makes it easier to develop android applications so people with out too much knowledge  about programming could build android applications easy and fast that would feed their needs.

Until yesterday it was just a private beta but finally today they have announced that is free to download for everyone with a Google account. So go to App Inventor and grab a copy to start playing with this awesome tool :)

Here is the first video they uploaded showing the capabilities of it. Enjoy it!



Happy coding :)

Sunday, December 12, 2010

Google Talk not working on Android

Usually when you get a new phone it is like a new toy for us and that is exactly what happened tome. I got my new N1 and I started installed a lot of apps and updates you know Google maps, GVoice, Pandora, Games, Network tools and a large etc. Obviously I ate almost all my internal memory by the I only had less than 20Mb.



One of the big problems I have with my N1 is storage ( you never have enough ;) ) It only has 512 Mb of internal memory and basically as much as your pocket can get on external memory, usually android devices support 32Gb easily. When you install apps all of them go to your internal memory which is shared with all other things like the Android OS itself so you if you do not move them manually to your SD ( some apps have this new functionality ), you will ending up like me with no internal space available.



When this happens some apps like GTalk won't work anymore. I noticed that every time I tried to signing in, it will try to do it for a while and then give you a black screen and go back to home.  It took me a while to relate the out of space problem I had with apps not working properly. It seems Android needs a certain amount of space vailable in order to run applications properly that is why I always recommend moving huge apps to SD card whenever is possible and also cleaning app's cache.

Friday, December 10, 2010

Gmail push not working

Couple of days ago I noticed that I was not getting Email notifications from my Gmail account in my N1. Every time I had to refresh it manually and then I would get my emails. At first I did not care about it but then it started becoming annoying to refresh it manually all the time. After a lot of time trying things to make it work again like re-installing the app, configuring accounts, google and etc etc I found the solution.

The first thing I did was to move most of my apps to the SD card since I only had 20Mb of free space now I have around 50Mb ( still low ). It seems when you run out of space in your main memory some apps start behaving really weird or they stop working at all ( more on this later ). Still I was not getting my GMail notifications :(



The second thing I did was cleaning my cache and clear the app's data; to do this you just go to Settings --> Applications--> Manage Applications --> All --> Gmail and once you are there you click on Clear Data and Clear Cache by doing this you are wiping all the information the application has about you so the next time you try to execute it you might have to enter your credentials again.



Finally I re-started my phone and FINALLY!!!! notifications are back!!!!! :)

Some recommendations: be sure to have at least 50Mb of free memory in your phone's main memory, move as much apps as you can to your SD card and from time to time try cleaning your app's cache and in some extremely situations your app's data

Hope this info helps some one else.