Blackberry 5.0 - BrowserField handle link clicked

喜夏-厌秋 提交于 2019-11-29 07:49:19

Override handleNavigationRequest() of ProtocolController like

ProtocolController controller = new ProtocolController(browserField) {
    public void handleNavigationRequest(BrowserFieldRequest request) throws Exception {
         /* 
         Here you get the redirection link using 
           request.getURL() 
         and do what you want to do 
          */
      // to display url in browserfield use
      InputConnection inputConnection = handleResourceRequest(request);
      browserField.displayContent(inputConnection, request.getURL()); 

    }
};

browserField.getConfig().setProperty(BrowserFieldConfig.CONTROLLER, controller);

Use the following class that was I used

public class CacheProtocolController extends ProtocolController{
    public CacheProtocolController() {
        super(browserField);     
    }

    /**
    * Handle navigation requests (e.g., link clicks)
    */
    public void handleNavigationRequest(final BrowserFieldRequest request) throws Exception {
        UiApplication.getUiApplication().invokeAndWait(new Runnable() {
            public void run() {
                // TODO Auto-generated method stub
                Logger.debug("*******URL*******",request.getURL() );
        });
    }

    /**
    * Handle resource request (e.g., images, external css/javascript resources)
    */
    public InputConnection handleResourceRequest(BrowserFieldRequest request) throws Exception {
        return super.handleResourceRequest(request);
    }
}
pranavjayadev

I have solved this problem using the following class:

public class CacheProtocolController extends ProtocolController{
    private SparseList sparseList = null;
    private int imageIndex ;
    private int click = 0;
    private BrowserField browserField = null;

    public CacheProtocolController(BrowserField browserField,SparseList sparseList,int imageIndex ) {
        super(browserField);
        this.sparseList = sparseList;
        this.imageIndex = imageIndex;
    }

    /**
    * Handle navigation requests (e.g., link clicks)
    */
    public void handleNavigationRequest(final BrowserFieldRequest request) throws Exception {
        UiApplication.getUiApplication().invokeAndWait(new Runnable() {
            public void run() {
                Logger.debug("*******URL*******",request.getURL() );
                String requestUrl = null;
                requestUrl = FileManipulations.replaceAll(request.getURL(), "file:///SDCard/BlackBerry/pictures/", "../");
                Logger.debug("*******requestUrl*******",requestUrl );
                Enumeration enumeration = sparseList.elements();
                while (enumeration.hasMoreElements()) {
                    final News news = (News) enumeration.nextElement();
                    if(news.getDetailsURL().equalsIgnoreCase(requestUrl)){
                        if(click == 1){
                            click = 0;
                            UiApplication.getUiApplication().pushScreen(new DetailedNewsScreen(news.getImageURL() , imageIndex));
                        } else
                            click++;
                    }
                }
            }
        });
    }

    /**
    * Handle resource request (e.g., images, external css/javascript resources)
    */
    public InputConnection handleResourceRequest(BrowserFieldRequest request) throws Exception {
        return super.handleResourceRequest(request);
    }

}

And in the MainScren use the following

browserField = new BrowserField();
browserField.getConfig().setProperty(BrowserFieldConfig.CONTROLLER, new CacheProtocolController(browserField,List,index));
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!