Reputation: 43
I am trying to open a social link within my app on a button click listener.i want to open it within app i do not want to open a webview for it. I dont find any way to open that link.the url for this link is come from server also i dont understand how to load url on a button click.Please provide any solution.
this.linkedin.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String URL=sbobj.getLinkdin_url();
Intent intent=new Intent(getApplicationContext(),LinkedinProfile.class);
intent.putExtra("URL",sbobj.getLinkdin_url());
startActivity(intent);
}
});
sbobj
is the object of class from which I am trying to get url.
"linkdin_url": "https://in.linkedin.com/in/kumaraguru"
this is the url,which i have to get from server.
Upvotes: 1
Views: 1849
Reputation: 5299
If you are ok with adding new activity then you better use this. I will beautiful Webview out of box and very easy to use but yes you need to add one more activity. Here is the link: FinestWebView. See the beautiful UI of this:
Upvotes: 0
Reputation: 2535
Custom Tab layout will work for you.
https://developer.chrome.com/multidevice/android/customtabs
this.linkedin.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String URL = sbobj.getLinkdin_url();
CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();
CustomTabsIntent customTabsIntent = builder.build();
customTabsIntent.launchUrl(this, Uri.parse(URL));
}
});
Upvotes: 4
Reputation: 195
You can try this
this.linkedin.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String url = sbobj.getLinkdin_url();
if (url.contains("https://in.linkedin.com")) {
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(url));
startActivity(i);
} else {
Utils.ShowToast(context, "Url not Valid!");
}
}
});
Upvotes: 0