Downloading a PDFpage to a string - android

Having done some basic tutorials, I started making my first real android app in eclipse. I want this app to check if the text in an EditText matches the text on a PDFpage (this one: http://www.augustinianum.eu/roosterwijzigingen/14062012.pdf (it contains my school's schedule changes)). I've found out how to make the app check if the text in the EditText matches a string (with the method contains()), so now the only thing I need to do is to download all of the text of that PDFpage to a string. But I have no idea how to. Or is there maybe a method which I can check with if a PDFpage contains a certain word without downloading the entire website to a string?
Thank You!

A PDF is not a text-file, it is a binary file. Therefore you should not download the data into a string but into a byte array. Then you must extract the text data from the PDF using some PDF library. In that text you then can search your keyword.
The most interesting part will be to extract the text from the PDF. You may look around this site for other questions which tried the same. Here is a quick search or this.

Related

How can I store a spanned string in sqlite?

In Android, I have an application that handles multiple rich format text fields. I get the description of the text from an xml and create it as an spannable string builder, adding each run and styling it.
Is there a way to store this on sqlite that doesn't imply storing the whole XML describing the paragraph?
I know it can be done in iOS but I haven't found a way for Android.
Thanks in advance for any answers or tips.
Is there a way to store this on sqlite that doesn't imply storing the whole XML describing the paragraph?
I do not know what "the whole XML describing the paragraph" is. You can:
Use Html.toHtml() to generate HTML from a Spannable, or
Roll your own code to convert a Spannable into something that can be stored as a string or byte array

Adding a Resource Bundle Link to load a new Activity

I have a paragraph of text with a url at the end of it. I have the text and link in the strings.xml. Is there anyway to get it to load a new Activity from the strings.xml file? I'm assuming I'll have to break up the paragraph text and link, but thought I'd check.
strings.xml:
The quick brown fox can be found at: http://thequickbrownfox.com\n more text here
I need to change the hardcoded url "http://thequickbrownfox.com" to load a screen inside my app instead of a page on the web.
strings.xml is purely an abstraction mechanism used for string lookup to facilitate multi language support etc; you cannot use it to load activities or do anything else programatically. It sounds like you are actually talking about parsing the url out of a particular paragraph stored within strings.xml and then depending on what that url is, you invoke a corresponding activity.
If this is the case then you can either parse out the url from the paragraph and respond accordingly.
OR
you can store your paragraph as one item in strings.xml and your url as another item and combine them programmatically in your code.
Either approach can be fine depending on what you are doing.

how to add smilies/emotions in my edittext for a notes app in android?

can any one know about how to add/insert emotions/smiles to text(which ever i typed in my edit text for my notes). i have little confusion about if i want to add these smiles of type .png in to edit text type of string, is it possible? and also i have to save these input into sqlite database. normally i know to store string data taken from edit text.
but along with that text i want to also add smiles symbols where ever my cursor placed and to be store in sqlite data base. and get it back to read.
so guys any ideas, most welcome!
Try to use java (i.e. android) spannable method to implement smiley (i.e.) images for that. You will surely get it, search in google for "how to add images/smiley with java spannable method in android?" you will get good idea.
Reading your question the first thing I can think of is Mapping each image to a sequence of letters, for example :) is smiley.png etc. Now your database also has these smaller representation However while reading from the database you can convert those special character sequences to appropriate image.
For simplicity in seraching those Strings You can wrap them in some less used characters i.e. [ or { or <.

Display ® registered trademark symbol in Android v4.0 WebView?

The source HTML string (including the symbol) is coming from the strings.xml resource file, and is destined to be displayed in a WebView. I've tested with this in the resources:
<string name="MY_STRING">®</string>
Using the actual trademark symbol in the resources (®), the projects builds, but when displayed in the WebView it shows as "®" (i.e. an "A" circumflex, followed by the registered trademark symbol) - i.e. two characters are shown, the first incorrect & unwanted.
I see the same result when using the entity reference, ®
Using ® fails, and the project does not build.
This is the code that pushes the string resource into the WebView:
String html = getString(R.string.MY_STRING);
((WebView)findViewById(R.id.terms_web_view)).loadData(html, "text/html", "UTF-8");
I also tried this, but it did not help:
webView.getSettings().setDefaultTextEncodingName("UTF-8");
I pushed the HTML string to Logcat, and it looks fine - it shows the symbol correctly. So if the string is ok, and the WebView is set to use UTF-8, why is the symbol not displaying correctly?
UPDATE
I tested on other devices. I can only reproduce this issue on a Galaxy Nexus on Android v4.04. On a Nexus One v2.3.x, Wildfire S on v2.3.x and a Samsung Tab 10.1 on v3.2, it works fine. I've changed the question title to clarify this is an ICS issue.
String resources are not designed to hold arbitrary HTML, including arbitrary entity references.
You might be able to get an arbitrary entity reference to work if you pre-escape it:
<string name="MY_STRING">&reg;</string>
IIRC, that should decode to ® after your call to getString().
At the end of the day, you need to get ® to WebView. If you cannot determine a way to do that with a string resource, you will need to store this value someplace else.
You are using loadData(html, "text/html", "UTF-8"); This method expect a html string in your variable html. But it is not. Try
String html = "<html><body>My text is ®</body></html>";
for instance.
--updated to have a full html document
And if you store it in a resource file use :
<string name="MY_STRING" formatted="false"><html><body>My text is ®</body></html></string>
This is not and Android developer answer but just something simple if you're trying to text somebody and neither Ⓡ nor ™ aren't available as symbols (like on my LG phone Android 7.0). Just copy those symbols from this message thread and send them in a message to yourself or stuff them in a quick memo. Then you have them readily available for future use.

extracting strings from KML file

I am extracting strings from KML file, if the string contains special character like !, #, #, ', " etc. its using codes like '
I am not able to extract entire string if it is like above, by calling getNodeValue(). It is terminating the string at special character.
<name>Continue onto Royal's Market</name>
If i extract the string i am getting only ""Continue onto Royal". I want entire string as
Continue onto Royal's Market.
How to achieve this ?? If anybody familiar with this please reply to this one.
Thanks
Your problem has nothing to do with KML but is general for XML parsning:
Don't use getNodeValue(), as there is no guarantee in DOM that text isn't actually split over several nodes.
Try using getTextContent() instead.
You might also have to replace entities, as in: node.getTextContent().replaceAll("'","'");
In general I wouldnt use DOM at all for extracting data.
I'd use the XmlPullParser as its simpler to work with - and parses faster.

Categories

Resources