Web browser application - how to intercept URL intents? - android

I have a custom ROM and have no default browser except WebView Browser Tester. I have develop my own kind of web browser app(webviewclient activity) and install this in a phone. Now I want that whatever URLs when user click in a phone, my browser application will intercept and load this URL. Here is what I am using in intent_filter
<intent_filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.BROWSABLE"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent_filter>
But it is not working and still WebView browser Tester app launch and loading links. Can someone tell me how I can set my app as a default browser App OR use any special intent which can help to launch this activity while clicking on any URL?

Try adding both intent filters
<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="*"/>
</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="https"
android:host="*" />
</intent-filter>

For this you have to identify the launching Activity of Browser application, something like this:
Intent intent = new Intent();
intent.setComponent(new ComponentName("/*Pass your browser package*/","com.google.android.browser.BrowserActivity /*And pass Browser Activity*/"));
intent.setAction("android.intent.action.VIEW");
intent.addCategory("android.intent.category.BROWSABLE");
Uri uri = Uri.parse(url);
intent.setData(uri);
try
{
startActivity(intent);
}
catch (Exception e)
{
e.printStackTrace();
}
Answer already available on this link

Related

Is it possible to open android app from Gmail with deep link

When clicking my custom deep link in gmail I get redirected to the browser by default. Meanwhile doing the same from Outlook opens my app nicely.
Here is my intent filter:
<intent-filter>
<data
android:host="my.domain.com"
android:port="9201"
android:scheme="https" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
</intent-filter>
Edit: spelling

how to open link with app instead of browser

I am trying read barcod and then get URL from this barcod and then trying to open this URL. it show this page which is open with app or continue with browser . even if select open with app . it will ask me this page next time. how can directly open this url with Autocad a360 app.
this is my code:
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(StringURL));
startActivity(intent);
Add this code to manifest.
<activity
android:theme="#style/AppTheme.Launcher"
android:name=".features.MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter android:label="#string/app_name">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:host="YOURSITE.com"
android:scheme="http" />
</intent-filter>
</activity>
App will launch when you try to open http://YOURSITE.com
Deep link was correct answer

Opening the custom file format in my application instead of downloading it on Android

When user type the url to my .someExt file in his web browser (on Android Phone), the message appears:
This content is unsupported content. Do you really want to download?
Instead, I would like to associate the .someExt (my custom file extension) with my Android Application (that the user has downloaded previously) so when user type the url to .someExt in browser my Application will open the file.
How to achieve it? I guess it has to be done with manifest and some "handle" method in my Activity.
Based on: Associate App with file extension - Intent filter Not working?
I have used:
<activity
android:name=".MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</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:mimeType="application/someExt" />
</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:host="*" />
<data android:scheme="file" />
<data android:scheme="smb" />
<data android:scheme="content" />
<data android:scheme="http" />
<data android:scheme="https" />
<data android:mimeType="*/*" />
<data android:pathPattern=".*\\.someExt" />
</intent-filter>
</activity>
Now, when user type the url to my .someExt the file is being downloaded and I can open it when downloading is done (so my Application will run it). But I don't want all those additional clicks - I want it to be:
User click the link to .someExt on the website.
The .someExt opens in my Android Application.
And not the:
User click the link to .someExt on the website.
The file starts to download.
User open "downloads" and click on downloaded file.
The .someExt opens in my Android Application.
I don't think you can realize this feature in Android with different kind of browsers. The URL user type is handled by the browser most of the time. How to deal with the scheme is decided by the behaviors of the browser. If your scheme is http, the browser will try to open with it own and handle by itself.
Currently, most browsers add support for market scheme. If the URI's scheme is market, it will jump to Google Play or other markets.
But is can be done from other app with Intent.
Declare your activity like following to receive the ACTION_VIEW action.
<activity
android:name=".MainActivity2Activity"
android:label="#string/title_activity_main_activity2">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE" />
<category android:name="android.intent.category.DEFAULT" />
<data
android:host="com.example.myapp"
android:mimeType="*/*"
android:pathPattern=".*\\.someExt"
android:scheme="http" />
</intent-filter>
</activity>
From other apps, you could do like this.
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse("http://com.example.myapp/test.someExt"), "*/*");
intent.setPackage("com.example.myapplication");
startActivity(intent);

How to open VKontakte app with a specific friend?

Background
In order to open Facebook app with a specific Facebook friend, you can use this intent:
final Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(String.format("fb://profile/%s", friendId)));
A similar solution is found for LinkedIn:
final Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(String.format("linkedin://profile/%s", friendId)));
I think the next one will work for Google Plus (didn't test it, but it seems promising) :
final Intent intent =new Intent(Intent.ACTION_VIEW, Uri.parse(String.format("https://plus.google.com/%s/posts", friendId)));
The question
I've tried to find how to open VKontakte (VK) social network app using such intents, but couldn't find it.
Is there such an intent? If so, what is it?
The answer from developer is next:
Yes, it's done the same way:
final Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(String.format("vkontakte://profile/%d", friendId)));
If you need to open a community, use the same URL but add the minus sign to the community ID.
Question answered here
Here is a list of url i found at VK app manifest
http ://vk.com/.*
http ://vkontakte.ru/.*
https ://vk.com/.*
https ://vkontakte.ru/.*
http ://m.vk.com/.*
Note: remove space after http/https. SO won't let me post more than 2 links
you can use any of that to launch vk from your app
here is how i do that
private void sendIntentToVkApp() {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("http://vk.com/hmrussia"));
try {
startActivity(intent);
} catch (ActivityNotFoundException e) {
Toast.makeText(this, e.getMessage(), Toast.LENGTH_LONG).show();
}
}
and here is a part of VK Manifest where all the schemes are defined
<intent-filter>
<category
android:name="android.intent.category.DEFAULT"/>
<action
android:name="android.intent.action.VIEW"/>
<data
android:scheme="vklink"/>
</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="vk.com"
android:pathPattern="/.*"/>
</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="vkontakte.ru"
android:pathPattern="/.*"/>
</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="https"
android:host="vk.com"
android:pathPattern="/.*"/>
</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="https"
android:host="vkontakte.ru"
android:pathPattern="/.*"/>
</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="vkontakte"
android:pathPattern="/.*"/>
</intent-filter>
In Kotlin. This will open the app if installed, otherwise the browser will open.
private fun openVk(profileId: String) {
val uri = Uri.parse("http://vk.com/$profileId")
val intent = Intent(Intent.ACTION_VIEW, uri)
startActivity(intent)
}

getIntent().getData() returns previous url in android

I am trying to enable deep linking in my app . So my Intent- Filter looks like below
<intent-filter>
<data
android:host="*.showonthecloud.com"
android:scheme="http" />
<data
android:host="*.showonthecloud.com"
android:scheme="https" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<action android:name="android.intent.action.VIEW" />
<action android:name="android.intent.action.ALL_APPS" />
</intent-filter>
When clicking the url from other app (Gmail App) my app got opened.But get the previously clicked url. The implemented code is
Intent deepLinkIntent = getIntent();
dataUri = deepLinkIntent.getData();
The printed value shows the previous one
Log.d(TAG, "Received url from intent :data uri==>" +dataUri);
I got one link http://developer.appcelerator.com/question/153521/android-intent-getdata-returns-the-same-value
From this can't get any answer.

Categories

Resources