1

I have a link which needs to be shown using webview I have a link which when opened in normal browser say chrome first prompts a dialog box to enter username and password and then goes for the link which has video embedded in it

I have used the code as seen below

import net.rim.device.api.browser.field2.*;
import net.rim.device.api.ui.*;
import net.rim.device.api.ui.container.*;

public class BrowserFieldDemo extends UiApplication
{
    public static void main(String[] args)
    {
        BrowserFieldDemo app = new BrowserFieldDemo();
        app.enterEventDispatcher();
    }

    public BrowserFieldDemo()
    {
        pushScreen(new BrowserFieldDemoScreen());
    }
}

class BrowserFieldDemoScreen extends MainScreen
{
    public BrowserFieldDemoScreen()
    {
        BrowserFieldConfig myBrowserFieldConfig = new BrowserFieldConfig();
        myBrowserFieldConfig.setProperty(BrowserFieldConfig.NAVIGATION_MODE,BrowserFieldConfig.NAVIGATION_MODE_POINTER);
        BrowserField browserField = new BrowserField(myBrowserFieldConfig);

        add(browserField);
        browserField.requestContent("http://www.blackberry.com");
    }
}

But this give Authentication error 401 which might have caused since I hit the link directly ... So how can I add some lines of code to authenticate user in the existing code

user3313210
  • 59
  • 1
  • 9

1 Answers1

0

There are two samples of BrowserField interaction that I suggest you review. One is supplied in the BlackBerry Facebook SDK, which you will find here:

Facebook SDK

You will find a blog about this SDK here:

Facebook SDL Blog

This is not written by BlackBerry but is sort of supported. I have used it, but personally I find it more complicated than I need so instead I recommend you review the Twitter API ME SDK

Twitter API ME

This code has created a single BrowserField enclosing class that to my mind anyway makes it simpler to interact with the BrowserField.

So getting back to your question, how do you achieve this on the BlackBerry? Sorry, I am not answering that specific question. What I am doing is giving you links to two projects that are written to do this, and I suggest you review the code contained in these projects, and so figure it out for yourself.

There are many forum posts on both of these APIs on this and other forum sites. I suggest you search for more information too.

Also the BB developer web site has many helpful articles on the BrowserField, including this one:

Create your first BrowserField

Update

The above is not actually relevant now that you have updated your question.

If I understand correctly, normally you have to enter a user name and password to be authenticated, then you can watch the video. In your case you want the BrowserField to go directly to the video link. This is not working because you have not entered login information.

I am not that familiar with this process, but I suspect that whether you can actually do this or not will depend on the authentication method used by the web site.

If it is standard basic authentication, then I think you might be OK. You can supply a username and password as a header before making the request - see BrowserField addStandardRequestHeaders(...) method. Sorry I can't give you the format that you need to use to supply a header for basic authentication, but I have done it in the past and I think the header required is well documented if you search for it. From memory, you need to Base64 encode the username followed by a semi-colon, followed by the password and add this as an "Authentication" header.

If it is some other authentication, then you need to find out what and if you can add information to the headers that will allow you to bypass the authentication screen.

If you are not familiar with HTTP headers, then you will need to do some research to understand what these are and how they can be used.

if you can't supply the authentication information in a header, then I think you are just going to have to ask the user to login - or move the video to some more public space.

Further Update

The official documentation that describes the headers required for authentication is here:

rfc2617

Perhaps a more readable summary for Basic Authentication, can be found here:

http://en.wikipedia.org/wiki/Basic_access_authentication

You can often make use of the supplied HttpProtocolConstants class to set constant HTTP values, for example the key for this is:

HttpProtocolConstants.HEADER_AUTHORIZATION

and the content will be

"Basic " + 'your Base64 encoded username_semicolon_password characters'

Community
  • 1
  • 1
Peter Strange
  • 2,640
  • 11
  • 11
  • Please check my edited question and lemme know some code lines for the same . – user3313210 Feb 26 '14 at 11:16
  • ok ... Now .. i have used Hashtable userHash = new Hashtable(); userHash.put("admin", "****"); and added one more line browserField.addStandardRequestHeaders(userHash, true); Now this should work rght – Yatin Feb 27 '14 at 05:54