Saturday, November 24, 2012

Calling system applications in Android

In my previous posts I have used reading contacts through API calls, however there is an easy method for doing standard tasks by calling system's pre installed apps. In this post I am going to cover the details of how we can call the system apps through intents.

We are going to create a spinner control for providing the user some options and hit a submit button.

Here's main.xml which defines the UI.

 <?xml version="1.0" encoding="utf-8"?>  
 <LinearLayout xmlns:android=""  
       android:prompt="@string/app_prompt" />  

Spinner control requires a string array (application_array) for it's entries which is defined in strings.xml.

 <?xml version="1.0" encoding="utf-8"?>  
   <string name="app_name">callingsystemapps</string>  
   <string name="app_prompt">Choose a application</string>  
   <string-array name="application_array">  

In main.xml we have also have defined onClick method btnSubmitOnClick which is defined in

   public void btnSubmitOnClick (View v)  
     Spinner spinner1 = (Spinner) findViewById(;  
     if (spinner1.getSelectedItem().toString().equals("Browser")){  
       Intent i = new  
     else if (spinner1.getSelectedItem().toString().equals("Dialler")){  
       Intent i = new  
     else if (spinner1.getSelectedItem().toString().equals("Map")) {  
         Intent i = new  
     else if (spinner1.getSelectedItem().toString().equals("Contacts")) {  
       Intent i = new  

Only difference between the four is the passing intent which is as below:


Along with that we are passing parameters depending upon intent type. After that it's just calling startActivity on the intent.

Try running the example and you shall get like this.

Thanks for reading, don't forget to check links page for resources.

Wednesday, November 21, 2012

getActionBar and targetSdkVersion in Android development

Hi All,

Recently I was trying to reiterate Android docs training just to fill in anything I missed previously. There I came across this piece of code:

     // Initialize member TextView so we can manipulate it later  
     mTextView = (TextView) findViewById(;  
     // Make sure we're running on Honeycomb or higher to use ActionBar APIs  
       // For the main activity, make sure the app icon in the action bar  
       // does not behave as a button  
       ActionBar actionBar = getActionBar();  

I tried to put that in a simple hello world example and it worked on an 2.2 emulator, however it failed to run on 4.0 emulator. On debugging it turned out that getActionBar was returning null value. Though there was on-line help available for some other directions it just came to my mind to check AndroidManifest.xml file. There I saw only "android:minSdkVersion="8"" I remembered that there was a target SDK  as well which can be defined. So I checked a project created by eclipse and found the "android:targetSdkVersion="15"" line and added it to "uses-sdk " tag in AndroidManifest.xml and the app started working on 4.0 emulator.

This clears two things, first is that Idea IDE adds only minSDKVersion while eclipse adds targetSDKVersion as well. Which is reflected in new project also but could effect like this.

Second, if you search for getActionBar returning null you get loads of advice but maybe not this. So check if you are having this issue.

Thanks for reading. Thanks for Android guys for creating such a good documentation, which by and large so much better than Facebook developer docs. Only wish Facebook docs were also as clear as the Android docs.

Tuesday, November 20, 2012

Quick tips for improving Java apps performance

"Ever had performance problems? Yeah me too. If my manager screams
“faaaaster” one more time, i will have hearing impairment for the rest
of my life. BTW, did i sense a German pronunciation in all that noise?"

Sunday, November 18, 2012

Nexus 4 unboxing and first impressions

Google’s newest flagship handset, the LG Nexus, 4 is finally upon us. The highly anticipated stock Android smartphone features some of the highest-end specs of any phone currently on the market, but does it manage to satisfy? Stay tuned for a complete review. However, in the meantime, be sure to catch our unboxing and first impressions below.

Saturday, November 17, 2012

Capture the output of var_dump in a string


You are programming in PHP and you have an array variable that you’d like to explore at different execution paths. Of course, the best way is to use a PHP debugger like xdebug or Zend Debugger, but, what happens when you’re too lazy to install a debugger? What happens when you don’t want or can’t install a debugger and you just need to check the content of that array by dumping it in your log file? Well, you might think you’re stuck, but, read on…

Thursday, November 8, 2012

How to change look & feel of NetBeans IDE and application

Standard GUI toolkit of Java is Swing. NetBeans IDE and Platform is written in Swing. It's widely used and accepted. It's cross-platform and it's doesn't look very well under (GTK+) Linux.

Read more here:

Debugging php locally with Zend debugger

My tryst with Facebook app development is taking me to rather not ventured areas of computing.

Latest is debugging php code locally, kindly browse my previous posts to see how to deploy LAMP and create virtual hosts etc.

I was on the lookout of seeing which debugger will suit most on Linux Mint. I found that Zend has a debugger which could be blended with your existing server stack. So I researched and setted it up.

Here is how I did it.

Download the Zend debugger from Zend website here. Select the "Studio Web Debugger" and follow the instructions.

Zend forums has excellent step by step guide on installing the debugger. It can be found here.

Once you have completed the instructions restart your web server.

Now check your error log "/var/log/apache2/error.log", if it has error like following:

"Failed loading /etc/apache2/ cannot open shared object file: No such file or directory"

install libssl0.9.8 using synaptic.

After that I installed PDT for eclipse and tested the debugger connection in "Debug Cnfigurations..." in Run menu. But the connection failed after searching a bit I found that default port for Zend debugger is 10137, which I changed in eclipse.

Now I am able to debug php in eclipse.

Hope you find this useful, thanks for reading, thanks again to guys for creating such useful software's.

Wednesday, November 7, 2012

Deploying a facebook php app locally on Linux

As in my previous post I said that currently I am having a tryst with Facebook apps. Going further I thought of setting up a local environment where I could make changes locally and see them without uploading on heroku website. I find lots of issues which finally got resolved thanks to generous guys on internet. Following their path I am sharing the complete list of instructions I followed to deploy the Facebook app locally here.

First of all you need to create an app on facebook and host it on heroku website following instructions from following link.

Please bear in mind that I chose to deploy the main app locally rather than creating a dev app.

If you find any problem related to ssh keys these commands may help you as they did for me.

 # ssh -vT  

Above command checks whether a secure connections with heroku site is possible or not. If you get any errors try generating a ssh key and submitting it to heroku.

 # ssh-keygen  
 # heroku keys:add ~/.ssh/  

Follow my previous post to create virtual hosts, also don't forget to set facebook app id and app secret in "/etc/apache2/conf/extra/httpd-vhosts.conf" file under VirtualHost tag as below. You can these two from Facebook app site.

 <VirtualHost *:80>  
   DocumentRoot /home/ashish/savefromiad/xxxxxxxxxxxx  
   ServerName mycoolapp-dev.localhost  
   SetEnv FACEBOOK_APP_ID xxxxxxxxxxxxxxxxxx  
   SetEnv FACEBOOK_SECRET xxxxxxxxxxxxxxxxxxxxxxxxxxxxx  

When I tried accessing the virtual site I got a blank page. I tried searching on internet and got this error in apache error.log at "/var/log/apache2/error.log".

 PHP Warning: require_once(sdk/src/facebook.php): failed to open stream: No such file or directory  

When checked the app directory I found that the php sdk was missing so I got that from their git repository.

and copied that under src/sdk of my app local directory.

Still I kept getting permission error so I changed the owner of the directory to www-data as below.

 # chown -R www-data .  

So the permission error vanished, please bear in mind that may have further repercussions but for now things worked for me. I got this help while setting up Joomla! locally so applied this here as well.

But the errors kept coming, this time like this one.

 Uncaught exception 'Exception' with message 'Facebook needs the CURL PHP extension.  

So checked the php manual and from user notes installed curl and php extension as below.

 # sudo apt-get install curl libcurl3 libcurl3-dev php5-curl  

Even after this it didn't worked so I restarted my laptop and lo!!! it worked.

Later I noticed that this local running is not same as on heroku.Will see how to resolve and add.
Update 2:
In the mean time you could try heroku eclipse plugin It greatly eases the change, commit, and test phases. Off course you would be running your actual master code

Thanks for reading and thanks to guys for helping me out. Please don't forget to share if you find this helpful.

Tuesday, November 6, 2012

Creating virtual hosts in apache2

Recently I was trying to create a facebook app and thought of creating virtual hosts on my machine where I possibly could test it. Here is the steps I took to create two virtual hosts on my Linux Mint.

First install LAMP stack if you don't have it already

 sudo apt-get install lamp-server^ -y  

(Don't forget the caret '^')

Now define the following in "/etc/apache2/conf/extra/httpd-vhosts.conf" file

 NameVirtualHost *:80  

If the above mentioned file does not exist create it.

Also make sure that "/etc/apache2/httpd.conf" has this line

 Include conf/extra/httpd-vhosts.confconf  

NameVirtualHost needs to be all conf files only once so make sure that "/etc/apache2/ports.conf" has got it commented out.

 #NameVirtualHost *:80  

Now create the definition of virtual hosts like below.

 NameVirtualHost *:80  
 <VirtualHost *:80>  
    DocumentRoot "/var/www"  
    ServerName localhost  
 <VirtualHost *:80>  
   DocumentRoot "/var/www/mysite"  
   ServerName mysite.localhost  

One also need to create the entry in "/etc/hosts" like this.    localhost    mysite.localhost  

Now you should be able to test your sites.

Thanks for reading and much credit goes to guys on internet for helping out specially on

Sunday, November 4, 2012

Most useful wordpress plugins for any website

Recently I've been into foray of creating websites. Though I liked joomla for saving time I decided upon wordpress. In a couple of weeks I have come across many plugins which are very useful for any wordpress site hence am sharing them here. Please keep in mind though tht it depends on your hosting site whether you would be able to take full benefit of these plugins.

1. Akismet

Fighting spam for you and free for personal use. It needs and API key which is easy to create and deploy into your site.

2. BackUpWordPress

Regularly backups your website so you free of worry about your site corruption.

3. bbPress

Very easy to create forums which looks native to your website.

4. Better WP Security

Tightens your website security though depends on your website hosting company not all options are enforcing.

5. CloudFlare

Free CDN for your site again your website hosting site support is needed to enable it.

6. Disqus Comment System

Professional looking commenting system for your site, has community and some other nice feature as well.

7. Facebook

Needless to say anything about this.

8. Google Analytics

Helps adding Google Analytics to your site in easy way.

9. Google XML Sitemaps

Generate site maps which are easy to be submitted in Google webmaster and bing.

10. Gravatar Favicon

An avataar system to be used for any site integrating nicely into wordpress.

11. gtrans

Makes it super easy to make your site translated on the fly to cater to a larger audience.

12. Jetpack by

Many useful options such as site stats, mobile themes, integration etc. Very useful.

13. Newsletter

As the name says handy newsletter creation.

14. PayPal Donations

Easy to use donation plugin to get support for your siite.

15. Scripts Gzip

Compress your scripts to fasten your website.

16. Sociable

Adds lots of social networking site sharing to your posts.

17. Ultimate TinyMCE

Ultimate editor to create posts if not wrong used by as well.

18. W3 Total Cache

Lot of caching options to make your website faster. Again depends on your website.

19. Wordfence Security

Integrates antivirus and firewall in your website.

20. WordPress Gzip Compression

Enable gzip compression to make your website load faster.

21. WordPress Importer

Import your posts from other worpress site.

22. WordPress Ping Optimizer

Save your site from being tagged as ping spammer.

23. WordPress SEO

Search engine optimization tools tightly integrated into your site.

24. WP-o-Matic

Automated posting into your website.

25. WP-Optimize

Optimize your database.

26. WP-PageNavi

A better menu navigation system.

27. WP Code Highlight

Highlight your code snippets into colorful coding.

28. WP

High images are bottleneck into site performance make it faster with this plugin.

29. WPtouch

Make your website ready for touch screen based devices like iPhone etc.

30. Yet Another Related Posts Plugin

Automatically creates related posts entries for your posts.

31. BAW Post Views Count

Adds how many times a post has been viewed.

I've given very short intros of these plugins however you can click on links and see the details.

Please do not forget to share if you liked this.