how to start my app using a url link and go to different activity. i have used this code
<activity
android:name=".Act1"
android:label="activity first"
android:screenOrientation="landscape" >
<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="xyz.com"
android:pathPrefix="/abc/"
android:scheme="https" />
</intent-filter>
</activity>
by using this code i am able to open Act1 while entering into my android app but i want to switch to Act2 and Act3. because i have to use three different url and for all the stating screen should be Act1, Act2 and Act3 as click on url1, url2 and url3 respectively. please suggest if any solution.
The best things to do is to launch the same activity ("Front activity"). In this "front activity" you parse the url and launch Act1, 2, 3 depending on the url.
Related
I seem to be doing something wrong with deep linking in my app. I have two activities: a post viewer which views posts on a site, and a profile viewer which views a users profile. Below is my code that I've set up following Google's guide to deep linking.
Profile Activity Manifest Declaration
<activity
android:name=".ui.activity.ProfileActivity"
android:parentActivityName=".ui.activity.MainActivity">
<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="gab.ai"
android:pathPattern="/..*"
android:scheme="https" />
</intent-filter>
</activity>
Post Viewer Activity Manifest Declaration
<activity
android:name=".ui.activity.PostViewerActivity"
android:parentActivityName=".ui.activity.MainActivity">
<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="gab.ai"
android:pathPattern="/..*/posts/..*"
android:scheme="https" />
</intent-filter>
</activity>
I've left out the intent handling code because it is redundant. The deep links work properly, except for a weird issue when opening URLs that direct to the post viewer activity.
This works perfectly. Tapping a link such as https://url/.. opens the dialog and lists only one option When selecting the app, it opens the proper activity perfectly.
Here's where it gets weird. When clicking a URL such as https://url/../posts/.. the Android System sees both activity deep links as feasible. My question is how do I get around this? Changing the URL scheme is out, and I'm not fluent enough about deep links to figure out a workaround.
In ProfileActivity android:pathPattern="/..*" equals to /..*/posts/..* because an asterisk ('*') matches a sequence of 0 to many occurrences of the immediately preceding character. Try to use escape character \ as explained in docs
I have an html page with two links as follow:
Test 1
Test 2
I open it with android Internet app. In my "Hello word" manifest application i declare:
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
<intent-filter android:label="testapp">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="myApp" />
</intent-filter>
</activity>
I can open my application with both links.The first time i click on both links my app starts and passes through onCreate (my app was not in background before click). The second time (app now is in recent tasks), the first link clicked before in chronologically order pass through onResume only but the second pass on onCreate. This will be the behaviour if i try open links n times until i kill application from recent. Any ideas?Thanks!
An Android activity, by default can be instantiated multiple times. You should use android:launchMode="singleTask" to override this behavior. There are some other flags that might interest you if you - here is the link to documentation.
I'm trying to open an android app when I tap a URL inside an email. It's working well the app is opening, the problem is when I use the "Internet Browser" it opens the android on the browser, that means I will have two instances of the Android app. This doesn't happen using Chrome browser, it only calls the app, it doesn't open on the browser.
I resolved this problem using:
android:launchMode="singleInstance" and android:launchMode="singleTask"
but I'm not able to reach the parameters from the URL tapped to open the app.
URL structure: email://act/parameter1/parameter2
This is my code:
<activity
android:name=".Login"
android:screenOrientation="portrait"
android:exported="true"
android:windowSoftInputMode="stateHidden|adjustResize">
<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="act" android:scheme="email" />
</intent-filter>
</activity>
In conclusion, I would like to open the app only with one instance (not on the browser) and be able to reach the parameters, using any browser (Chrome, Internet, Firefox).
Thanks in advance
You didn't post your activity code, but i will try to guess the problem: If your activity is a singleTask you need to handle incomming Intents in onCreate() and in onNewIntent() . This is because Activity will be created only once and each next incoming Intent will be then handled by onNewIntent()
There is a perfect way to launch our android application through Deeplink.
<activity
android:name="com.example.android.GizmosActivity"
android:label="#string/title_gizmos" >
<intent-filter android:label="#string/filter_title_viewgizmos">
<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="www.example.com"
android:pathPrefix="/gizmos" />
</intent-filter>
</activity>
Here, I can easily launch my application through “http://www.example.com/gizmos”, But my question comes when I am going to hit shorten URL of this link i.e. goo.gl/tNQpWe.
What could be the ways to launch my app through tiny/ shorten url too ?
Please suggest.
The short url will be redirecting to your server/domain and from there you do the same what "gizmos" did. Deep linking is basically a HTML page rendering some expected data by your android application (In your case android:host and android:pathPrefix)
You will need to create a basic html rendering the android schema if you need data to be passed. I would suggest you to follow Branch.io.
https://blog.branch.io/technical-guide-to-deep-linking-on-android-chrome-intents
My activity definition looks like this:
<activity
android:name="com.broadvision.myvv.MyVV_Splash"
android:screenOrientation="portrait">
<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="vmoso" />
<data
android:host="www.vmoso.com"
android:scheme="http" />
</data>
</intent-filter>
</activity>
This activity is root activity in my app, it can be started from browser app, after this, if I hit browser icon, what I want to see is the browser UI, but in fact, I still see my own app, which is incorrect.
I've tried to add android:launchMode="singleInstance" and android:launchMode="singleTask", it works for this case, i.e.: my app activity starts as a new task, and I can switch back to browser, but when I hit my app icon from home screen, it always starts as a new task, which is not what I want to see, I want to see the last Activity when I leave.
Also tried android:allowTaskReparenting="true", but doesn't work, I believe the point is on launchMode, but after tried all 4 modes, still cannot figure it out.