SASL authentication failed using mechanism DIGEST

I have seen this error while using Smack in my chatting app.

When i try to login my app it failed login every time.

Here is my logCat.

Xmpp==>SASL authentication failed using mechanism DIGEST-MD5: 02-15 10:55:00.385: E/Oxygen(4187): at org.jivesoftware.smack.SASLAuthentication.authenticate(SASLAuthentication.java:341)
02-15 10:55:00.385: E/Oxygen(4187): at org.jivesoftware.smack.XMPPConnection.login(XMPPConnection.java:242)
02-15 10:55:00.385: E/Oxygen(4187): at org.jivesoftware.smack.Connection.login(Connection.java:371)
02-15 10:55:00.385: E/Oxygen(4187): at free_call.chat.oxygen.util.XmppTool.login(XmppTool.java:434)
02-15 10:55:00.385: E/Oxygen(4187): at free_call.chat.oxygen.PresenceService.userLogin(PresenceService.java:818)
02-15 10:55:00.385: E/Oxygen(4187): at free_call.chat.oxygen.PresenceService.xxampServerLogin(PresenceService.java:728)
02-15 10:55:00.385: E/Oxygen(4187): at free_call.chat.oxygen.PresenceService$xampRegistation.doInBackground(PresenceService.java:870)
02-15 10:55:00.385: E/Oxygen(4187): at free_call.chat.oxygen.PresenceService$xampRegistation.doInBackground(PresenceService.java:1)
02-15 10:55:00.385: E/Oxygen(4187): at android.os.AsyncTask$2.call(AsyncTask.java:292)
02-15 10:55:00.385: E/Oxygen(4187): at java.util.concurrent.FutureTask.run(FutureTask.java:237)
02-15 10:55:00.385: E/Oxygen(4187): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
02-15 10:55:00.385: E/Oxygen(4187): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
02-15 10:55:00.385: E/Oxygen(4187): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
02-15 10:55:00.385: E/Oxygen(4187): at java.lang.Thread.run(Thread.java:818)
02-15 10:55:00.385: E/xxamp status1(4187): xxamp server not connected

Answer

i have used below code and it worked for me..

    ConnectionConfiguration config = new ConnectionConfiguration("your_server", port_no);
config.setSASLAuthenticationEnabled(true);
config.setCompressionEnabled(true);
config.setSecurityMode(SecurityMode.enabled);

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
    config.setTruststoreType("AndroidCAStore");
    config.setTruststorePassword(null);
    config.setTruststorePath(null);
} else {
    config.setTruststoreType("BKS");
    String path = System.getProperty("javax.net.ssl.trustStore");
    if (path == null)
        path = System.getProperty("java.home") + File.separator + "etc"
            + File.separator + "security" + File.separator
            + "cacerts.bks";
    config.setTruststorePath(path);
}