for some time, I have been observing that modern android apps(Telegram) use a new way to open urls in the app. By default, the apps I have made, use ACTION_VIEW and the external browser open the url. These apps now manage that intent with a kind of in-app browser witch adapts to the same style. Any idea of what its?
sample
Those are Custom chrome tabs.In app browser.instead of using webview to open your Url, you are going to customize your chrome browser,to look alike your app.you can modify the toolbar tab color as per your app theme .You could give enter and exit animation like fragments transition.So the user wouldn't feel a big transition from your app to browser.For implementation details check this link https://developer.chrome.com/multidevice/android/customtabs
For security reasons also it could be useful,as because you are not going handle those url on you own or inside your app(there might be some security issues with JavaScript)
This is done with WebView. You will find the documentation very interesting https://developer.android.com/reference/android/webkit/WebView
This is achieved by WebView in an Activity that displays web pages. Instead of
Uri uri = Uri.parse("https://www.google.com/");
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);
You will load the page by calling:
webviewObj.loadUrl("https://www.google.com/");
You can check the official document which describes the whole process. Basic Usage of WebView has been described in this blog which is easy to comprehend and implement.
do the following:
String url = "http://www.example.com";
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(url));
startActivity(i);
try this it helps you.
Related
I'm a web developer. I'm currently developing android application on Android Studio using WebView which access my website as an android application. One of my webpage contains many external links. My goal is to make the android application can handle external links like Gmail App does (also like facebook and Line do).
Below is the example of gmail app.
An email contains external link
Link clicked, then application open a new activity acts like a browser without leaving Gmail application
Any idea how to make it?
It is pretty simple. You have to use Chrome Custom Tabs as suggested by Gergely as well in comment. Below is the small functional code that will help you to achieve this.
First add this dependency to your build.gradle(Module:app)
compile 'com.android.support:customtabs:23.4.0'
Second add below function to your code and simply pass string URL to it.
private void redirectUsingCustomTab(String url)
{
Uri uri = Uri.parse(url);
CustomTabsIntent.Builder intentBuilder = new CustomTabsIntent.Builder();
// set desired toolbar colors
intentBuilder.setToolbarColor(ContextCompat.getColor(this, R.color.colorPrimary));
intentBuilder.setSecondaryToolbarColor(ContextCompat.getColor(this, R.color.colorPrimaryDark));
// add start and exit animations if you want(optional)
/*intentBuilder.setStartAnimations(this, android.R.anim.slide_in_left, android.R.anim.slide_out_right);
intentBuilder.setExitAnimations(this, android.R.anim.slide_in_left,
android.R.anim.slide_out_right);*/
CustomTabsIntent customTabsIntent = intentBuilder.build();
customTabsIntent.launchUrl(activity, uri);
}
Rest it will take care itself. Since Chrome Custom Tabs can customised so lot can be done like you can add menu to toolbar. For detailed information you can visit official documentation from Google itself here.
Hope it will help you to start with :)
I want to show an image in my Sony Smarwatch Sample project. How can I add a link to an external URL? The URL has to be shown in my device not in the SmartWatch. My code is the following, with this my image is shown in the layout:
Bundle iconBundle = new Bundle();
iconBundle.putInt(Control.Intents.EXTRA_LAYOUT_REFERENCE, R.id.thumbnail);
iconBundle.putString(Control.Intents.EXTRA_DATA_URI,
ExtensionUtils.getUriString(mContext, R.drawable.thumbnail_list_item));
¿How can I add a event to this bundle? I want to go to an external url. How can I add a link to my Preference Class?
I am not totally sure I understand what you are asking, but if you want to be able to click on something on the watch and have it launch a url you can use this code:
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://play.google.com/store/apps/developer?id=Sony+Mobile+Communications"));
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
ctxt.startActivity(intent);
If you want to launch the preference settings screen for your app you can do something like this:
Intent intent = new Intent(ctxt, HelloLayoutsPreferenceActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
ctxt.startActivity(intent);
This should work in the Hello Layouts sample project. The context is passed in the control extension constructor so you should be able to grab it from there. Please let me know if this is not what you were asking.
I want open the android browser, and set the html data on it. I do not want to use webview control. How can I do that?
Try the following:
String URL= [url];
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(URL));
startActivity(intent);
You can save the html file locally on the SD and give the url to it.
Good Luck
Not specific to android, but to generic morden browsers:
You can make entire document into a long string of URI, and then locate that to show the original document. See http://en.wikipedia.org/wiki/Data_URI_scheme.
Someone provides a handy web-based tool to convert any document into Data URI string:
http://www.dopiaza.org/tools/datauri/
The size limit varies among the specific web browsers.
Hi
I want to write an app to call default browser and redirect to a designated url.
Any suggestion to 1)call the default browser, 2)redirect to a designated url.
Thanks
you just want to launch an ACTION_VIEW intent with the Uri of the webpage as your data element :
Intent httpIntent = new Intent(Intent.ACTION_VIEW);
httpIntent.setData(Uri.parse("http://www.bbc.co.uk"));
startActivity(httpIntent);
To open the default browser use an Intent with the action VIEW. To tell the browser which page to load us the data-part of the Intent.
Example:
Intent browse = new Intent(Intent.ACTION_VIEW, Uri.parse("http://stackoverflow.com"));
startActivity(browse);
Since this is a basic task in Android you might want to read some basics about Intents in Android.
I execute the following code:
Uri uri =
Uri.withAppendedPath(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
imageIdStr); Intent intent = new
Intent();
intent.setAction(android.content.Intent.ACTION_VIEW);
intent.setData(uri);
activity.startActivity(intent);
which opens the image viewer activity but I don't want to see the navigation arrows as well as the items in the menu. I only want the zoom controls. Is it possible to have it like that ?
That depends on the application that's actually displaying the image. On Android 2.0 and older, it's probably the Gallery app. On many Android 2.1+ apps, it's probably CoolIris' gallery. If the user has one of the many gallery apps from the market installed, it's up to those apps. I highly doubt there's a standardized extra to control that.
If you're really concerned about what the image display looks like, then you should handle that yourself. If you're really just trying to display an image (and maybe add pinch-zoom support?), it's a reasonable scope.