Things to do before uploading an app to the Android Market

Hi there,

Imagine the scenario when you have just finished developing your cool mobile application and want to share it with the world.
Hold on a moment before you do it and consider below list of recommended things to do.

Here's the list of things TO DO - most of them require some code changes:
  • Make sure your app looks good enough on as many as devices as possible, i.e. different screen sizes, tablets, etc.
  • Verify if your app needs all the permissions specified in the Android Manifest file. Usually the less permission requests the more likely user will install the app.
  • Enabled fullscreen mode in your activities:
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);

  • Add some statistics to your app in order to track what's going on. I would recommend going with Google Analytics - it's quite simple and quick integration.
  • If your app has free version you should consider adding some ads. Again would recommend a Google product - AdMob. You can show banner ad and fullscreen ad on application start or close. Take it easy to not annoy users with "aggresive" ads :)
  • Add 'Rate this app' and 'Send feedback' buttons. It is important that your app has good rating and also you are aware of user feedback.
  • If you have some other apps consider adding section / tab 'More apps' to show them. It's an easy and quick way to advertise your work.
  • Reduce number of third-party libraries used by your project. In general if there are things that are relatively easy to do without library then it's better to do it manually.
  • Add the version information / details aka changelog. Users would like to know what has changed since the last version.
  • Add settings / preferences and help "features" to your app.
  • Set the preferred installation place of your app to external storage (e.g. SD card) - in the manifest file set:
 android:installLocation="preferExternal"
  • Remove all error loggers and logging and try and catch errors in risky places to not show the exceptions to the end users.
  • Verify values for min, max and target SDK version specified in the manifest file.
  • Run Android LINT tool to check for warnings and error. Sometimes it may not be possible to clean them all but try to fix as much as you can.
  • Enable ProGuard in project.properties:
proguard.config=proguard.cfg

ProGuard will reduce size and optimize your code. If it's enabled it runs automatically when exporting signed APK. You may want to run full set of tests after it just in case if everything is working the same as in the original version.
  • Use zipalign tool to "zipaligned" the APK
zipalign -f -v 4 src.apk out.apk
  • Test the app on some real devices - emulators are there but you know it's never the same :)
  • Prepare good description and promotion text together with some screen shots.
  • Finally rate your own app - yeah why not starting with some good rating :)
    You can also ask friends and family to download and rate the app.
OK that's quite a long list but still worth doing :)
 
By the way let me know in the comments what else you are doing or recommend to do before  publishing and mobile app. Any ideas and comments welcome :)

Thanks!

Google Plus One button in the Android app

The quickest way to let users to like your Google page is to provide 'plus one' button.

There is a simple way you can do it withing Android APP.

1. In layout XML of your target activity add the followin:

<com.google.android.gms.plus.PlusOneButton
        xmlns:plus="http://schemas.android.com/apk/lib/com.google.android.gms.plus"
        android:id="@+id/plus_one_button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        plus:size="standard"
        plus:annotation="inline" />


 
2. In the activity class:
private PlusOneButton plusOneButton;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    plusOneButton = (PlusOneButton) findViewById(R.id.plus_one_button);
}


protected void onResume() {
    super.onResume();
    plusOneButton.initialize(GOOGLE_PLUS_URL, PLUS_ONE_REQUEST_CODE);
}



Where:
- GOOGLE_PLUS_URL is the address of the Google page to be +1'd
- PLUS_ONE_REQUEST_CODE is the request code to use when opening the +1 activity. This value must be an unsigned 16 bit integer.

That's all you need.


Spring locale configuration for web application

Hi,

Today we will set up spring configuration for locale based settings for web application in order to support many languages

Basic XML config for you servlet usually named servlet_name-servlet.xml:
1. Definite message source bean.
<bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
  <property name="basename" value="classpath:/locales/messages" />
<!-- do not use system locale by default as it can differ based on OS-->
  <property name="fallbackToSystemLocale" value="false" />
</bean>


Property basename definies path and name of your "messages" files, i.e.:
- messages // default text to use
- messages_es  // text in Spanish
- messages_pl // text in Polish
etc.

2. Define locale resolver and support automatic locale changes:
<bean id="localeResolver" class="org.springframework.web.servlet.i18n.SessionLocaleResolver">
  <!-- <property name="defaultLocale" value="en" /> you can specify default here -->
</bean>


3. Interceptor responsible for resolving locale:
<mvc:interceptors>
  <bean class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor">
    <property name="paramName" value="ln" />
  </bean>
</mvc:interceptors>


Remember to specify MVC namespace:
xmlns:mvc="http://www.springframework.org/schema/mvc"

So for example let say you have an URL /yeyeyey.html which returns English content.
If you go to /yeyeyey.html?ln=es it should return content in Spanish.

Of course you will need to  have messages defined in messages_es file.

Now if you want to access specific message in the code you can do it through the MessageSource bean:
@Autowired
private transient MessageSource messageSource;


messageSource.getMessage("text.key.value", null, locale);

where current locale you can get from Spring context:
LocaleContextHolder.getLocale();

If you want get the correct text value on the UI (i.e. JSP) you can use <spring:message> tag:
<spring:message code="text.key.value" text="PUT_DEFAULT_VALUE_HERE" />

That's it.


Linux: how to connect Sony mobile phone via USB

Hi there,

Recently I was trying to connect my Sony Xperia S mobile phone (with Android OS) to my PC running on Linux (Ubuntu)....
... and guess what no success :(


So here are the steps TO DO in order to successfully connect your mobile phone:
1. Connect to the  USB port and run lsusb command to see the devices.
2. Note the vendor ID for you device.

3. Install additional packages:
sudo apt-get install libusb-dev
sudo apt-get install gmtp

4. Download libmtp-1.1.6 extract and build:
cd libmtp-1.1.6
./configure --prefix=/usr
make
sudo make install
 

5. Copy libmtp rules to rules.d:
sudo cp 69-libmtp.rules /etc/udev/rules.d/

6. Edit the rules:
Add something similar to below with correct product id specified earlier in lsusb
# SONY XPERIA SL
ATTR{idVendor}=="0fce", ATTR{idProduct}=="4169", SYMLINK+="libmtp-%k", ENV{ID_MTP_DEVICE}="1", ENV{ID_MEDIA_PLAYER}="1"
ATTR{idVendor}=="0fce", ATTR{idProduct}=="0169", SYMLINK+="libmtp-%k", ENV{ID_MTP_DEVICE}="1", ENV{ID_MEDIA_PLAYER}="1"


Save and close.

7. Reload the rules: sudo udevadm control --reload-rules

8. Connect device again to USB port and run GMTP to connect.

You should now be able to transfer files to and from your device.

Also if you are an Android developer you can now debug your application directly on your mobile phone :)

Hope that will be helpful for someone :)




Hit counter for JSP servlet web application

Hola!

There are many free nice and simple hit counters available out there. However they are not totally free as you will also have some kind of hidden url to the external website/resource within it.

If you want you can implement such counter yourself within JSP file in a no time :)

One of the simplest way is to just do it within the JSP file with no core java work:
1. Use application attribute within your JSP file:
<%
    Integer counter = (Integer) application.getAttribute("counter");
    if(counter == null || counter == 0) {
       counter = 1; // initial value
    } else {
       counter += 1;
    }
    application.setAttribute("counter", counter);
%>



2. Then just show it: <%= counter%>

Instead of storing it in application attribute you could declare it as a static field. As you know static fields in programming are generally shared across all instances of an object.

Note that we are not storing the actual value of the counter in the datastore. It means everytime the application server is restarted the counter returns to the initial value.

It shouldn't be a problem because usually you restart an  app when you want to upload a new version anyway. In that case you can set the counter to the last known value instead of "1" in the new code.




Linux: release cache memory

Hi!

Sometimes it may be useful to release some of the cache memory under Linux OS environment.

Here is a simple script which does that:
---------
#!/bin/sh
sync;
sudo sync;
echo 1 > /proc/sys/vm/drop_caches;
echo 2 > /proc/sys/vm/drop_caches;
echo 3 > /proc/sys/vm/drop_caches;
sync;
sudo sync;

echo "WOW! I feel good :D"

---------

Save it under preferred name, e.g. cleaner.sh
Run it as a sudo: sudo sh cleaner.sh
That's it!


How to upload web application to App Engine

Hello all,

It's been a while but here I come with another hopefully useful post :)

Ever wondered what you need to do in order to upload your web app to the Google AppSpot (app engine)?

Let's rock!

Assuming you already have an account (if not create one https://appengine.google.com/)
Requirements:
1. Login to your account and create new application - follow on screen instructions and use common sense :)

2. Download official App Engine SDK: https://developers.google.com/appengine/downloads

3. Create appengine-web.xml (next to standard web.xml file):

<?xml version="1.0" encoding="utf-8"?>
<appengine-web-app xmlns="http://appengine.google.com/ns/1.0">
  <application>your_app_name</application>
  <version>1</version>
  <threadsafe>true</threadsafe>
  <sessions-enabled>true</sessions-enabled>
</appengine-web-app>


4. Build the app locally like usual to create WAR file and related app folder (if you WAR does not extract automatically you can extract it manually), e.g.:
/home/user/dev/app-name/target/app-name.war
/home/user/dev/app-name/target/app-name

5. Go to the bin directory of the app-engine SDK home:
cd /home/user/APP_ENGINE_SDK_HOME/bin/

6. Run the appcfg script:
./appcfg.sh update /home/user/dev/app-name/target/app-name/

OR equivalent for other OS

It will prompt you for your registered e-mail and password and that's it. All done :)

In few minutes your application should be available online!

Have fun!