Chrome RE-DIRECT without Opening New Window or Tab - android

Need to get Chrome to RE-DIRECT in the CURRENT TAB-WINDOW and NOT OPEN a New Tab-Window for the URL Re-Direct.
Any clues?
The Code - but opens the RE-DIRECT URL in another Tab-Window:
Private Chrome As Intent
Chrome.Initialize(Chrome.ACTION_VIEW,"http://www.youtube.com")
Chrome.SetComponent("com.android.chrome/com.google.android.apps.chrome.Main")
StartActivity(Chrome)
I have an idea!!!
Is there ANY WAY to CLOSE CURRENT TAB? So nevermind Chrome opens New Tab.

A standard way of redirecting the page using Javascript is by changing window.location:
window.location="http://example.com"

Related

Android 12 open link in Chrome intent

Since Android 12, links can only be opened with one "approved" app.
As of right now I have my app's supported urls defined in AndroidManifest.xml as intent-filter.
Also I have a button in my app that creates an intent to open a link in browser.
With Android 12 limitations though, if I have the url tied to my app, clicking the open in browser button does re-open my app, which is quite an unwanted behavior.
Is there a way to force a url open in chrome (or other browser)?
I checked the android developer documentation but have not found anything about it.
Thank you
You can specify the default browser explicitly as the package to handle your intent:
val defaultBrowserIntent = Intent(Intent.ACTION_VIEW, Uri.parse("http://"))
// This would be Chrome if it's the selected default browser
val defaultBrowserPackageName = packageManager.resolveActivity(
defaultBrowserIntent,
PackageManager.MATCH_DEFAULT_ONLY
)
?.activityInfo
?.packageName
val yourIntent = Intent(context, ...).apply {
package = defaultBrowserPackageName
}

Web intent url getting modifying automatically

I trying to a webpage link so for this I am using following code
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://example.com/privacy"));
startActivity(browserIntent);
when I click on link, it open in web browser and go to proper page, when i press again on app link and open it again web browser its URL get modifying automatically, on second click i get URL like this
"https://http//example.com/privacy" I don't why this is happening
I find bug in my code
my string file had anchor tag attached thats why new url getting added to intent
this ling had bug
<string name="txt_terms_and_conditions"><a href='https://http://example.com/privacy'>By clicking the Send OTP option,\n you agree to our Terms and Conditions</a></string>
so I removed anchor tag so it working normally

Android intent for display url?

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.

Close browser tab from application

Like a parental control application, I have bloacked few websites. As the blocked url is detected its re-directed to about:blank.
Evey thing is working fine, problem arises in Android 4.4 Chrome browser.
about:blank opens in new tab, along with recentaly open tabs.
I want the close all thoes tab. Below is what i have done.
Intent mBrowserIntent = new Intent(Intent.ACTION_VIEW);
mBrowserIntent.setPackage(packageName);
mBrowserIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK|Intent.FLAG_ACTIVITY_NEW_TASK);
mBrowserIntent.putExtra(Browser.EXTRA_APPLICATION_ID , packageName);
Uri uri = Uri.parse(defaultURL);
mBrowserIntent.setData(uri);
startActivity(mBrowserIntent);

Android - Call default browser with and redirect to a designated url

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.

Categories

Resources