How to read .docx on Android with Apache Poi - android

I have .docx file in assets folder and use this part of code to to read it
AssetManager am = context.getAssets();
InputStream is;
is = (InputStream) am.open("amaretti.docx");
XWPFDocument hdoc=new XWPFDocument(OPCPackage.open(is));
and jars for this are:
poi.jar
poi-ooxml.jar
But shows me an error:
08-27 18:16:31.660: I/dalvikvm(23221): Could not find method org.openxmlformats.schemas.wordprocessingml.x2006.main.CTDocument1$Factory.newInstance, referenced from method org.apache.poi.xwpf.usermodel.XWPFDocument.onDocumentCreate
I guess some jar or classes are missing.
Any suggestion would be useful.
Thanks in advance

You're missing some jars. In order to read Word 2007 files using POI you also need the following libraries (they're all available in the archive you download from the official Apache POI site):
poi-ooxml-schemas (the one you're getting the error about)
xmlbeans
dom4j
stax
According to the official website, dom4j and stax are no longer needed but I found I had problems when I didn't add them.
Unfortunately, you're bound to discover that adding all of these libraries will result in a Dalvik dex error (an Android classes.dex can hold up to 64k of method declarations, which you will cross). The "official" explanation for this is that POI is simply not designed for Android. Unfortunately I have not been able to find an easy, manageable solution for that problem (there have been attempts, some partially successful, of porting POI to Android, but they're too cumbersome for my taste). I solved that problem by sending the Word 2007 files to a remote server, converted them to the old format and returned to the mobile device to be opened by POI.

Related

Any library to read mdict *.MDX files in android?

I have a .mdx file that infact is a dictionary database (some android apps like bluedict can read its data).
I have used Daemon.tools but it could not open it.
I was looking for any library or sources which helps me to read MDX dictionary files in Java, I have found some resources already such as KnIfER/mdict-java but it does not work in Android Studio (it has errors on accumulation_blockId_tree.xxing(new myCpr(position,1)).getKey().value line and it is connot resolve symbol 'value'). Does any one knows a good source about these files and possible libraries which could be used for it?.
Well, actually this is my java project.
the error mentioned is just a problem of jdk version. you can add <> parentheses after myCpr and convert return of xxing to type myCpr<Integer,Integer> .
But now, I have very much reduced usage of rbtree and use more binary list searching.have a look there.

System can't find specifed path ndkbuild in android

I want to build an ocr app in android.For that i am using tessaract library.I am following this turorial ocr tutoial it says follow below steps
Download the NDK & extract to C:\ drive-Done
Set NDK Path & Android SDK path to PATH variable in Enviorment Variable.-Done
Download tessaract library and extract it to C:-Done
open command line & go inside tessract folder ibn downloaded library.-
Write ndk-build-Not Done
When i write ndk-build it says the system can't find the specified path.
Please tell me how to resolve this issue.I have already spent lot of hard time on this.
Thanks in advance.
If you re-read the link you posted, you may notice this line from the author:
Attention: if you fail at any of the above steps, you are not ready for this shit yet. Better grab an introduction to android development course, read a book, then come back to this tutorial. You’ll just waste time and nerves and you’ll bitch about it in the comments that this crash, this doesn’t work. (PS. no, I will not send you the source code on your email, stop spamming k thx.)
You should seriously consider his advice - working with the Android NDK only gets more difficult from here.
You're probably getting that error message because cmd couldn't find the ndk-build program, which is located inside the root of android-ndk-r10e. Possible causes:
You made an error when editing your PATH variable - make sure each file path is separated by a semicolon and that you provided the full path to your NDK install.
Your PATH is too long - the max length is 260 characters. See this page for more info. tl;dr: prefix \?\ to your PATH to get around this length limit.
You had cmd open when you set the variables - try restarting the cmd
program or even restarting your machine.

How to load android libraries when running binary files?

So, I have this executable binary file that references some libraries. When I try to run it with runtime.exec(), it gives me an error on the error stream saying:
link_image[1891]: 7176 could not load needed library 'XXX.so' for 'YYY' (load_library[1093]: Library 'XXX.so' not found)CANNOT LINK EXECUTABLE
I have the XXX.so library but I have no idea where I should place it relative to the binary YYY. I want this to work for unrooted device.
Btw, I'm not very good with the building stuff in general, so if you think there's something wrong I did when I built the binary, feel free to point that out.
You have two choices
build this binary with -static flag, I think this is the best way
you can use dlopen to load this library dynamicly, such as
void *g_handle = NULL;
g_handle = dlopen("/system/lib/libskia.so", RTLD_LAZY);
_skFT_Init_FreeType = dlsym(g_handle, "FT_Init_FreeType");
/**do something */
dlclose(g_handle);
Please see https://stackoverflow.com/a/12934668 where yours truly proposed wrapper to set LD_LIBRARY_PATH in a generic way. You can use ProcessBuilder with modified environment, too. See https://stackoverflow.com/a/8962189/192373.

Why SDL_Window is an incomplete type?

I am porting to SDL2 and the Android platform a C++ game that uses SDL 1.2. Everything went well so far except for one thing: when I try to access the fields of SDL_Window, the compiler tells me
error: invalid use of incomplete type 'SDL_Window {aka struct SDL_Window}'
I think my installation of SDL may be faulty. I have compiled SDL 2.0.0 from the source found on libsdl.org using the folloing command:
ndk-build NDK_PROJECT_PATH=. APP_BUILD_SCRIPT=./Android.mk APP_PLATFORM=android-18
Then, I have copied the freshly built libSDL2.so into $ANDROID_TOOLCHAIN/sysroot/usr/lib and the files in the include/ directory in $ANDROID_TOOLCHAIN/sysroot/usr/include/SDL. These files are given to CMake and referenced by the game's code. I managed to convert every SDL calls and now I am stuck with this SDL_Window problem.
I did a quick search in SDL's source code and found that SDL.h includes SDL_video.h which contains a typedef SDL_Window on struct SDL_Window. Then I searched for this struct and did not find anything except in the original source archive, in a file named src/video/SDL_sysvideo.h. Since it is not a file of the API, I doubt I have to include it in my code.
So, how to find a definition of SDL_Window in SDL2, for Android (if this is relevant)?
It appears that the problem is a lack of knowledge of SDL 2's API. Let's remember that one does not access the fields of struct SDL_Window: there are functions to get the size and the flags of the window, such as SDL_GetWindowFlags and SDL_GetWindowSize.
So the problem is absolutely not related to the installation of the SDL or to Android builds. Sorry for the waste of time, people of the Web.
I would expect that you are expected to only deal in pointers to SDL_Window objects, and not actually put a full SDL_Window object on the stack.

Problems using the EWS Java API on Android

I am trying to use the EWS Java API v1.1.5 (http://archive.msdn.microsoft.com/ewsjavaapi) in an Android application, and have run into a number of issues.
I downloaded the source, and followed the instructions provided to compile the EWS Java API in Eclipse. In those instructions you are told to download and
add the following pre-requiste jar file dependencies:
commons-codec-1.4.jar
commons-httpclient-3.1.jar
commons-logging-1.1.1.jar
jcifs-1.3.15.jar
I did this, and followed the build instructions with produced the following jar files:
EWSAPI-1.1.0.jar
EWSAPIWithJars-1.1.0
Next, I built a brand new Android application, added the appropriate permissions to the manifest, and then added the following source to the primary activity's OnCreate:
ExchangeService service = new ExchangeService();
ExchangeCredentials credentials = new WebCredentials("emailaddress", "password");
service.setCredentials(credentials);
try
{
service.autodiscoverUrl("emailaddress", this);
}
catch (Exception e)
{
e.printStackTrace();
}
I first tried running this application with the EWSAPI-1.1.0.jar file as a dependency. When I did that, I obtained the following fatal error:
Uncaught handler: thread main exiting due to uncaught exception
java.lang.NoClassDefFoundError:
org.apache.commons.httpclient.MultiThreadedHttpConnectionManager at
microsoft.exchange.webservices.data.ExchangeServiceBase.(Unknown
Source) at
microsoft.exchange.webservices.data.ExchangeServiceBase.(Unknown
Source) at
microsoft.exchange.webservices.data.ExchangeService.(Unknown
Source) at
com.meshin.exchange.ExchangeDiscoveryActivity.onCreate(ExchangeDiscoveryActivity.java:40)
From what I've researched, it seems like this error is being generated because Android comes with the Apache HttpClient 4.0, which doesn't appear
to have the MultiThreadedHttpConnectionManager class anymore.
If I instead remove the EWSAPI-1.1.0.jar, and instead use the EWSAPIWithJARS-1.1.0.jar file as a dependency, I get the following error:
VFY: unable to resolve static method 908: Ljavax/xml/stream/XMLOutputFactory;
newInstance()Ljavax/xml/stream/XMLOutputFactory;
VFY: dead code 0x0008-006a in L
microsoft/exchange/webservices/data/EwsUtilities;.formatLogMessage
(Ljava/lang/String;Ljava/lang/String;) Ljava/lang/String;
VFY: unable to find class referenced in signature (Ljavax/xml/stream/XMLStreamWriter;)
And then eventually...
FATAL EXCEPTION: main java.lang.VerifyError:
microsoft.exchange.webservices.data.AutodiscoverService at
microsoft.exchange.webservices.data.ExchangeService.getAutodiscoverUrl(Unknown
Source) at
microsoft.exchange.webservices.data.ExchangeService.autodiscoverUrl(Unknown
Source) at
com.meshin.exchange.ExchangeDiscoveryActivity.onCreate(ExchangeDiscoveryActivity.java:41)
I am assuming because now I am including the HttpClient 3.1 jar and it is conflicting with the HttpClient 4.0 jar included with the Android libraries.
My question is if there is a way for me to use the EWS Java API in an Android project without having to re-write the parts of it which reference
HttpClient 3.1-specific things which are no longer in 4.0.
You can use microsoft's EWS api for android by doing the following steps,
download the source code available in the URL,
http://archive.msdn.microsoft.com/ewsjavaapi
EWSJavaAPI_1.1.5.zip
Make the changes to above api to work for JDK 1.4 in eclipse like remove override annotations e.t.c
Download source code of javax.* package available in below URL,
http://www.java2s.com/Code/JarDownload/jsr173/jsr173_1.0_src.jar.zip
Download source code of stax api available in below URL,
http://dist.codehaus.org/stax/distributions/stax-src-1.2.0.zip
Keep all the sources under the single java project in eclipse
Open the project explorer and select the package which are starts with "javax" and rename to your company name eg: com. Note: Eclipse will ask for all the naming contexts will change then click OK.
Export all the java sources to one single jar file.
Then You good to go to use the jar in Android application with out any problems.
I used the same way explained above and it worked in android application 100% perfectly.
This isn't a useful answer but I've also been struggling to look at the EWS API over the last couple of weeks, with no success.
The main issue I've found is it references a lot of the javax APIs which aren't on Android. There's a hack you can find that explains how to "re-class" these but I've not got it working yet; in addition, the DnsClient references some namespaces that jarsearches only return for rt.jar - the main runtime. And including this in an Android app would just be crazy!
Before finding the API I was trying to use KSOAP to communicate with EWS but again ran into problems - you need to be able to do NTLM and SSL and I couldn't find any way of combining all these with KSOAP in any simple way.
The EWS API looks the way to go (why re-invent the wheel) but getting it working on Android looks very tricky (if not impossible)
Please check this library for the solution

Categories

Resources