I want to create a web browser and I succeed to defined it as the default one with those lines.
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="http" />
<data android:scheme="https" />
</intent-filter>
but now when I, for example, go on Gmail and click on a link it opens my app but the problem is that I didn't find a way to make it capable of opening the app and make the Webview loading the link that I clicked in this example on Gmail. So how can I do so when another app launches the web browser, the javascript code is capable of getting the URL so that I can load it on the Webview with the command mywebview.load(urlgetwhentheappopen);?
the code
try {
String url = getIntent().getData().getPath();
Toast.makeText(this, url, Toast.LENGTH_LONG).show();
Log.d("link", url);
WebView myweb=(WebView) findViewById(R.id.web);
myweb.loadUrl(url);
}catch(Exception e){
Log.d("error","no link"+String.valueOf(e));
}
The Android OS passes the URL path to your app inside of Intent object.
in your WebBrowser activity you could get the link like this:
Koltin
val url = intent.data?.toString()
Java
String url = getIntent().getData().toString()
Then you can simply call:
mywebview.load ( url );
Related
My app is a WebView Application and I've setup URL Intent Filters so when a link with the domain "riftacademy.org" is clicked, it opens my app.
Now I'm trying to implement deep-linking into the WebView application...
I saw something similar in the thread here How to enable deep-linking in WebView on Android app?
But unlike the above which uses a custom URI Scheme to open the application, I'd like to implement deep-linking in my WebView using my domain name "riftacademy.org"
In this scenario, when a link such as https://riftacademy.org/login or https://riftacademy.org/register is clicked, it should open the app and go to the pages that match the links. But in this case, it opens the app but only loads the homepage riftacademy.org...
I want the WebView app to be able to load links after the app has been opened, similar to how YouTube and Facebook handle links
Can Deep-Linking be achieved in WebView using Domain Names?
A snippet of where I'm guessing may be needed to edit
newWebView.setWebViewClient(new WebViewClient() {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
Intent browserIntent = new Intent(Intent.ACTION_VIEW);
browserIntent.setData(Uri.parse(url));
startActivity(browserIntent);
return true;
}
});
return true;
}
});
Thanks in advance
So I've been able to solve this with the help of Ron from https://webintoapp.com ... This was achieved using URI Intent Filters and placing the following code in the MainActivity.java and AndroidManifest.xml
I added this to the OnCreate Method in my MainActivity.java... The website name should be added just after the else{mWebView.loadUrL
SetWebView(mWebView);
Intent intent = getIntent();
Uri data = intent.getData();
if(data != null) {
//Load the deep-link url:
String url = intent.getDataString();
mWebView.loadUrl(url);
}
else
{
mWebView.loadUrl("https://riftacademy.org/");
}
And this to my MainActivity.xml... The android:host should be the website URL as well
<activity android:name=".MainActivity">
<intent-filter android:label="The Title">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:scheme="https"
android:host="riftacademy.org" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:scheme="http"
android:host="riftacademy.org" />
This would enable the WebView App to load all kinds of links as long as the links starts with the default URL of the website
I'm making an app that takes an URL to X domain, makes a get with Jsoup, scraps some content, and the present that content. I've already done that with an EditText on my app, but what i want now is that the app can be selected as an app to open the url from other apps(You know, when the app shows an URL, you click, and then a prompt asks which app would you want to use), and then pass that url as the parameter of the EditText, doesn't matter if directly start execution, or if just paste the url on the EditText.
want now is that the app can be selected as an app to open the url
from other apps
Add intent-filter with BROWSABLE category in AndroidManifest:
<activity ...>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="http" />
<data android:scheme="https" />
</intent-filter>
</activity>
pass that url as the parameter of the EditText, doesn't matter if
directly start execution, or if just paste the url on the EditText
Call getIntent().getData() in BROWSABLE Activity to get provided Uri to open or show in EditText :
// prepare URL
Uri dataUri = getIntent().getData();
URL webUrl = new URL(dataUri.getScheme(),
dataUri.getHost(),
dataUri.getPath());
I have built an Android Browser where I want to load external web links from other apps. Here I have added this code on AndroidManifest.xml . So when I am open http/https link from other app, it's showing my app in the browser list.
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="http" />
<data android:scheme="https" />
</intent-filter>
Now, by which key name I will get that data into my browser ???
Suppose, if I send a web link which key is "url", then I load that url by this way,
Intent intent = getIntent();
String url = intent.getStringExtra("url");
if(url!=null) {
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(url));
startActivity(i);
finish();
}
I do not know by which key name other app is send data to open with external browser. How can I solve this ?
http://www.vogella.com/tutorials/AndroidIntent/article.html
Refer the link. In this, they explained how to use explict intent for make communication between two application. Also their example perfectly satisfy your need.
I really can't find anything for this, maybe I'm using the wrong keywords. Hope you can help anyway.
I developed an application which has the task to navigate a website in a easy way from mobile, but now I want it to be recognised outside from other applications as default for certain links. For example:
An email arrives from this website on your phone, when you click on the link in it, which rediricts to a page on that website, I want that the OS asks me to choose which application I want to use, in this case Google Chrome or my application.
Only thing I was able to do was to make it open YouTube links with the YouTube application externally, not viceversa from outside
Thanks fot the help and the idea, this is how i made it work:
Manifest.xml
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:host="www.mywebsite"
android:scheme="https"
/>
Mainactivity.java (inside OnCreate)
WebView myWebView = (WebView) findViewById(R.id.webView);
Intent intent = getIntent();
Uri data = intent.getData();
if (data!=null) {
myWebView.loadUrl(String.valueOf(data)); //Load given link from external app
} else {
myWebView.loadUrl("http://www.mywebsite"); //Load homescreen
}
I am using this piece of code to launch my app from a link.
<activity
android:name="com.example.myApp.myClass"
android:label="#string/app_name" >
<intent-filter>
<data
android:host="customHostName"
android:scheme="customScheme" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
This is href link, i want to get the key in the end.
customScheme://customHost/49FYTJTF00
It is working fine on all previous versions of android, but is not working on Lollipop.
When I click the link it only shows the list of browsers to launch.
What should I do?
Edit:
After testing and testing, I found that if your scheme contains an uppercase character the browser won't be able to launch it. Your scheme should only contain lowercase characters!
Also note that bug 459156 of the chromium project still doesn't allow you to launch url's directly, you should reference users to a webpage containing this JavaScript code:
<!DOCTYPE html>
<html>
<body>
<script language="javascript">
window.location = 'customscheme://customHost/49FYTJTF00';
</script>
</body>
</html>
Users landing on this page will automatically be prompted with either an Activity chooser dialog or directly send to your Activity.
To try it, open the Android browser go to the url below and copy paste the above snippet in the editor:
http://www.w3schools.com/html/tryit.asp?filename=tryhtml_intro
Gif showing browser + JavaScript opening the Activity
Original post
I tried out your custom URI and it works on Android 5.0
But you should be aware of the following two bugs/issues:
Bug 459156 of the Chromium project This basicly means launching custom schemes from the Android browser does not work unless the URL is applied using JavaScript. For a workaround see this StackOverflow post: OAuth and custom scheme result in a "ERR_UNKNOWN_URL_SCHEME" in Chrome
Bug 80971: URI with custom scheme are not clickable in SMS Text (Linkify?)
My approach
I created two separate Activities, one as intent receiver and the other as intent launcher. The launching activity has an EditText where the full URI can be entered and a button to launch the entered URI.
Main.java onClick (Launching activity)
#Override
public void onClick(View view) {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(input.getText().toString()));
try {
startActivity(intent);
} catch(ActivityNotFoundException e){
Toast.makeText(this, "Auww!! No Activity can open this URI!", Toast.LENGTH_SHORT).show();
}
}
manifest.xml (only the activities)
Note the <data android:pathPattern=".*"/> part. this part is important so anything after the host will be accepted as valid.
<activity
android:name=".Main"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity
android:name=".UriActivity"
android:label="#string/app_name">
<!--
This intent-filter will open any URI with the following forms:
customscheme://customHost/49FYTJTF00
customscheme://customHost
https://www.google.com/something/something
http://www.google.com/
http://google.com/something
-->
<intent-filter>
<data android:scheme="https"/>
<data android:scheme="http"/>
<data android:host="google.com"/>
<data android:host="www.google.com"/>
<data android:scheme="customscheme"/>
<data android:host="customHost"/>
<data android:pathPattern=".*"/>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
</intent-filter>
</activity>
UriActivity.java (Receiving activity)
public class UriActivity extends ActionBarActivity {
private TextView tvText;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_uri);
tvText = (TextView) findViewById(R.id.text);
setTextFromIntent();
}
#Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
setTextFromIntent();
}
private void setTextFromIntent(){
StringBuilder text = new StringBuilder();
Uri data = getIntent().getData();
if(data != null){
text.append("Path:\n");
text.append(data.getPath());
text.append("\n\nScheme:\n");
text.append(data.getScheme());
text.append("\n\nHost:\n");
text.append(data.getHost());
text.append("\n\nPath segments:\n");
text.append(Arrays.toString(data.getPathSegments().toArray()));
} else {
text.append("Uri is null");
}
tvText.setText(text);
}
}
Screenshot:
Test project download:
I made a download for the project if you wan't to try it out yourself.
Please use pathprefix.
android:pathPrefix="/"
It might solve your problem.
Please follow android developer guide URL.
Instead of using a link to customScheme://customHost/49FYTJTF00, have you tried using a link like
<a href="intent://customHostName/49FYTJTF00#Intent;scheme=customScheme;end">
Chrome should be able to open that in your app just fine. At the same time, this might not work on all browsers.
Keep in mind if you want run the app from Google Chrome you should do that in another way .
You wrote:
<data
android:host="customHostName"
android:scheme="customScheme" />
So, use customScheme://customHostName/49FYTJTF00
instead of customScheme://customHost/49FYTJTF00