I am developing an android app, in which user must need to login first to use it’s features. So as usual user must need to login using provided user credential.
But I don’t want user always enter username and password again and again, so that I am just sharing a URL with user and if user click on shared link from anywhere in phone (via mail, or WhatsApp, or Facebook, etc.) phone must prompt to choose my app and app should automatically extract the URL and directly redirect the app to my Home Screen by hitting the login api if username and password are correct.
The shared url will be look like this – http://www.myurl.com/sso?username=Scb56745&password=!l0Aeu0yQazxssx
For now I have managed to prompt the dialog using this code in my AndroidManifest file –
<activity
android:name="com.my.par.activities.UserActivity"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:windowSoftInputMode="stateHidden">
<intent-filter android:autoVerify="true" tools:targetApi="m">
<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.myurl.com"
android:path="/sso"
android:scheme="http" />
<data
android:host="www.yoururl.com"
android:path="/sso1"
android:scheme="https" />
</intent-filter>
</activity>
I am getting this clicked URL link in my UserAcitivity’s on getIntent() method, like this –
Uri uri = getIntent().getData();
String path = uri.getPath();
-
So my real question is how to extract the username and password separately and so that I can call my login api by sending this username and password from this url (for ex. http://www.myurl.com/sso?username=Scb56745&password=!l0Aeu0yQazxssx). – Done
-
And how can I put a dynamic URL or host name, path and scheme in AndroidMenifest file? – Done
-
How can we force our app to always directly open the app,(don’t need to show the chooser dialog) because no use of it even user click on browser nothing gonna happen.
Happy coding 🙂
2
Answers
Try using code like this :
And call it
etc.
UPDATE:
The only “dynamic” way of adding URL I know is using something like this :
https://developer.android.com/studio/build/manifest-build-variables
you can change this URL depending on your Build Variant.
As is said here :
https://stackoverflow.com/a/43339476/8713068
you cannot update Android Manifest directly from code
Karzel is also right but it’s written in
Kotlin
, I believe you are expecting the solution forJava
I’ll answer the same inJava
To answer your next part about dynamic URL, you can have multiple
intent-filters
for that purposeand so on.
To open your app directly by clicking the link and not show a chooser dialog you’ll have to use a custom URI, for example:
You can change
syn3sthete
to any custom value you want.Don’t forget to add an
intent-filter
for your custom URI.