I am making an app in which I am displaying a PDF file from url on WebView by appending Google Doc url i.e;
String pdf_url = "my pdf url";
webView.loadUrl("https://docs.google.com/gview?embedded=true&url="+pdf_url);
its displaying perfect but my app is in Swedish Language and its a requirement of the app that every word must be display in Swedish Language. The problem is when pdf file is shown its showing copy right and some words by Google in English language. Is there a way to convert these words in Swedish? may be the Google Doc url (https://docs.google.com/gview?embedded=true&url=) has the option to set language value. I can't figure this one out and stuck here. Any type of help would be appreciated.
The current output is shown below in the picture for better understanding
can you try to add "se" or "SE" just before the end of the url : exemple:
www.myUrl.html ===> www.myUrl.se.html
www.myUrl.pdf ===> www.myUrl.se.pdf
Related
Case: User should be able to view and print pdf
My solution: I am opening PDF inside Webview with the help of docs.google.com/gview. Below is my code
Set up Webview
string url = "http://www.africau.edu/images/default/sample.pdf";
string gview = $"https://docs.google.com/gview?embedded=true&url={url}";
mWebView.LoadUrl(gview);
Print PDF
var printMgr = (PrintManager)GetSystemService(PrintService);
printMgr.Print("print", mWebView.CreatePrintDocumentAdapter("print"), null);
Below is the screenshot. As you can see PDF loads just fine
Problem
When I want to print PDF, all the PDF pages are printed in one paper which you can see below
I would appreciate any suggestion, including different library for displaying/printing pdf or suggestion in Java or Kotlin, I can convert them to C#.
I would not print the web page but print the PDF directly as when printing the web page it just sees it as a longer web page and knows nothing about the content.
Use a custom print adapter instead, but instead of drawing a PDF to print you can just use the existing PDF you already have.
See for details https://developer.android.com/training/printing/custom-docs.html
I am creating an android application. I am getting the response from server in json format. I ma parsing the json response. When I get the content it may contain image or video link. How can I check whether image or video link is present in the content and download the corresponding image or video and display it in my application. I am aware f downloading images and displaying them, but I am not aware of how to check for the link.
My response is in the following format:
<p class='para-inside-post'> cool panda <a class='handler_name' href='/#12'>#12</a> </p><img class=\"post-img-tag\" postcreatorid=\"56332edfad441746cbd15000\" src=\"https://image.jpg\" height=\"430px\" width=\"430px\">"
I am parsing the text as shown below:
postContentSplit = Html.fromHtml(content).toString();
Similarly, how can I do the same for images and videos?
All suggestions are welcome. Please help me come out of this issue.
Use Patterns in order to check url validity
Patterns.WEB_URL.matcher(potentialUrl).matches()
It will return True if URL is valid and false if URL is invalid.
I want to develop an android application which takes a particular input from the app and gives it to a website, then the website fetches the result. I want to display this result from the website and display it in the android app. I tried using xml parsing but the website is not a xml based website. The website is http://www.fastvturesults.com/ and the input is a roll number(usn number). Can anyone guide me on how to fecth the result from this site and parse it to the app.
Use JSOUP which extracts datas from website and display the result.
Document document = Jsoup.connect(url).get();
// Get the html document title
String title = document.title(); //get title
Elements description = document
.select("meta[name=description]");
// Locate the content attribute
String desc = description.attr("content");
and so on.
I'm having a slight problem opening a certain URL in the browser. First of all I use the following code to launch the browser:
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(Globals.currentChatURL));
startActivity(Intent.createChooser(browserIntent, "Select browser:"));
Now if I set Globals.currentChatURL to something like http://www.google.com then it opens that site just fine. But my URL is a little more complicated as it contains multiple parameters which are all base64 encoded. Here is an example of how my URL looks:
http://webportal.mysite.com/ChatProgram/chat.php? intgroup=UFYyMA==&intid=UFYyMEZN&hg=Pw__&pref=user&en=U0NPVFQgTUlMTEFS&ee=cGF1bGdAbWFnbmF0ZWNoLmNvbQ==&eq=UFRWRkVI&ec=TUFHTkFURUNI
Now if I use my above code to try and launch this URL it brings me to the Google search page with the following message:
"Your search - http://URLabove ... did not match any documents"
Yet if I copy the URL and paste it into the address box it brings me to the right place. How can I fix this?? The whole point of this is to have the user click the button and the site to launch, not for the user to have to copy and paste the URL manually.
Any suggestions would be greatly appreciated.
Thanks a lot
There is unwanted equal signs in the query part of your http URI. Such signs have a specific meaning as delimiters in the form ¶meter=value.
This equal signs represents padding values (0, 1 or 2) from your base64 encoding.
You can either
remove them because your base64 server decoder won't bother reconstructing them, or
percent encode them (with all other reserved characters).
In android you can use percent encode this way:
String value = URLEncoder.encode("annoying values with reserved chars &=#", "utf-8");
String url = "http://stackoverflow.com/search?q=" + value;
The RFC 2396 is now deprecated but that is what URI.parse() is based on as stated by the documentation:
uriString an RFC 2396-compliant, encoded URI
An exception is thrown when I run this code. If you replace the Hindi characters in the URL with "Hello" it plays the file just fine.
When I load this URL (with the Hindi characters) in a browser it plays just fine.
What's going on?
Here's my code:
MediaPlayer mediaPlayer = new MediaPlayer();
mediaPlayer.setDataSource(getResources().getString(R.string.test));
mediaPlayer.prepare();
Here's the string resource def:
<string name="test">http://translate.google.com/translate_tts?q=आलू</string>
I don't think unicode characters are legal in URLs, unless you encode them. Here's the spec:
https://www.rfc-editor.org/rfc/rfc1738
+1 tdammers is right, you can't have non-ASCII characters in a URI.
You can have them in an IRI, which is what this is:
http://translate.google.com/translate_tts?q=आलू
Browsers typically support IRIs (with some limitations), but many other tools don't (including, apparently, the Android media player). For those tools, you have to convert the IRI to a URI. This is done by:
taking any non-ASCII characters in the hostname part of the address and encoding them using the IDN algorithm;
taking any non-ASCII characters in other parts of the address (like here, the query) and %-encoding their UTF-8 byte representation.
This gives you:
http://translate.google.com/translate_tts?q=%e0%a4%86%e0%a4%b2%e0%a5%82
which should work anywhere. (And paste a URI like this into a browser and typically it'll display it in IRI form with the Hindi in the address bar.)
I have found the solution from other person. You have encode the text first. Then you have to add the encode method in "ie" parameter. For your text if you set the url for mediaplayer as http://translate.google.com/translate_tts?ie=UTF-8&q=%e0%a4%86%e0%a4%b2%e0%a5%82 it will play the desired word.