In android, i am trying to open an html file from sdcard path to show it in web view . As my path starts with some special character( eg. sdcard/11/#directoryName/index.html), it is not opening that html file . can any one help me to resolve this issue?
Thanks
The character "#" is not a legal character in an URL path. The "#" character is used to reference an "anchor" within a document. Usually used like this:
http://my.host.com/path/to/url#part-of-document
You could try to URL-encode that character in the path so that it doesn't get interpreted as an anchor reference, like this:
file:///storage/sdcard/11/%23directoryName/index.html
but it may be that you will need to read the file yourself and pass the data to the WebView instead.
Related
I am creating a folder in android's internal storage by using the below code-
File file=new File(this.getFilesDir()+"/"+FolderNamefromEditTextasString);
file.mkdir();
I am getting the folder name from an Edit Text. I want to know how to check if the folder name is valid or not before creating. I don't exactly know which characters should not be there in a valid folder name. I first would like to validate the string from edit text. Also, I don't like to have spaces and "." in folder name string.
use regular expressions to test if it is something valid. I guess you can allow numbers, letters - and it can be ok not to allow special characters (such as ë,# and other)
something like [0-9a-zA-Z/-+]+ should work just fine
I download file from many URLs.
e.g.:
https://myhost/sh/8n0wli4v5895jom/AAB2E0WA2fetPTLjWtYe5HjAa/00019.jpg
https://myhost/sh/8n0wli4v5895jom/AAB2E0WA2fetPTLjWtYe5HjAa/0001.jpg
https://myhost2222/sh/8n0wli4v5895jom/AAB2E0WA2fetPTLjWtYe5HjAa/00019.jpg
https://myhost2222/sh/8n0wli4v5895jom/AAB2E0WA2fetPTLjWtYe5HjAa/0001.jpg
Now I need to save all download files to Android local folder.
But what is file name must be?
I think to create file name from URL.
But URL contain forbidden characters for file name. So... I thing to create hash (SHA-1) from url or maybe convert URL to Base64.
Is this a good solution?
The idea is to save the file with filename the same as the URL it was downloaded from. This way it will be easy to find it (reconstruct the filename) in the filesystem (cache) given the URL.
So suppose we have this URL: https://myhost/sh/8n0wli4v5895jom/AAB2E0WA2fetPTLjWtYe5HjAa/00019.jpg
Invalid characters are : and /, so a simple String.replaceAll will remove these characters
String filename = "https://myhost/sh/8n0wli4v5895jom/AAB2E0WA2fetPTLjWtYe5HjAa/00019.jpg".replaceAll(":\\/\\/|\\/", "");
This filename variable equals to: httpsmyhostsh8n0wli4v5895jomAAB2E0WA2fetPTLjWtYe5HjAa00019.jpg
Of course if you want you can instead of completely removing those characters, to replace them with a valid character e.g. -.
make names from time:
String carTime = String.valueOf(System.currentTimeMillis());
String fileName=carTime.substring(carTime.length() - 4, carTime.length())+".jpg"
I think a base64 is good solution if you want a reversed way.
URL => FILENAME (encode base64)
FILENAME => URL (decode base64)
If you just replace : and \ by nothing you lose information and can't
retreive the orginal URL from FILENAME
If you use a Hash fonction you lose information too (and you add a very very very small risk of collision)
Maybe today you don't need a reversed solution but tomorrow for debug you don't know ;-)
Be carrefull : Filenames have limit length
EDIT :
Another solution is to simply create intermediate directory (replacing only https:// by your local temp folder)
I am using salesforce for my android app in backend.
and somewhere while using SOQL, I am getting response something like this :
Article_FileNames":"Template.doc"
Article_FileContentTypes":"application/msword
Article_FileBodys":"/services/data/v35.0/sobjects/Hub_Knowledge_Articlekav/xxxxxxxxxxx/Article_FileBodys
ArticleNumber":"000001010
LastPublishedDate":"2015-12-09T20:34:48.000+0000
Now i am not getting, how I can let the user open the file named "Template.doc" on click.
How to open this file ?
is there any file path or id which will linkify this filename ?
Any help will be appreciated!
The only file types that are directly available from outside of your Salesforce instance are images, which are made so by setting the Externally Available Image flag on the Document object itself.
If you need to work with other file types, you're going to have to build them yourself to facilitate their download by the end user. This can be done by querying your instance for the Document, which will contain the Base64 encoded file contents (Body), that array's length (BodyLength), the file extension (Type), and also the file name itself (Name).
Given what you provided, your SOQL query would look something like :
SELECT Body, BodyLength, Name, Type FROM Document WHERE Name = 'Template' AND Type = 'doc'
From there, you should have everything you need to build the file in memory.
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.
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.