We are trying to create some deep links for Android using branch.io but haven't had any success in last 2 days. We would be really glad if we can get some help on how to do it.
Configuration:
Android Manifest:
<activity
android:name=".login.view.DeepLinkActivity"
android:screenOrientation="portrait"
android:theme="#style/AppTheme.Login"
android:windowSoftInputMode="adjustResize">
<intent-filter>
<data android:scheme="myapp" android:host="open" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
</intent-filter>
</activity>
Branch.io Dashboard :
Under android redirects section, the value for "Android URI schema" is set to "myapp://"
The link is being generated via branch.io HTTP API. The post request is
host: v1/url
request body:
{
"alias":"xxxx",
"data":"{\"$fallback_url\":\"www.xxx.com\",\"$android_depplink_path\":\"myapp://open/\"}",
"branch_key":"key_test_xxxxxxxxxx"
}
Whenever we are trying to open this link via email, we are redirected to the fallback URL defined in branch.io dashboard.
Please help us get this configuration right.
You need to override onStart method of your launcher Activity and handle the redirection according to data passed from intent.
STEP 1: Generate Deep links using https://dev.branch.io/getting-started/creating-links/apps/android/#generate-the-link
STEP 2 : Handle the intent and take to desired activity
https://dev.branch.io/getting-started/deep-link-routing/guide/android/#building-a-custom-deep-link-routing-method
Don't forget to add android:launchMode="singleTop" in Activity Manifest to have only one instance at a time.
you can also handle this using intent.addFlag() passing Intent.FLAG_ACTIVITY_REORDER_TO_FRONT and Intent.FLAG_ACTIVITY_CLEAR_TOP. Hope this helps.
Related
I've been trying to use deep linking from a website I own to a resource inside my app. I've been reading about how things has evolved with deep linking in Android, particularly Paul Kinlan's blog post which seems to be the most recent explanation on how things should work.
I also have read this discussion on why custom scheme is a bad practice and should not be used, which made sense.
Now I decided to use the #intent link in my website to open the resource in the app when user taps on the link. For this, I used a link like this:
intent:#Intent;package=com.example.project;component=com.example.project/.ui.ActivityWithResource;i.res_id=80;end
But when I click on it, nothing happens, and I see this in the logs:
chromium: [INFO:CONSOLE(0)] "Navigation is blocked: intent:#Intent;package=com.example.project;component=com.example.project/.ui.ActivityWithResource;i.res_id=80;end", source: http://example.com/?res_id=80 (0)
I then read about this on Chrome documentation, which interestingly, their example was using a custom scheme, contrary to what they had argued before should not be done!
Now if I add the HTTP scheme to my intent link, like this:
intent://example.com/?res_id=80#Intent;scheme=http;package=com.example.project;component=com.example.project/.ui.ActivityWithResource;end
Then it works, because the activity has the intent-filter to handle the urls like http://example.com/, but why when I specify the component, it doesn't work?
Also, when I use HTTP scheme in my intent, in shows activity resolver (except android 6.0 as I do use auto-verify), but I assume if I can get my explicit intent link to work, it should directly open the resource in the app, as I already have defined the component in the intent link. right?
Maybe the only way is to use custom scheme after all?
Thanks
P.S: Here is the activity definition in my AndroidManifest. I wasn't sure if it requires android:pathPrefix to work or not, so I added both intent-filters
<activity
android:name=".ui.ActivityWithResource"
android:label="#string/app_name"
android:exported="true"
android:screenOrientation="portrait">
<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:scheme="http" android:host="example.com" android:pathPrefix="/"/>
</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:scheme="http" android:host="example.com"/>
</intent-filter>
</activity>
Fitbit API doesn't support webview anymore.
So, I studied chrome custom tabs and applied in my app.
But after login, when I pressed this pink button(allow button), nothing happened.(Image below)
How can I receive access token and store it in app?
Please help me.
Thanks.
When authorizing agains the Fitbit API, you need to provide a redirect_uri, which is where the user will be taken after logging in. You need to provide a uri that will take the user back to your application.
To achieve that, create an intent filter and add a data tag with a custom scheme, such as myapplication://logincallback to the Activity you want to handle the login.
The intent filter will look something like this:
<intent-filter . . . >
<data android:scheme="myapplication" android:host="logincallback" />
. . .
</intent-filter>
Now, set the redirect_uri as mypplication://logincallback to the authorization step of the flow, and when the user clicks the pink button, it should open the Activity you added the intent filter.
You will be able to retrieve the parameters inside your activity by calling getData on the Intent.
<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="logincallback"
android:pathPattern=".*"
android:scheme="myapp" />
</intent-filter>
Suppose you have redirect_uri myapp://logincallback, then add above code in your activity in Manifest xml file and it will work.
What really to post in the area of App Link where it asks to "Add a Android deep link URL to your app."?
Trivial, I guess, for everyone out here, but I am struggling.
In your Android Manifest, you can declare that certain activities are able to view certain uri's - such as
yourapp://view/specific/content/at/this/uri
The intent filter for this in your activity could be
<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="yourapp"/>
</intent-filter>
</activity>
See https://developer.android.com/training/app-indexing/deep-linking.html
I am integrating twitter posting in my app using twitter4j library. I am following this. But I am having issue in call back. After authorizing it doesn't actually comes to our app, but actually it opens up call back activity that we specified in browser. I am not sure why this is happening.
I tried to search but couldn't find anything related to this. So May be people haven't noticed or I missed something while integrating it.
Either way please help me to resolve this issue.
It's opening the custom URL link inside the browser itself because you haven't defined which activity should handle the custom links Or You haven't defined proper categories. Here is a sample. Make sure you include the categories. The android.intent.category.BROWSABLE will ensure that the browser opens your app.
private final String CALLBACKURL = "x-oauthflow-twitter://privlyT4JCallback";
<activity
android:name=".TwitterLinkGrabberService"
android:configChanges="keyboardHidden|orientation|screenSize"
android:launchMode="singleInstance" >
<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="privlyT4JCallback"
android:scheme="x-oauthflow-twitter" />
</intent-filter>
</activity>
you already install app with same callback, you must change the callback String from manifest and
call back constant from activity.try to use unique call back Address.
<data android:scheme="login-twitter" android:host="callback1" />
and
static final String TWITTER_CALLBACK_URL = "login-twitter://callback1";
This topic has been covered before, but I can't find an answer specific to what I'm asking.
Where I am: I followed hackmod's first piece of advice here: Make a link in the Android browser start up my app? and got this to work with a link in the webpage.
However, I'm having trouble understanding the second option (intent uri's). here's what I've got:
<activity android:name="com.myapps.tests.Layout2"
android:label="Auth Complete"
>
<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="mydomain.com"
android:path="/launch" />
</intent-filter>
</activity>
Now, with that I can go to "mydomain.com/launch" and it launches my activity. this all works well, except that I get the chooser. what I want is for it to just launch my activity without giving options.
From the explanation in the post I referenced it looks like thats what intent uris are for,but I can't find a straightforward example. what should my link in my webpage look like in order to launch this with no chooser?
I've seen a couple of examples that look something like this:
<a href="intent:#Intent;action=com.myapp.android.MY_ACTION;end">
However, that doesn't seem to work when I try it.
My test device is a Galaxy Tab 2.
any help would be appreciated.
I was also trying to launch the app in the recomended way. The following code worked for me.
Code inside the <activity> block of YourActivity in AndroidManifest.xml :
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="your.activity.namespace.CUSTOMACTION" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
</intent-filter>
Code in the activities onCreate() method :
Intent intent = getIntent();
if(intent != null && intent.getAction() == "your.activity.namespace.CUSTOMACTION") {
extraValue = intent.getStringExtra("extraValueName");
Log.e("AwseomeApp", "Extra value Recieved from intent : " + extraValue);
}
For the code in HTML, write an intent for launching the specific Activity, with the action your.activity.namespace.CUSTOMACTION, and your application package name your.activity.namespace. Your can also put some extra in the intent. For example intent.putExtra("extraValueName", "WOW"). Then get the required URL by printing the value of intent.toUri(Intent.URI_INTENT_SCHEME) in the Log. It should look like :
intent:#Intent;action=your.example.namespace.CUSTOMACTION;package=your.example.namespace;component=your.example.namespace/.activity.YourActivity;S.extraValueName=WOW;end
So your HTML code should look like :
<a href="intent:#Intent;action=your.example.namespace.CUSTOMACTION;package=your.example.namespace;component=your.example.namespace/.activity.YourActivity;S.extraValueName=WOW;end">
Launch App
</a>
This is as per what #hackbod suggested in here and this page from developers.google.com.
Depending on your intent filter this link should work:
start my app
But you should note that the android system will ask the user if your app or any other browser should be started.
If you want to avoid this implement a custom protcol handler. So just your app will listen for that and the user won't get the intent chooser.
Try to add this data intent:
<data android:scheme="mycoolapp" android:host="launch" />
With the code above this link should work:
start my app
I needed a small change to abhishek89m'a answer to make this work.
<a href="intent:#Intent;action=your.example.namespace.CUSTOMACTION;package=your.example.namespace;component=your.example.namespace/.YourActivity;S.extraValueName=WOW;end">
Launch App
</a>
I removed ".activity" after the slash in component name.
And I want to add, that custom action is probably the best answer to this problem if you don't want the app chooser to show up.
p.s. I would add this as comment, but I'm a new user and I don't have enough reputation points.
<a href="your.app.scheme://other/parameters/here">
This link on your browser will launch the app with the specific schema
like that on your intent
<intent-filter>
<data android:scheme="your.app.scheme" />
<action android:name="android.intent.action.VIEW" />
</intent-filter>