Launch app's activity when opening a specific link pattern - android

I have a little web app that sends anonymous messages as links.
I'm currently working on its Android version. The links of messages are in the pattern:
https://believe-labs.co/speak/m?somerandomkey
I want that when the receiver clicks the link of a message, and if the app is installed on the device, the browser should redirect the link to my app activity and launch it.
I tried
<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="believe-labs.co/m" android:scheme="https"/>
</intent-filter>
but it doesn't seem to work. Where am I wrong and what do I need to add?

You must use this kind of data (host & path):
<data
android:scheme="https"
android:host="believe-labs.co"
android:path="/speak/m" />

You shouldn't use believe-labs.co/m in the host,you can try the below code that will work for sure because i am also using same code in my app to be open via deeplink.
<category android:name="android.intent.category.DEFAULT"></category>
<category android:name="android.intent.category.BROWSABLE"></category>
<data
android:host="believe-labs.co"
android:scheme="https"></data>
</intent-filter>

Related

How Can I Create an Intent to 'Open In App' but Not from the Browser

I've got an intent in my AndroidManifest.xml working great. When a person visits a page called "train", the actions specified in my ActivityMain are carried out.
However, my website includes some features which are not available in my app.
So i'd still like users to be able to navigate around my website with ease, without links to the train page on the browser opening the app.
Does anyone know how I can use an intent-filter to prompt the user with the option to "open in app" from apps such as Gmail, Messenger, etc, but NOT when they're on my website going to the specified page?
<intent-filter>
<data android:scheme="https"/>
<data android:host="example.co.uk"/>
<data android:path="/train/"/>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
</intent-filter>
<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="example.co.uk"
android:path="/train/"
android:scheme="https" />
</intent-filter>
For further information you can view detail here about deep linking:
https://developer.android.com/training/app-links

Firebase dynamic link not opening/launching my installed app [duplicate]

I have developed an android app locally on my device (app not yet on android play store). I have the following logic to get deep link in MainActivity.
GoogleApiClient mGoogleApiClient = new GoogleApiClient.Builder(this)
.enableAutoManage(this, null)
.addApi(AppInvite.API)
.build();
// Check if this app was launched from a deep link. Setting autoLaunchDeepLink to true
// would automatically launch the deep link if one is found.
boolean autoLaunchDeepLink = false;
AppInvite.AppInviteApi.getInvitation(mGoogleApiClient, this, autoLaunchDeepLink)
.setResultCallback(
new ResultCallback<AppInviteInvitationResult>() {
#Override
public void onResult(#NonNull AppInviteInvitationResult result) {
if (result.getStatus().isSuccess()) {
// Extract deep link from Intent
Intent intent = result.getInvitationIntent();
String deepLink = AppInviteReferral.getDeepLink(intent);
Toast.makeText(getApplicationContext(), deepLink, Toast.LENGTH_LONG).show();
// Handle the deep link. For example, open the linked
// content, or apply promotional credit to the user's
// account.
// ...
} else {
Log.d(TAG, "getInvitation: no deep link found.");
}
}
});
I built some dynamic links using Firebase console and open in mobile browser. But it is not opening my app and reaching to line String deepLink = AppInviteReferral.getDeepLink(intent);
Instead it is opening the URL in mobile browser itself.
How to open the app and handle deep link in activity while using firebase dynamic link??
Edit:
I have intent filter in the manifest file.
<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" />
<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:scheme="http"/>
<data android:host="example.com" android:scheme="https"/>
</intent-filter>
</activity>
Action View and Action Main both are of different Intent category. So, you need to put them in different blocks like this:
<activity android:name=".DynamicLinkActivity">
<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:host="example.com"
android:scheme="http" />
<data
android:host="example.com"
android:scheme="https" />
</intent-filter>
</activity>
Alternatively, you could also provide the data in your intent-filter, like stated in the "regular" deep links doc (https://developer.android.com/training/app-indexing/deep-linking.html)
The intent filter would then look like the following :
<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="https://XXYYZZ42.app.goo.gl/" // <- Replace with your deep link from the console
android:scheme="https"/>
</intent-filter>
That said link can be obtained in your console, right here :
EDIT : Added the picture to show where to find this link
Update January 2019
Ensure that you have added the SHA256 certificate fingerprint for your app into your project in the Firebase console.
Add the below code in the AndroidManifest.xml under the activity which you want the dynamic link to lunch:
<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="mydomainname.page.link" android:scheme="http"/>
<data android:host="mydomainname.page.link" android:scheme="https"/>
</intent-filter>
Remove android:autoVerify="true" if you have Android 6.0 (API level 23) and below or the app will crash.
As explained in another answer, your intent filter seems to have some problems. Also your url may have some problems. When I was playing with those, I had created faulty URL to FireBase web site without noticing it. It is possible to test you code by opening the whole url in your app. I wrote all urls to be tested to an email and sent to myself, open in the device and started clicking. After that you can create the url you want in FireBase. Below are few examples (typos and other errors possible):
If you clicked this url on your device:
https://<myapp>.app.goo.gl/?link=https://mysite.fi/112972&apn=com.mydomain.myapp
and had this in you manifest:
<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="mysite.fi"
android:pathPattern=".*" />
</intent-filter>
It should open https://mysite.fi/112972 in your app (com.mydomain.myapp) and if you opened the link on your PC, it would open https://mysite.fi/112972 in the browser.
If you opened this url in your device:
https://<myapp>.app.goo.gl/?link=https://mysite.fi/112972&apn=com.mydomain.myapp&al=myscheme://mydeeplink/112972&afl=http://fallback.fi
and had this in you manifest:
<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="myscheme"
android:host="mydeeplink"
android:pathPattern=".*" />
</intent-filter>
It would open myscheme://mydeeplink/112972 in your app (com.mydomain.myapp). You would need to have code for handling it. If the app is not installed, it would open http://fallback.fi in your browser. On the PC it would still open https://mysite.fi/112972.
(edit 19.3.2018) It seems that Firebase does not fully support 'al=' anymore. The code works, but it is missing from the documentation and Firebase console generated urls.
I had the same problem with deep links not working and the former answers wasn't helping. What did the trick was splitting the "data" tag like this:
Instead of:
<data android:host="example.com" android:scheme="http"/>
<data android:host="example.com" android:scheme="https"/>
Do this:
<data android:host="example.com"/>
<data android:scheme="http"/>
<data android:scheme="https"/>
Hope that will help anyone else :)

Firebase dynamic link not opening the app

I have developed an android app locally on my device (app not yet on android play store). I have the following logic to get deep link in MainActivity.
GoogleApiClient mGoogleApiClient = new GoogleApiClient.Builder(this)
.enableAutoManage(this, null)
.addApi(AppInvite.API)
.build();
// Check if this app was launched from a deep link. Setting autoLaunchDeepLink to true
// would automatically launch the deep link if one is found.
boolean autoLaunchDeepLink = false;
AppInvite.AppInviteApi.getInvitation(mGoogleApiClient, this, autoLaunchDeepLink)
.setResultCallback(
new ResultCallback<AppInviteInvitationResult>() {
#Override
public void onResult(#NonNull AppInviteInvitationResult result) {
if (result.getStatus().isSuccess()) {
// Extract deep link from Intent
Intent intent = result.getInvitationIntent();
String deepLink = AppInviteReferral.getDeepLink(intent);
Toast.makeText(getApplicationContext(), deepLink, Toast.LENGTH_LONG).show();
// Handle the deep link. For example, open the linked
// content, or apply promotional credit to the user's
// account.
// ...
} else {
Log.d(TAG, "getInvitation: no deep link found.");
}
}
});
I built some dynamic links using Firebase console and open in mobile browser. But it is not opening my app and reaching to line String deepLink = AppInviteReferral.getDeepLink(intent);
Instead it is opening the URL in mobile browser itself.
How to open the app and handle deep link in activity while using firebase dynamic link??
Edit:
I have intent filter in the manifest file.
<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" />
<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:scheme="http"/>
<data android:host="example.com" android:scheme="https"/>
</intent-filter>
</activity>
Action View and Action Main both are of different Intent category. So, you need to put them in different blocks like this:
<activity android:name=".DynamicLinkActivity">
<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:host="example.com"
android:scheme="http" />
<data
android:host="example.com"
android:scheme="https" />
</intent-filter>
</activity>
Alternatively, you could also provide the data in your intent-filter, like stated in the "regular" deep links doc (https://developer.android.com/training/app-indexing/deep-linking.html)
The intent filter would then look like the following :
<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="https://XXYYZZ42.app.goo.gl/" // <- Replace with your deep link from the console
android:scheme="https"/>
</intent-filter>
That said link can be obtained in your console, right here :
EDIT : Added the picture to show where to find this link
Update January 2019
Ensure that you have added the SHA256 certificate fingerprint for your app into your project in the Firebase console.
Add the below code in the AndroidManifest.xml under the activity which you want the dynamic link to lunch:
<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="mydomainname.page.link" android:scheme="http"/>
<data android:host="mydomainname.page.link" android:scheme="https"/>
</intent-filter>
Remove android:autoVerify="true" if you have Android 6.0 (API level 23) and below or the app will crash.
As explained in another answer, your intent filter seems to have some problems. Also your url may have some problems. When I was playing with those, I had created faulty URL to FireBase web site without noticing it. It is possible to test you code by opening the whole url in your app. I wrote all urls to be tested to an email and sent to myself, open in the device and started clicking. After that you can create the url you want in FireBase. Below are few examples (typos and other errors possible):
If you clicked this url on your device:
https://<myapp>.app.goo.gl/?link=https://mysite.fi/112972&apn=com.mydomain.myapp
and had this in you manifest:
<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="mysite.fi"
android:pathPattern=".*" />
</intent-filter>
It should open https://mysite.fi/112972 in your app (com.mydomain.myapp) and if you opened the link on your PC, it would open https://mysite.fi/112972 in the browser.
If you opened this url in your device:
https://<myapp>.app.goo.gl/?link=https://mysite.fi/112972&apn=com.mydomain.myapp&al=myscheme://mydeeplink/112972&afl=http://fallback.fi
and had this in you manifest:
<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="myscheme"
android:host="mydeeplink"
android:pathPattern=".*" />
</intent-filter>
It would open myscheme://mydeeplink/112972 in your app (com.mydomain.myapp). You would need to have code for handling it. If the app is not installed, it would open http://fallback.fi in your browser. On the PC it would still open https://mysite.fi/112972.
(edit 19.3.2018) It seems that Firebase does not fully support 'al=' anymore. The code works, but it is missing from the documentation and Firebase console generated urls.
I had the same problem with deep links not working and the former answers wasn't helping. What did the trick was splitting the "data" tag like this:
Instead of:
<data android:host="example.com" android:scheme="http"/>
<data android:host="example.com" android:scheme="https"/>
Do this:
<data android:host="example.com"/>
<data android:scheme="http"/>
<data android:scheme="https"/>
Hope that will help anyone else :)

Can't get intent filter working on Android - AIR app

I want my app to execute when example.com is browsed to. No matter what I do, I cant make this happen. I've tried dozens of things listed in other questions.
Trying to troubleshoot, if I can get answers to these questions it will help a lot:
- Is there a certain permission I need to request in order to capture intents?
- Is there a way to query an app to see what intents it accepts? So I can test that my manifest is properly being set.
Here is the config I'm using which doesn't work:
<intent-filter>
<action android:name="android.intent.action.VIEW"></action>
<category android:name="android.intent.category.DEFAULT"></category>
<category android:name="android.intent.category.BROWSABLE"></category>
<data android:host="example.com"> </data>
<data android:scheme="https"></data>
<data android:scheme="http"></data>
<data android:pathPattern=".*"></data>
</intent-filter>
It's up to whatever app you're using to try to launch yours to use an intent that your application can handle. If you're in a browser, and you click on a link that a browser can handle, odds are the browser is just going to handle that link instead of making an intent to see if there are any other apps that can handle it.
Try sending a link to your email and opening from there instead. If you have set up everything correctly already, I bet you it'll ask whether you want to open your browser or your app.
Turns out you need two intent filters setup, or else it wont work. You also need everything wrapped in an 'activity' block, which I didn't have. Here's the updated XML that now works:
<activity>
<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"></action>
<category android:name="android.intent.category.BROWSABLE"></category>
<category android:name="android.intent.category.DEFAULT"></category>
<data android:host="example.com"> </data>
<data android:scheme="https"></data>
<data android:scheme="http"></data>
<data android:pathPattern=".*"></data>
</intent-filter>
</activity>
If anyone understands why two intent-filters are needed would be great to know the explanation.

How do I get a domain link to open my app on android?

The following works fine:
I click on the link www.mycompany.com in an email and it starts my app:
<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.mycompany.com/download" android:scheme="http"/>
</intent-filter>
However, what I want to work is as below but it's not working:
I want to be able to restrict it to the link www.mycompany.com/download:
<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.mycompany.com/download" android:scheme="http" />
</intent-filter>
Why the distinction? I don't want to block my entire website with the app. I just want that specific domain to redirect to the app. How do I do that?
What you've shown is not a subdomain. That is,
www.mycompany.com/download
is not a subdomain of
www.mycompany.com
But you could use a subdomain to address this issue by setting up something like
download.mycompany.com
and have it map to www.mycompany.com/download. (Most servers allow you to set up subdomains like that.) You can then modify the intent filter accordingly.
EDIT
To support what you're trying to do without setting up a subdomain, you can do the following:
<data
android:host="www.mycompany.com"
android:scheme="http"
android:pathPrefix="download"
/>
I would suggest you to try latest feature made available by Google and that is App-indexing to show your app even when user search about your website on Google.
You need to go through 2 steps:
1 Sign Up for this feature here
2 Update your app as well as sitemap of your website as mentioned here
For further reference you can go through this documentation
Screenshot :

Categories

Resources