Monday 26 August 2013

Issue with android webview

I was working with android application. I have found an issue in webview component of android. Html is being rendered in web view easily for older versions of android. But in case of android 4.2.2, i have found that it is rendering blank screen in web view.

I have not dig into the issue alot. But i could solve the issue using adding one property in menifest file of my application.


android:hardwareAccelerated="false"
This line disables hardware acceleration.

Tuesday 2 April 2013

Openfire Custom IQ Handler


XMPP is providing plenty of Rosters. That we can use to develop a full fledged chat application. But Openfire is delighting its developers by providing custom plugins development.

I have been needed to add a plugin that would be helpful to search users from the server. On the application side i needed a list of users with some patterns.

I have developed following plugin code for that. This plugin gets installed on server side. It mainly deals with a custom IQ. Whenever application will request for that particular custom IQ. Server will pass flow to this custom plugin.

For developing custom iq. You need to extend IQHandler class. As well need to implement some of the methods from that class to provide your functionality.

public class SearchIQhanlder extends IQHandler { // extend IQ handler class to create a custom iq request
    private IQHandlerInfo info;
    
    public SearchIQhanlder(String moduleName)
    {
  super(moduleName);
  info = new IQHandlerInfo("query", "custom:iq:Search"); // provide a custom unique query signature for your IQ
    }
    
    public IQHandlerInfo getInfo()
    {
 return info;
    }
    
    public IQ handleIQ(IQ packet) throws UnauthorizedException{ // this method will handle the request. all login will go into this method.
 IQ result = IQ.createResultIQ(packet);
 try {
  // if you want to handle specific query. you need to check for its type. I needed this as i have wrote the plugin to provide some information to application. If you are setting some values on server side. You should use set type.
  IQ.Type type = packet.getType(); 
  result.setChildElement("query", "custom:iq:Search");
  Element query = result.getChildElement();
  // conditionally hanlde get or set type of IQ. I was not using set type. So i have make it as "not acceptable"
  if (type.equals(IQ.Type.get)) {
  } else {
      result.setChildElement(packet.getChildElement().createCopy());
      result.setChildElement("coord", "custom:iq:Search#response");    
      result.setError(PacketError.Condition.not_acceptable);
  }
  return result;
 } catch (Exception e) {
  // if you face any issue while processing. You can response back with "bad request"
  result.setChildElement(packet.getChildElement().createCopy());
  result.setChildElement("coord", "custom:iq:Search#response");    
  result.setError(PacketError.Condition.bad_request);
 } 
 return result;
    }
    
    public void initialize(XMPPServer server) {
 super.initialize(server);
    }    
}

Now you need to create one plugin class. That class would be extending plugin class. In that class you need to create one instance of IQ handler class that you have developed. Assign that handler class to IQ router. IQ router is kind bus of openfire that is managing roster requests.

 IQHandler handler = new SearchIQhanlder("SearchIQhanlder");
 IQRouter iqRouter = XMPPServer.getInstance().getIQRouter();
 iqRouter.addHandler(handler);  

On the application side you need to create one new IQ to request for your custom IQHanlder. Following is the example of what i have created.

<iq type='get' id='search' from='"+ Datas.jid.getLittleJid() + "'>
<query xmlns='custom:iq:Search'>
<search>"+ usernamefield.getText() +"</search>
</query>
</iq>

That is all to create a custom IQHandler. It is very easy to create such IQ. As well this would be very helpful for application development.

Let me know if you need any help regarding the same.