Wednesday, January 3, 2018

Android Open Phone Dialer from Code

There are Two ways to achieve it.

 1) Have to start the dialer via code, without user interaction. 

 You need Action_Dial, use below code it will open Dialer with number specified.

Intent intent = new Intent(Intent.ACTION_DIAL); 

The 'tel:' prefix is required, otherwhise the following exception will be thrown:

java.lang.IllegalStateException: Could not execute method of the activity. Action_Dial doesn't require any permission. If you want to initiate the call directly without user's interaction , You can use action Intent.ACTION_CALL.

In this case, you must add the following permission in your AndroidManifest.xml:

<uses-permission android:name="android.permission.CALL_PHONE">

2) Have user to click on Phone_Number string and start the call. 


You need to use TextView with below property.
android:autoLink="phone" android:linksClickable="true"

This is how you can open EditText label assigned number on dialer directly.
 android:text="+91 22 2222 2222"

Saturday, December 23, 2017

Apply Border color to button on Android

Use the <stroke> element. Add this xml file in res/drawable folder as button_border.xml:

<?xml version="1.0" encoding="utf-8"?>
  <shape xmlns:android=""
    <gradient android:startColor="#FFFFFF" 
       android:angle="270" />
    <corners android:radius="3dp" />
    <stroke android:width="5px" android:color="#ffffff" />

then call this by in layout file


Forcing “portrait” orientation mode for android application

Adding following code segment in AndroidManifest file for each activity, we can force the android application to work only in portrait mode.

Note: Don't apply the orientation to the application element, instead you should apply the attribute to the activity element, and you must also set configChanges as noted below.


Monday, December 18, 2017

Java Interview Question: HashSet vs HashMap


  1. HashSet class implements the Set interface
  2. In HashSet, we store objects(elements or values) e.g. If we have a HashSet of string elements then it could depict a set of HashSet elements: {“Hello”, “Hi”, “Bye”, “Run”}
  3. HashSet does not allow duplicate elements that mean you can not store duplicate values in HashSet.
  4. HashSet permits to have a single null value.
  5. HashSet is not synchronized which means they are not suitable for thread-safe operations until unless synchronized explicitly. 


  1. HashMap class implements the Map interface
  2. HashMap is used for storing key & value pairs. In short, it maintains the mapping of key & value (The HashMap class is roughly equivalent to Hashtable, except that it is unsynchronized and permits nulls.) This is how you could represent HashMap elements if it has integer key and value of String type: e.g. {1->”Hello”, 2->”Hi”, 3->”Bye”, 4->”Run”}
  3. HashMap does not allow duplicate keys however it allows having duplicate values.
  4. HashMap permits single null key and any number of null values.
  5. HashMap is not synchronized which means they are not suitable for thread-safe operations until unless synchronized explicitly. 

Friday, December 15, 2017

How to handle HTTP Header related issue in Apache

By following below steps you can suppress following HTTP Header related security issues in web applications those are hosted in apache web server.
  • Web Browser XSS Protection Not Enabled
  • X-Frame option Header not set
  • X-Content-Type-Options header missing  
  • Incomplete or No Cache-control and Pragma HTTP Header Set

These issues can be handled by placing following lines in httpd.conf of apache web server.

Header set X-XSS-Protection “1; mode=block”
Header set Strict-Transport-Security "max-age=31536000; includeSubDomains; preload"
Header always append X-Frame-Options DENY
Header set X-Content-Type-Options nosniff
Header set Content-Security-Policy "default-src 'self';"

For this mod_hedaers module also need to be enabled. so uncomment the following Load Module line:

LoadModule headers_module modules/

Now doing security audit test again, you can see these issues are handled properly. 

Handling HTTP Header related security issues in Tomcat 8 web applications

The following issues are the commonly occurs in security audit report of any java web applications

  • Web Browser XSS Protection Not Enabled
  • X-Frame option Header not set
  • X-Content-Type-Options header missing  
  • Incomplete or No Cache-control and Pragma HTTP Header Set

Tomcat 8 provides, support for following http header 

  • X-Frame-Options – to prevent clickjacking attack
  • X-XSS-Protection – to avoid cross-site scripting attack
  • X-Content-Type-Options – block content type sniffing
  • HSTS – add strict transport security

To utilize this option we need to follow simple steps. Just uncomment the following lines in Tomcat's web.xml files (\conf\web.xml).


Remember it is not applications individual web.xml files. it is tomcat's web.xml. after uncommenting these lines. restart the tomcat and redo the security audit. you can see the issues are handled.

Friday, October 13, 2017

'gradle' is not recognized as an internal or external command

Following steps need to be followed for fixing: "'gradle' is not recognized as an internal or external command" error.

  1.  Download the zipped file of Gradle from
  2. Unzip them and place them in your Windows machine at any specific location. For e.g. “C:\Program Files\”. 
  3. Click on the Windows button at the left bottom of the desktop. 
  4. Right-click on “Computer” and click on “Properties”. This will open the Control Panel. 
  5. Click on “Advanced System settings” and then click on “Environment Variables” button. 
  6. Click on “New…” button under the “System Variables” section and enter Variable name as ‘GRADLE_HOME’. 
  7. Provide the path of the Gradle file as Variable value, i.e. C:\Program Files\gradle-2.8 
  8. Click OK. 
  9. Select “path” variable under the “System Variables” section and click on “Edit” button. 
  10. Go to the end of variable value and add “;%GRADLE_HOME%\bin” and click on “OK” button. 
  11. Press “Windows + R” and type ‘cmd’. Click OK. 
  12. Type the command “gradle –v” on the command prompt. 
  13. Now the screen displays the version of the Gradle. This means that the Gradle is successfully configured on the given Windows machine.