open Url in android in web browser application - android

I am working on a Web browser. The web browser is working, but I need help in the part where my Application catches Android system's url when clicked (http,https etc) and open my web browser application
Like any other browser chrome ,firefox etc, how these app open the default app choose menu?
Reading about these I learn about <intent-filter> is used
Can someone help me with what to be added to Manifest file and to my activity so that my Application catches url?

Try adding CATEGORY_BROWSABLE to your activity that can handle URLs.
Like this:
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<!--This makes activity an option for the default action (center press) to perform
on a piece of data. -->
<category android:name="android.intent.category.DEFAULT" />
<!-- Activities that can be safely invoked from a browser must support this category. -->
<category android:name="android.intent.category.BROWSABLE" />
<data
android:scheme="http" />
<data
android:scheme="https" />
</intent-filter>

Related

android deeplink, force open externally

I am developing an android app which accepts deeplink. For example consider this one:
<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:host="returnapp" android:scheme="testscheme" />
</intent-filter>
So if we call the url testscheme://returnapp/?status=1 then app should be opened.
In Google Chrome it opens up and everything goes right but in firefox, the app gets opened as child of browser task (which has the link to my app). But I want it to be opened independently.
So is there something to add to manifest to force this attribute or I should add some keyword in my HTML href?
UPDATE
I think I should make a change in the link showing in webpage in firefox. Currently I am using this link:
<h1>test</h1>
Something like target="_system" to tell firefox to open this link externally.
The browsers itself need to support and implment the browsability. The browsers have to find other activities supporting android.intent.category.BROWSABLE when opening a web-page.
So as you say, Firefox is not supported for opening app directly, however there is a solution you can try is to add android:autoVerify="true" in any one of the web URL intent filters in your app manifest that include the android.intent.action.VIEW intent action and android.intent.category.BROWSABLE intent category, as shown in the following manifest code snippet:
<intent-filter android:autoVerify="true">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:host="returnapp" android:scheme="testscheme" />
</intent-filter>
Even though I'm still not sure this gonna work because of android:autoVerify="true" is for appLink not for deepLink

How to block URL to open my android app?

My android app allows to open other website like "http://www.google.com" in a web browser from app. And my code is below.
<activity
android:name=".HomeActivity"
android:launchMode="singleTop"
android:screenOrientation="portrait" >
<intent-filter>
<category android:name="android.intent.category.DEFAULT" />
<action android:name="android.intent.action.VIEW" />
<data android:scheme="http" />
<data android:scheme="https" />
</intent-filter>
</activity>
But this gives me a problem. In the email or text message, click any website link, there will be a choice to open from my app. See the picture I posted. If I click on www.google.com in the text message, I will get a choice to open from my app.
I don't want the popup shows my app. How to handle this? Please help. Thanks a lot.
You can't avoid that, unless you specifically know what browser the user wants to use. And you don't know that.
You could have a WebView activity/fragment bundled in your application that will display webpages for you. That way you'd have full control. Here's a guide on WebView
Your app is being displayed in the Complete Action Using chooser because of your intent-filter:
<intent-filter>
<category android:name="android.intent.category.DEFAULT" />
<action android:name="android.intent.action.VIEW" />
<data android:scheme="http" />
<data android:scheme="https" />
</intent-filter>
and particularly because you've specified just a "scheme" entry, with no specific "host". This would in effect offer any web URL intent to open in your app.
Without understanding what your intended behavior exactly is, you can delete the <data> nodes from your intent-filter to remove your app from the Chooser.
Or alternatively, you might want specific URL's to offer your app in the Chooser, like http://yourserver.com and https://yourserver.com, for this you could alter your intent-filter as follows:
<data android:scheme="http" android:host="yourserver.com" />
If your question is to block URLs of other websites in your android app for download purpose then search for the iConstants.java file in your project and write the following code:
public interface iConstants {
public static final String[] DISABLE_DOWNLOADING = {"URL", };
public static final String WEB_DISABLE = "We cannot allow to download videos form this website.";
}

Launching custom Android application from Android browser / Chrome

First of all, my question is extremely similar to this, this and this. The Android documentation for what I'm trying to achieve is here. I couldn't get this to work using these resources so please don't mark this as duplicate as it is not.
I have a website and an Android application. The user will be able to scan QR codes that contain links like http://mywebsite.com/map/. When the user tries to open this link, I want Android to show him a chooser dialog where he can choose to open that link using my application. If my application is not installed, it should proceed to the specified website.
I know Chrome allows this by opening the chooser dialog when the user navigates to that address. For example, try downloading the Stack Exchange app and going to this question in Chrome. It will show this:
I have added the following code in AndroidManifest.xml after following the suggestion in the above-mentioned answers:
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:host="mywebsite.com"
android:path="/map"
android:scheme="http" />
<data
android:host="mywebsite.com"
android:path="/animals"
android:scheme="http" />
<data
android:host="mywebsite.com"
android:path="/articles"
android:scheme="http" />
</intent-filter>
Also, I have tried adding android:mimeType="text/plain" to data but it didn't help.
The problem is that when I go to http://mywebsite.com/map or http://mywebsite.com/map/ Chrome just opens the webpage without showing the chooser dialog.
I would like to mention:
following the Android documentation, I have added this code inside one of the activity structures in AndroidManifest.xml. As I am not sure this is the perfect place to add it, I have also tried adding it outside the application structure and directly inside the application structure but it didn't work
this is the only code I have implemented for this to work. If something else is needed please let me know. From what I understand, adding a href to the webpage is only needed when using custom schemas
I do not want to use a custom schema in order to achieve this
I am developing on a Nexus 4, running Android 4.4.2 (latest)
You need to set it up like this :
<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:host="example.com"
android:pathPrefix="/someresource/"
android:scheme="http" />
<data
android:host="www.example.com"
android:pathPrefix="/someresource/"
android:scheme="http" />
</intent-filter>
Notice that in your case, you would need to use android:pathPrefix instead of android:path.
Just to be sure, you should reset the preferences for your app in case you have accidentally set it to always open the link in chrome rather than show the chooser dialog. Once "Always" is used to open the matching uri, it will never show the chooser.
Second, you can have as many data elements in the intent filter as your want, but it is not necessary to repeat information. You can do the same thing like this:
<data android:host="mywebsite.com"/>
<data android:scheme="http"/>
<data android:path="/map"/>
<data android:path="/animals"/>
<data android:path="/articles"/>
But note that for the path, you can just use a wildcard
<data android:path="/.*"/>
Consider adding an additional
<data android:host="www.mywebsite.com"/>
And finally you may not want to show the chooser dialog but open a specific app intent/activity directly. On your website, if you detect the android user agent, you can create a link url this way:
<a href="intent://mywebsite.com/articles#Intent;package=com.myapp;scheme=http;end;"/>
See here for more details How do I open any app from my web browser (Chrome) in Android? What do I have to do with the A Href link?
Note that with this method if the app is not installed the user will be taken to the Google Play store for the specified app package.
If you are still having problems, check your intent filter priority. http://developer.android.com/guide/topics/manifest/intent-filter-element.html
In my case site URL is: http://www.example.org/mobile/
so putting these code into AndroidManifest.xml inside 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:host="www.example.org"
android:pathPrefix="/mobile/"
android:scheme="http" />
</intent-filter>
Here,
scheme -> Protocol of particular site
host-> Exact site url with WWW
pathprefix - > Your site's sub path if available
Now,
You can search with chrome / etc android browser'search box like example then open chosen dialog ..!!

Open custom app by URL from browser's address bar

I writed a simple Android application and added a intent filter like this:
<intent-filter>
<data android:scheme="http" android:host="www.somesite.com" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
Okay. Now, when I click by link from another application (like GMail) i see a dialog: choose application for run: MyApp or Browser.
But when I type this URL in browser's address bar it just open a site.
How can set up my app like a Google Play, Google+? (When I type a http://play.google.com/ - i see a dialog Google Play App or Browser)

Open my App with URL - Android

I'm developing an android app.... and I want to open my app when someone types the url in browser.. I'm able to get the "Complete Action Using.." and My app also shows there ONLY when I click the bookmark to the web link.. However if I type the URL in browser it simply loads up the website.. but I want to redirect it to my app.
Here is my code in Manifest file.
<intent-filter>
<data android:scheme="http" android:host="SOME_URL.SOMETHING"/>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
*SOME_URL.SOMETHING is the name of website to load.
Thanks in Advance :)

Categories

Resources