React Native: Opening URLs in Android (Equivalent to LinkingIOS.openURL) - javascript

I'm aware that when using React Native to develop for iOS, I have access to the LinkingIOS and WebView modules to work with URLs. Is there any sort of equivalent for Android? All I'm looking to do is open the URL in the device's browser.
I know that the contributors are working on implementing WebView in Android:
https://facebook.github.io/react-native/docs/known-issues.html#views
https://github.com/facebook/react-native/issues/2701
But is there anything I can use in the meantime?
Again, All I need is an equivalent to LinkingIOS.openUrl(url) for Android.

Try this module https://github.com/ivanph/react-native-webintent for opening urls in the default browser.

With the latest release of React Native (0.21), they provide module Linking to handle incoming as well as outgoing web url.
This can work both on Android and iOS without platform specific.

There is IntentAndroid to open URL.
Example
IntentAndroid.openURL(url)
Please refer to official doc for more info
https://facebook.github.io/react-native/docs/intentandroid.html#content

Related

Detect android webview

I have an html-javascript page, and I need to detect whenever it open on web view (Like inside facebook webview, twitter webview, etc.), and if it a webview - display another content.
Note: I do not control the third-party Android apps, so I cannot make changes to their code.
I already found a way to detect an IOS webview (Found it on stackoverflow):
var isIosWebview =/(iPhone|iPod|iPad).*AppleWebKit(?!.*Safari)/i.test(navigator.userAgent)
Now I'm looking for a javascript code that can detect Android web view.
Help?
You can't detect it by only using the user agent string, as any app that uses WebView can set the UA string to anything it wants.
If you still insist on using the UA string, this is the explanation of the official docs: initially, Chromium-based WebView was using .0.0.0 as Chrome version suffix; in the newer versions ; wv was added into the platform part of the UA string. Note that pre-KitKat WebViews didn't have the Chrome part. See older posts about that: Android, webview user agent vs browser user agent
Another hint of WebView involvement is presence of X-Requested-With HTTP header with an application package name. Note that this header is also set by XMLHttpRequest, so you need to look for the actual value of the header.
The statement that WebView doesn't support iframes is not correct.
The info others provided in this thread gave me what I needed to solve this problem in my case. For others, here is the resulting JS regex which represents the detection described in the accepted answer:
/(Version\/\d+.*\/\d+.0.0.0 Mobile|; ?wv|(iPhone|iPod|iPad).*AppleWebKit(?!.*Safari))/i.test(navigator.userAgent)
The regex includes cases for old Android, new Android, iOS versions.
I know how to do it. It is very simple. Because there is an object used by Android web view to trigger functions in its Android app via javascript. So in your js code you can use:
if (typeof Android === "undefined") {
// do something if is NOT a web view
} else {
// do something else if is a web view
}
I needed to detect if the browser was an Android WebView without using the User-Agent (since it can be spoofed), and without reading the Headers server-side.
It appears they were quite sneaky in hiding this, but you can check if the window has a property named "Android " (with a space at the end). This appears to be true only when being used as a WebView inside an app, and not in Chrome on the same device.
const isAndroidWebView = window.hasOwnProperty('Android ')
Disclaimer: I have only verified this on a Pixel 3 running Android 10, and a Nokia 6 running Android 9. Please comment if this does or doesn't work for your device.

An alternative to URL schemes on Android?

I need to support the launching of native apps from a web application. Considering that not all the apps support URL schemes, is there an alternative to launch native apps from Web without URL scheme on Android?
I'm looking for JavaScript solutions that will work on Android 4.4.
Did you have a look at this-https://developer.chrome.com/multidevice/android/intents..I think native apps and chrome webview on phone must be supporting this.
If your app is a hybrid one-you can try this:
You can have a method called launchNative(appName) in your native code and call it from javascript.refer-Native code calling JS in Android webapps

How to open an app from web on Android

I create 'iframe' element, use the http scheme to open an app on Android Device, it works fine if the app is installed.
When the app is not installed, I use setTimeout function setting window.location = marketurl,
it will open market, and it works fine on Android Browser, but it doesn't work on chrome 25+.
I only see an error message in my browser.
What should I do?
I believe there are some new changes to the functionality in Chrome for Android v. 25 and later. You may need to implement Intent. This is created to prevent unsafe app open from the browser.
Here is one example from Google Chrome for developers that will open the Zxing barcode scanner app.
Take a QR code
Reference: https://developer.chrome.com/multidevice/android/intents
It is no longer possible to launch an Android app by setting an
iframe's src attribute. For example, navigating an iframe to a URI
with a custom scheme such as paulsawesomeapp:// will not work even if
the user has the appropriate app installed. Instead, you should
implement a user gesture to launch the app via a custom scheme, or use
the “intent:” syntax described in this article.

detect Android app is installed or not in device using javascript or jquery

I build a webapp and I have social links in my webapp.
I am facing an issue regarding this. If I am having facebook installed in my device then on click of the share link it should open the native app instead of opening in browser.
And incase if I doesnt have any native app installed then it should automatically redirect to browser.
Here it is the code what I have tried:
Javascript:
if(isAndroid){
fb://profile//www.facebook.com/sharer/sharer.php // to open in native browser
http://wwww.facebook.com // to open in web browser.
}
How do I handle this urls...
Please help me out.
This is not possible, for privacy reasons.
See This answer
You can make Hybrid Application.
What you just need to do is ADD WEB INTERFACE which will make call to native source code through javascript and also get return value.
So you can write native function which will return if application is installed. Once you set this interface you can use it further for open that app and passing intent and all that.
You can do it easily. Start Here:
https://developer.android.com/guide/webapps/webview.html

Specifying Native Messaging Host for Chrome extension

I am using native messaging API in Chrome extension, and I want to ship the native application within my extension.
In Windows, I add a registry key under HKLM\SOFTWARE\Google\Chrome\NativeMessagingHosts. Since my application is inside the extension folder after installed, I reference the full path by "%LOCALAPPDATA%\Google\Chrome\User Data\Default\Extensions\...\....json". But in this way, my extension complains "Specified native messaging host not found.".
If I expand the %LOCALAPPDATA% and write the path as "C:\Users\...\AppData\Local\Google\Chrome\User Data\Default\Extensions\...\....json", then my extension can successfully communicate with the host.
I wonder if this is an intended behavior? Thank you for your help.
There is no expansion of environment variables in the current Chromium code. It sounds like a reasonable feature request, though there might be security reasons not to do it. If you file a bug, we'll have a look and see whether it's feasible.

Categories