Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Developer
Posts: 142
Registered: ‎06-26-2009
My Device: Not Specified

Problem in opening office files

Hi Friends,

 

I am downloading the file from server to some temp location on device. Using JSR211 package classes trying to open it in respective device application viewer.

 

Got success in opening image and txt files, but office files are not opening and it is also not giving any error or Exception.

 

Here is my code snippet:

 

This method i have written in my main appliction class i.e DotApplication and before pushing my first screen i am calling this.

 

 

static void registerApp()
   {
        try
        {
            // This app will be a handler for csv files and will be invoked
            // with ACTION_OPEN.
            String[] types = {
            "application/msword",
            "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
            "application/vnd.ms-excel",
            "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
            "application/vnd.ms-powerpoint",
            "application/vnd.openxmlformats-officedocument.presentationml.presentation",
            "text/csv", "text/plain" };
            String[] suffixes = { "doc", "docx", "xls", "xlsx",
            "ppt", "pptx", "csv", "txt" };           
            String[] actions = {ContentHandler.ACTION_OPEN};   
            //String[] actionNames = {"Open docs"}; 
            //ActionNameMap[] actionNameMaps = {new ActionNameMap(actions,actionNames,"en")};

                        
            // Get access to the registry and register as a content handler.
             Registry registry = Registry.getRegistry(CLASSNAME);       
             registry.register(CLASSNAME,types,suffixes,actions,null,ID,null);
             
        }
        catch (ContentHandlerException che)
        {   
            System.out.print(che.toString());
        }
        catch (ClassNotFoundException cnfe)
        {        
            System.out.print(cnfe.toString());
        }
   }

 This is written in a class from where m trying to open the files

 

 

Registry registry = Registry.getRegistry("DotApp.DotApplication");
            String ext = filename.substring(filename.lastIndexOf('.')+1, filename.length());
            ContentHandler[] handlers = registry.forSuffix(ext);
            
            if(handlers.length == 0) 
            {
                customDialogBox = new CustomDialogBox("No content handler, please download one "+downloadpath, 1);
                UiApplication.getUiApplication().pushScreen(customDialogBox);
            }
            else 
            {
                ContentHandler myHandler = handlers[0]; // should check here to make sure the app can launch - there's a const for that
                Invocation i = new Invocation();
                i.setURL("file:///"+GetFileInfo.downloadpath +"/"+filename);
                //i.setType(myHandler.getContentType());
                i.setID(myHandler.getID() );
                i.setResponseRequired(false);
                try 
                {
                    registry.invoke(i);
                }
                catch (IOException e) {
                    ;
                }
            }

 

 

It opens the image and txt files properly in device viewer but when i try to open any office file everything runs properly without any Exception/Error and stays on the same screen.

And after all process in the end it says in console Smiley SadDotMobile is my app name)

Starting DotMobile
DotMobile already running

 

please friends help me with this, struggling for last 5 hours.

 

Developer
Posts: 1,055
Registered: ‎01-25-2009
My Device: BlackBerry Bold 9650/BlackBerry Torch 9800

Re: Problem in opening office files

It's not an elegant solution but try the following:

 

http://supportforums.blackberry.com/t5/Java-Development/how-to-open-a-word-document-file/m-p/435970#...

Jerome Carty - Follow jcarty on Twitter@jcarty | #webworks-dev / #BlackberryDev on irc.freenode.net | My Apps
Click "Accept as Solution" if post solved your original issue.. Give like/thumbs up if you feel post is helpful
Developer
Posts: 142
Registered: ‎06-26-2009
My Device: Not Specified

Re: Problem in opening office files

Thanks Jerome Carty,

 

The thread which u hav given it helped. what has been done in that thread is, file is dowloaded to the device and then its location is given to brower to open that file..it works but not for all files.

 

If device is having Word To Go for doc,excel,ppt .. it get opens but if it doesn't have it shows this mssg

 

Unsupported meadia type:application/vnd.ms-excel

 

so is there any way i can check in device Word To Go doc is available before giving file path to the browser, similary for other office files.

 

Please any can help with this issue..

 

Thanks.

 

 

 

 

Developer
Posts: 1,055
Registered: ‎01-25-2009
My Device: BlackBerry Bold 9650/BlackBerry Torch 9800

Re: Problem in opening office files

[ Edited ]

I don't know the names of the modules but you could probably try using the ApplicationManager APIs to see if DocumentsToGo is installed.

 

 

int handle = CodeModuleManager.getModuleHandle("DOCSTOGO_MODULE_NAME");
if( handle != 0 ) 
{
    // LAUNCH IN BROWSER
}

 

 

Jerome Carty - Follow jcarty on Twitter@jcarty | #webworks-dev / #BlackberryDev on irc.freenode.net | My Apps
Click "Accept as Solution" if post solved your original issue.. Give like/thumbs up if you feel post is helpful
Developer
Posts: 212
Registered: ‎07-18-2008
My Device: Storm 9550

Re: Problem in opening office files

I am not sure if I understand you correctly. Do you want to call Docs2Go or your own handler? The code looks like you want to open your own, right?

Because of:

  i.setID(myHandler.getID() );
If your problem was solved, please mark answer as "Accepted solution"
If your want to thank, click the "kudo" symbol
___________
visit me: http://mobilejavadevelopment.blogspot.com/
visit the Berlin BlackBerry Developer Group: http://berlinblackberrydevelopers.blogspot.com/
Developer
Posts: 142
Registered: ‎06-26-2009
My Device: Not Specified

Re: Problem in opening office files

Thanks dpreussler,

 

I want to call docs2go but The invocation class should itself call the file viewer depending upon the file type. i dont knw m going in the right direction or not.

 

Developer
Posts: 212
Registered: ‎07-18-2008
My Device: Storm 9550

Re: Problem in opening office files

I just don't understand why you register your own app for office files.

 

Try to dump out the content of the handler array.You are always taking the 1st one. I assume you don't call Docs2go but your own handler (which is in same library, which is already running, which is why you get this message).

 

 

If your problem was solved, please mark answer as "Accepted solution"
If your want to thank, click the "kudo" symbol
___________
visit me: http://mobilejavadevelopment.blogspot.com/
visit the Berlin BlackBerry Developer Group: http://berlinblackberrydevelopers.blogspot.com/
Developer
Posts: 142
Registered: ‎06-26-2009
My Device: Not Specified

Re: Problem in opening office files

thanks dpreussler for ur support,

 

Currently i have dumped all code and using following :

 

                try
                {
                    //Create the invocation request.
                    Invocation invocation = new  Invocation("file:///"+GetInfo.downloadpath +"/"+filename);
                    invocation.setAction(ContentHandler.ACTION_OPEN);
                    invocation.setResponseRequired(false);
    
                    //Use the registry to perform the invocation.
                    Registry registry = Registry.getRegistry("DotApp.DotNetApplication");
                    registry.invoke(invocation);
                }
                catch (Exception ex)
                {
                    System.out.println("Exception: " + ex.toString());
                    Dialog.alert("Please install the doc2go application on your device to preview                   "+filename+" file");
                }

 

This works fine and i got this from KB Article

http://www.blackberry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/800332/800639/How_To_...

Developer
Posts: 212
Registered: ‎07-18-2008
My Device: Storm 9550

Re: Problem in opening office files

So everything is solved? Robot Happy

If your problem was solved, please mark answer as "Accepted solution"
If your want to thank, click the "kudo" symbol
___________
visit me: http://mobilejavadevelopment.blogspot.com/
visit the Berlin BlackBerry Developer Group: http://berlinblackberrydevelopers.blogspot.com/