onPageFinished equivalant in custom chrome tab to get url - android

I am implementing Custom chrome tab in one of my app .
I have initiated Custom chrome tab intent with
startActivityforResult.
When user back press from action bar or bottom menu activity's onActivityResult gets called but intent is null.
I want to receive url as we do in onPageFinished(view, String url) in case of WebViewClient.
Thanks in advance .
Thanks in advance

It is not possible to get the URL from the navigation callbacks in Custom Tabs. This is to protect the user privacy when navigating.
If you have control over the page that is being loaded, it would be possible to redirect the user to an URL using a Custom schema that is handled by your application, and pass the information you need in that URL.
If you do not control the page, the solution would be to provide a custom action button or use the bottom toolbar, that triggers a PendingIntent and starts your Activity. You would then use Activity.onNewIntent / Activity.getIntent to retrieve the URL, that will be available as the Intent data. This example shows how to do it with a BroadcastReceiver.

Related

Is it possible to get the current URL of a Android Chrome CustomTab in real time?

I am using Chrome customTabs in android and I need to get the current URL in real time, which means once it changed, trigger a callback.
I found two things that may be useful.
CustomTabsCallback.onNavigationEvent(int navigationEvent, Bundle extras);
It can return a navigation event code when URL changed or refreshed.
How to get Url change from CustomTabsClient
BroadcastReceiver + PendingIntent can get url by clicking.
https://gist.github.com/YeWang0/d344618bf8ac269dc3c39fa45214cf8b#handle-actions-using-a-broadcastreceiver
I am thinking, is it possible to fake a click event when onNavigationEvent() called, then I should be able to get the URL in real time.
It is not possible
In order to safeguard the user's privacy when navigating, the URLs are not automatically sent to the host app through the navigation events.
It is possible to get the URL as a result of the user clicking on the custom action button or on one of the buttons on the secondary toolbar.
This piece of code shows how to setup the custom action button and this code shows how to retrieve the URL inside a BroadcastReceiver, invoked by the CustomAction.

Suggestion of using Activity or Fragment or Dialog

I have an Activity, in which I've used WebView.
I am loading given server URL in it. Its all working fine. There are several pages in it which I can navigate through.
In one of the page of Website (server URL), for example 'Product Description', there is a button named "Try This", which is basically to try the product that user can have a try.
When user touches this button, using JavaScriptInterface, I am calling one JavaScript function and getting the image URL and loading this in another Activity.
But when I presses the back button from this child Activity, its gets redirected to the very first page of the WebView i.e list of products, but not the last page that I visited.
How can I fix the back button navigation for this?
Second scenario, I've used is using custom dialog, in which I am able to load the picture successfully. What I want is the ability to have user interaction in this custom dialog. For Example, is it possible that user can drag, move, zoom, resize and capture picture from camera all in this custom dialog box? How can I achieve this, if it's feasible?
Third case, which I don't know exactly is to use Fragments.
Please suggest me how can I overcome this situation.
It would be best if I can use Activty without having back button navigation issue from the child activity.
lazy solution is to override the onBackPressed.
public void onBackPressed (){
if (webview.isFocused() && webview.canGoBack()) {
webview.goBack();
}
}

how to open google.navigation intent inside android view or fragment

Is it possible to open google navigation intent inside my appln (in a view like a fragment). I would like to display other info to the user as the navigation is going on.
No the intent starts an activity which means you leave your app completely and go to the google navigation app

How to create a custom browser in android

Hi i am having a activity with a button, on click of the button it has to load a custom browser in a new activity not the default browser of android. and i need a way to exclude the history of the browser such that on back press it comes back to the previous activity without navigating to previous website. I am new to android and any ways to do this
You are probably just talking about the WebView
Link to the official tutorial
Note :
This onKeyDown(int, KeyEvent) callback method will be called anytime a
button is pressed while in the Activity. The condition inside uses the
KeyEvent to check whether the key pressed is the BACK button and
whether the WebView is actually capable of navigating back (if it has
a history). If both are true, then the goBack() method is called,
which will navigate back one step in the WebView history.Returning
true indicates that the event has been handled. If this condition is
not met, then the event is sent back to the system.
You can start by putting a WebView in an activity.
If you want to have a view which can browse the web in your app then make use of the WebView view.
Else if you want to create your own custom browser, then you have to make use Web engine WebKit present in the library layer of the android.

Android: open URL in a new window WITHOUT leaving app

Is there anyway I can open web when user clicks on TextView, in a new window without leaving the app, it's like in iPhone when you click on an URL it shows you a new browser window, but there is a BACK button you can click to go back to previous screen?
Thanks!
You can create your own Browser Activity with a WebView in the layout. Inherently it is not going to have any of the functionality of the actual stock browser app though, other than displaying the web page. You'll have to add in the forward / back buttons if you want them and anything else you need. If you don't need any of that stuff then you should be fine with just a plain WebView. When you press the back button on the device it should close that activity and take you back to the one you started in.
Edit:
To get callbacks from a WebView when the user clicks a link you can use the WebViewClient shouldOverrideUrlLoading() method, like this:
wv.setWebViewClient(new WebViewClient() {
/* On Android 1.1 shouldOverrideUrlLoading() will be called every time the user clicks a link,
* but on Android 1.5 it will be called for every page load, even if it was caused by calling loadUrl()! */
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url)
{
Log.i(myTag, url);
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(url)) ;
startActivity(i);
return true;
}
});
For a TextView its a little bit more work, You'll have to make your own copy of the Linkyfy class and use a TransformFilter to make the links behave however you want them to. Check out this question for an example Android Linkify both web and #mentions all in the same TextView
Maybe a WebView is what you want.

Categories

Resources