Карзель тоже прав, но написано в Kotlin
, я полагаю, что вы ожидаете решения для Java
Я отвечу тем же в Java
Uri uri = getIntent().getData();
String strUsername = "", strPassword = "";
if (uri != null) {
strUsername = uri.getQueryParameter("username");
strPassword = uri.getQueryParameter("password");
}
else {
// Your app will pop up even if http://www.myurl.com/sso is clicked, so better to handle null uri
}
Чтобы ответить на вашу следующую частьЧто касается динамического URL, вы можете иметь несколько intent-filters
для этой цели
<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" />
</intent-filter>
<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="https" />
</intent-filter>
<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="/debug"
android:scheme="http" />
</intent-filter>
</activity>
и т. д.
Чтобы открыть свое приложение, нажав ссылку и не отображая диалоговое окно выбораВам придется использовать пользовательский URI, например:
syn3sthete://myurl.com/sso?username=Scb56745&password=!l0Aeu0yQazxssx
Вы можете изменить syn3sthete
на любое другое значение, которое вы хотите.Не забудьте добавить intent-filter
для своего пользовательского URI.
<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="myurl.com"
android:path="/sso"
android:scheme="syn3sthete" />
</intent-filter>