I having trouble improving my webview. I want there to be a page once the app opens were the user can set the url that the webview is permanently going to. It sounds very simple but I'm having a hard time.
mb you can first show dialog, where user should enter url, and this url set to web view
or start another activity, when user enter url
Create UrlActivity.java, where in onCreate you will do following thing.
take URL to be shown as a user input in EditText.
while firing intent to next activity, set that URL in intent's putExtra.
get this extra string in next activity using
String url = getIntent.getStringExtra("key of your urlstring");
and load this url in your webView.
Related
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.
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.
I'm currently programming an app where you should enter a text which is stored. The text should be able to be loaded in the app (maybe another activity) then.
It should be able to be used this way:
task.execute(new String[]{city,lang});
Is this makeable?
Thanks
You can use an Edittext on your first Activity on which user can type something.You can get that "something" programmatically in the same activity as a string.Now if you want to avail that string to another activity then you can use an Intent from the first activity to the second activity which will avail that string in the second activity.
my android app is simple client for web site. It opens site's url, using JavaScript and DOM enters username and password (predefined) and clicks "Log in" button. It uses WebView class.
Question: how during that process I could show some "ajax" loading image instead of showing webweiv on the same activity?
THank you!
You can set a WebViewClient to your webview and use the callbacks onPagestart and onPageFinished to show the progress.
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.