i am trying to use pdfbox lib into my android app but im getting
java.lang.NoClassDefFoundError: org.pdfbox.pdmodel.PDDocument
this error .as i'm developing commercial app i can not use other Lib like itext .So my question is can we use PDfBox in android.
here is my code:-
PDFParser parser = null;
String parsedText = null;
PDFTextStripper pdfStripper;
PDDocument pdDoc = null;
COSDocument cosDoc = null;
PDDocumentInformation pdDocInfo;
try {
f =new File(Environment.getExternalStorageDirectory()+File.separator+"Download"+File.separator+"Services.pdf");
if(f.exists()){
System.out.println("---------exists-----------");
}else{
System.out.println("------NOT----exists----------");
}
parser = new PDFParser(new FileInputStream(f));
} catch (Exception e) {
System.out.println("Unable to open PDF Parser.");
System.out.println("-----------------------error|"+e.toString());
}
try {
parser.parse();
cosDoc = parser.getDocument();
pdfStripper = new PDFTextStripper();
pdDoc = new PDDocument(cosDoc);//here i'm getting exception
//pdDoc = PDDocument.load(f, false);
parsedText = pdfStripper.getText(pdDoc);
} catch (Exception e) {
System.out.println("-----------------------error|"+e.toString());
System.out.println("An exception occured in parsing the PDF Document.");
e.printStackTrace();
try {
if (cosDoc != null) cosDoc.close();
if (pdDoc != null) pdDoc.close();
} catch (Exception e1) {
e.printStackTrace();
}
}
System.out.println("Done.");
System.out.println("-----------------------parsedText|"+parsedText);
using PDFBox 0.7.3 jar
It seems that PDFBox is depending on awt and swing classes that are not available on Android devices.
Therefor you can not use PDFBox on Android.
NoClassDefFoundError is thrown when the JVM can't load a class.
As the javadoc says
Have you included the pdfbox library on classpath during compilation?
If you only need to extract text from PDF document in Android , then use this https://github.com/RatheeshRavindran/PDFBoxLight
I recently did the porting of PDFBox to Android but please note that this still in Beta.
Related
I'm developing phonegap app and right now I'm trying to write a plugin to convert .amr files to .mp3 files. I'm using JAVE to do this conversion and while it's working on desktop it fails on android with this exception:
java.io.IOException: Error running exec().
Command: [/data/data/<my_package>/cache/jave-1/ffmpeg, -i, /sdcard/<my_filename>.amr, -vn, -acodec, libmp3lame, -f, mp3, -y, /sdcard/<my_filename>.mp3]
Working Directory: null Enviroment: null
I'm trying to do conversion like this:
private void convert(String input_file, CallbackContext callbackContext){
File input = new File(input_file);
File output = new File(input_file.replace(".amr", ".mp3"));
Encoder encoder = new Encoder();
EncodingAttributes encodingAttributes = new EncodingAttributes();
AudioAttributes audioAttributes = new AudioAttributes();
audioAttributes.setCodec("libmp3lame");
encodingAttributes.setAudioAttributes(audioAttributes);
encodingAttributes.setFormat("mp3");
try{
encoder.encode(input, output, encodingAttributes);
input.delete();
callbackContext.success("finished");
}
catch(Exception e){
callbackContext.error(e.getMessage());
}
}
I found this answer and I understand why error happens but the answer doesn't provide any solution. Is there a way to get this working in Phonegap project? Do I need to package ffmpeg library together with plugin and copy it to correct folder when app invokes the plugin?
/data/data/<my_package>/cache/jave-1
Stucked with same problem. For now i found that there is problem with file ffmpeg permissions. JAVE trying to set them, but for some reason it not working.
So i set this permission by myself like this:
Process process = null;
DataOutputStream dataOutputStream = null;
try {
process = Runtime.getRuntime().exec("su");
dataOutputStream = new DataOutputStream(process.getOutputStream());
dataOutputStream.writeBytes("chmod 0755 __AppCachePath__/jave-1/ffmpeg\n");
dataOutputStream.writeBytes("exit\n");
dataOutputStream.flush();
process.waitFor();
} catch (Exception e) {
} finally {
try {
if (dataOutputStream != null) {
dataOutputStream.close();
}
process.destroy();
} catch (Exception e) {
}
}
After this File permission problem goes away.
I was wondering if it is possible to find all the libraries that are included in the Android project programmatically. I am writing a library which would need info about other libraries included in the project. Any help much appreciated.
i have made a simple function, just make a call to this function when you want to have the details.
public static void checkLibrary(){
try {
Log.e(" i am in","checklibrary");
Set<String> libs = new HashSet<String>();
String mapsFile = "/proc/" + android.os.Process.myPid() + "/maps";
BufferedReader reader = new BufferedReader(new FileReader(mapsFile));
String line;
while ((line = reader.readLine()) != null) {
if (line.endsWith(".so")) {
int n = line.lastIndexOf(" ");
libs.add(line.substring(n + 1));
}
}
Log.e("Ldd", libs.size() + " libraries:");
for (String lib : libs) {
Log.e("Ldd", lib);
}
} catch (FileNotFoundException e) {
// Do some error handling...
} catch (IOException e) {
// Do some error handling...
}
}
For future readers.
You may use Mike Penz's AboutLibraries library
Benefits
Allow to list external, internal libraries used in your project
Out of box activity or fragment with list of libraries used in your project.
Using Android NDK is it possible (from native C-code) to get a list of loaded .so libraries? I am looking for an Android-version of the iOS functions _dyld_image_count()/_dyld_get_image_name().
Also is it possible to get the library name of the .so containing a specific function (on iOS this function is dladdr()).
You can read and parse /proc/self/maps file. It contains which address each shared object loaded for your application. self will help your application to read its own info.
nm command line utiliy which is also available in Android NDK can show you which symbols are available from certain shared object files. You can look how it is implemented and try to utilize the same libraries, but it won't be trivial.
Yes you can Get this Here is Sample
try {
Set<String> libs = new HashSet<String>();
String mapsFile = "/proc/" + android.os.Process.myPid() + "/maps";
BufferedReader reader = new BufferedReader(new
FileReader(mapsFile));
String line;
while ((line = reader.readLine()) != null) {
if (line.endsWith(".so")) {
int n = line.lastIndexOf(" ");
libs.add(line.substring(n + 1));
}
}
Log.d("Ldd", libs.size() + " libraries:");
for (String lib : libs) {
Log.d("Ldd", lib);
}
} catch (FileNotFoundException e) {
// Do some error handling...
} catch (IOException e) {
// Do some error handling...
}
try this This Might Help You
http://www.isco.com/webproductimages/appBnr/bnr1.jpg
I've used a website to see the metadata of a image. In this website, it shows all info of image. I want to know how to get the "Title" tag of above image in android.
I found here the similiar question for iOS only: How to get image metadata in ios
However I don't know how to get "Meta data" of image on android. ExifInterface only gives some informations. But I'm unable to get "Title" tag with it.
Can you provide any code snippet for get meta data in android for image?
Download metadata extractor from the link given here ...... click to download the library
choose the version 2.5.0.RC-3.zip
Extract the jar Folder
and import jar into libs folder in your poject and then execute the below code
try {
InputStream is = new URL("your image url").openStream();
BufferedInputStream bis = new BufferedInputStream(is);
Metadata metadata = ImageMetadataReader.readMetadata(bis,true);
for (Directory directory : metadata.getDirectories()) {
for (Tag tag : directory.getTags()) {
System.out.println(tag);
}
}
}
catch (ImageProcessingException e){}
catch (IOException e) {}
If you want to retrieve meta data information about an image ExifInterface is what you are looking for. Here is a quite good example of how this interface is used: http://android-er.blogspot.com/2009/12/read-exif-information-in-jpeg-file.html
But if you want to retrieve information of an online image I'm afraid it's not yet possible.
If you want to retrieve metadata from image in Android project, then you can do that with the help of: https://github.com/drewnoakes/metadata-extractor
Implement this in your gradle using
implementation 'com.drewnoakes:metadata-extractor:2.12.0'
Complete code is as follows
private static String getImageMetaData(Uri image1) {
try {
InputStream inputStream = FILE_CONTEXT.getContentResolver().openInputStream(image1);
try {
image1.getEncodedUserInfo();
Metadata metadata = ImageMetadataReader.readMetadata(inputStream);
for (Directory directory1 : metadata.getDirectories()) {
if (directory1.getName().equals("Exif IFD0")) {
for (Tag tag : directory1.getTags()) {
if (tag.getTagName().equals("Date/Time")) {
return tag.getDescription();
}
}
}
}
} catch (ImageProcessingException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
} catch (FileNotFoundException e) {
e.printStackTrace();
}
return null;
}
I downloaded a source code from a library for android, compiled it and I got a .jar file, I included into my project and I tried to use it but I always get a java.lang.NoClassDefFoundError, I noticed that in the jar file there are not R$XXX files, I read this post: Android Library Import delete R and tried the solutions but none worked for me.
I made my own simple library and I saw that either, the R files are not included in the jar, I have to add the .class files manually using winrar but I think I am missing something simple, I am using eclipse with ADT.
Thanks to everyone
If you are creating jar files then you should not include r.java,manifeast file in the jar file.
Because the jar wont get complied during compliation and wont create any static integer during compliation time.
In android we have Android LIbrary which is similar to android project but can be included in other projects.
And if still you need to have jar file then just keep class files in jar include all your resource contain in application and from java files you can use the below code to refer the resources during runtime.
That you must use getResourseIdByName(getPackageName(), "drawable", "icon") instead of R.drawable.icon in your code.
Below is the code for getResourceIdByName::
public int getResourseIdByName(String packageName, String className, String name) {
int id = 0;
try {
for (int i = 0; i < Class.forName(packageName + ".R").getClasses().length; i++) {
if(Class.forName(packageName + ".R").getClasses()[i].getName().split("\\$")[1].equals(className)) {
if(Class.forName(packageName + ".R").getClasses()[i] != null)
id = Class.forName(packageName + ".R").getClasses()[i].getField(name).getInt(Class.forName(packageName + ".R").getClasses()[i]);
break;
}
}
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (SecurityException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (NoSuchFieldException e) {
e.printStackTrace();
}
return id;
}