I'm trying to show a preview of URL with jsoup in android.
But my concern now is that I can not decide which image to show in preview. What I want is to show the website image, such as the "F" logo for Facebook, "t" logo for Twitter.
So, can anyone help me with this problem?
I guess you are looking for favIcon.
a favIcon might be in following ways-
like
<head>
<link rel="icon" href="http://example.com/image.ico" />
</head>
or
<head>
<link rel="icon" href="http://example.com/image.png" />
</head>
or
<head>
<meta content="/images/google_favicon_128.png" itemprop="image" />
</head>
For fist 2 types-
Connection con2=Jsoup.connect(url);
Document doc = con2.get();
Element e1=doc.head().select("link[href~=.*\\.(ico|png)]").first(); // example type 1 & 2
String imageUrl1=e1.attr("href");
Element e2 = doc.head().select("meta[itemprop=image]").first(); //example type 3
String imageUrl2=e2.attr("itemprop");
then load the imageUrl in ImageView.
Related
I looked into this solution history.pushState does not update url for "share ..." button on mobile Chrome.
I tried this snippet,
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link rel="canonical" href="http://localhost:3000">
<title>Test Website</title>
<script src="./jquery.min.js"></script>
</head>
<body>
Hey shan <br> <br>
<button id="btn">Click me</button>
<script>
$(document).ready(function () {
$('#btn').click(function () {
history.pushState({urlPath:'/'}, "/", "/1234?name=shan&color=87878");
});
});
</script>
</body>
</html>
This is working even without changing canonical url too. With the above code if i click the native share button in android chrome browser the string http://localhost:3000/1234?name=shan&color=87878 gets copied.
But in my actual website the same is not happening. The only change over there is Router.replace from nextjs. The approximate snippet looks like this
buttonClick = Router.replace(...)
The problem is when user clicks a button Router.replace is called with the params and everything works except the native share copies only the url http://localhost:3000/1234 not the query string.
But the querystring gets copied when i use the copy button or edit button on the browser.
I am not sure how to approach this problem, what could be the issue? Is any meta tag could block copying the queryparam?
How to share icon,text,url of the app as shown in the above image? Icon should be sent from drawable, I have tried all the shareintents.putExtras() and etc.. nothing is working for me.
Short answer: This isn't your job, it's the shared-to app's job.
Explanation: Facebook created a protocol called Open Graph, which apps like Facebook and Whatsapp use to get info about the what image to be displayed and what text to show.
To be able to have something like your included picture, you'd have to first own the website you are sharing links to, then you'd have to include this meta data in your html:
<html prefix="og: http://ogp.me/ns#">
<head>
<meta property="og:title" content="Text to be displayed." />
<meta property="og:type" content="video.movie" />
<meta property="og:url" content="Possibly a deep link to your app." />
<meta property="og:image" content="Image to be displayed."
/>
...
</head>
...
</html>
Finally in your android app you have to share a link to this website, possibly deep-linking into your app.
I am trying to post a link to FB in Unity using the FB SDK.
First I used the example given
FB.FeedShare(
null,
new Uri("https://developers.facebook.com/"),
"title",
"caption",
"description",
new Uri("https://imgur.com/a/IUwesX7"),
null,
HandleResult);
This works perfectly - link gets posted and has a preview picture (take from the first link). In fact, the link works so well that clicking on the pic opens MY app even though the page has no meta tags pointing to my app! How does that happen?
However, when I replace the links with my own it doesn't work:
FB.FeedShare(
null,
new Uri("http://anykey.co.il/deeplinks/duckduckduck.html/"),
"title",
"caption",
"description",
new Uri("http://anykey.co.il/deeplinks/feature.png"),
null,
HandleResult);
The link works ok but I don't get a preview picture. I get a placeholder with the name of my site. The placeholder is clickable and opens my app on my device but there is no pic
This is my html:
<!DOCTYPE html>
<HTML xmlns="http://www.w3.org/1999/xhtml"
xmlns:fb="http://ogp.me/ns/fb#">
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8">
<TITLE></TITLE>
<meta property="al:android:url" content="duckduckduck://story/1234">
<meta property="al:android:package" content="il.co.anykey.games.duckgames.duckduckduck">
<meta property="al:android:app_name" content="DuckDuckDuck">
<meta property="og:title" content="Duck Duck Duck" />
<meta property="og:type" content="website" />
<meta property="og:image" content="https://static.xx.fbcdn.net/rsrc.php/v3/ye/r/lWB96Z8sFtt.png" />
<STYLE TYPE="text/css">
body{font-family:Verdana,Geneva,sans-serif;font-size:16px;line-height:1.4em;color:#333;background-color:White;}
</STYLE>
</HEAD>
<BODY>
<A><IMG SRC="feature.png"></A>
<H1></H1>
<HR>
</BODY>
</HTML>
This is what I see when posting from my app:
Even stranger, if I copy the HTML from the FB link and put it on my site I get no picture.
What am I missing here? Does my website need to be authorised or something?
After burning many hours it turned out that removing the "/" from the end of my Url solved the problem.
Not sure why that is but now it is all working well.
Actually I want to load complete site from internet link but i want to load css files from mobile (means not from internet). Because I want to load all page faster using internal local css file.
Example :
<!DOCTYPE html>
<html lang="en">
<head>
<link rel="stylesheet" href="dist/css/bootstrap.min.css" />
<link rel="stylesheet" href="dist/css/font-awesome.min.css" />
</head>
</html>
So Here I want to Load "bootstrap.min.css" and "font-awesome.min.css" from mobile memory only.
My Android Code :
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
String url = "http://www.MySiteName.com/";
view = (WebView) this.findViewById(R.id.webView);
view.getSettings().setJavaScriptEnabled(true); // Enable JavaScript Support
view.setWebViewClient(new WebViewClient()); // Links open or Navigate in same webView not in Browser
view.loadUrl(url);
}
Please put CSS in assets folder, and refer to CSS by relative path, and load HTML to WebView by loadDataWithBaseURL() method:
if your css file name is mycss.css
StringBuilder data = new StringBuilder();
data .append("<HTML><HEAD><LINK href=\"mycss.css\" type=\"text/css\" rel=\"stylesheet\"/></HEAD><body>");
data .append(tables.toString());
data .append("</body></HTML>");
webView.loadDataWithBaseURL("file:///android_asset/", data .toString(), "text/html", "utf-8", null);
thank you
Because the two other answers are just copy pastas and I happened to have the same issue I will help you with my solution:
You need to specify the file path in the head section of your html file.
Pay attention to the part after href
<!DOCTYPE html>
<html lang="en">
<head>
<link rel="stylesheet" href="file:///android_asset/bootstrap.min.css" />
<link rel="stylesheet" href="file:///android_asset/font-awesome.min.css" />
</head>
</html>
I just can't get my head around why the other posters just copied and pasted and didn't even read what you were trying to tell them.
I hope this helps.
Be aware that your resources folder can be named differently.
I'm trying to access the data inside the assets/css from an external HTML file.
The process goes like this:
<html>
<head>
<meta name="viewport" content="target-densitydpi=device-dpi, width=device-width, height=device-height, user-scalable=yes" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>ola</title>
<link rel="stylesheet" type="text/css" href="file:///android_asset/css/main.css" />
<link rel="stylesheet" type="text/css" href="file:///android_asset/css/sch.css" />
<script type="text/javascript" src="file:///android_asset/css/ethan.js" />
<script type="text/javascript" src="scripts/allinone.js" />
</head>
<body>
<input id="btnTest1" name="button" type="button" style="height:0px;width:0px;" />
</body>
</html>
So here the thing is that, I'm actually calling the HTML file using a link (since the HTML file is not locally present). But main.css, sch.css and ethan.js are locally present in the assets/css folder.
What I'm trying to do is to load the allinone.js which is obviously external and the other three files into the which are internal and run the script.
I found "file:///android_asset/css/main.css" but it looks like it doesn't work.
Please help....
I would be curious to know more about the use case here. My understanding is this:
You're loading an externally hosted HTML file into an Android Webview
You need to overlay some local styles/scripts, which can't be hosted on the external site along with the HTML (presumably because you're generating them dynamically).
If that's so -- and given that the logical approach you conceived of using the file:// URI does not work -- there would seem to be two options, each making use of the webView API:
Load the HTML file from the remote source, modify it, then set it as the webView's source. Locate the tag of the remote HTML and inject your local JS / CSS inline there.
Make use of the 'loadUrl' WebView method to inject your CSS/Javascript dynamically (this seems unnecessarily complicated if #1 is an option). For example:
mWebView.loadUrl("javascript:injectJavascript(js)");
where the parameter 'js' is some inline Javascript that you load within your Android code, and injectJavascript is a method in the remote HTML file that actually inserts it into your DOM. Take an analogous approach to insert your CSS ...
Admittedly these approaches are a bit hackish. Ideally you would use a custom method of the WebView class like 'addCssToDom' or something, but as far as I can see, no such methods are available.