manifests.xml
<application
....
android:label="@string/app_name"
android:theme="@style/AppTheme">
<activity
android:name=".HomeScreenActivity"
android:screenOrientation="portrait"
android:theme="@style/AppTheme">
<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="somescheme" /> <!--This line to define schema -->
</intent-filter>
</activity>
....
</application>
HomeScreenActivity
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);
checkDeepLink();
}
private void checkDeepLink(){
if (getIntent() != null && getIntent().getData() != null) {
Uri data = getIntent().getData();
String scheme = data.getScheme();
String host = data.getHost();
String param = data.getQuery();
Log.d("DeepLink","Schema : " + scheme);
Log.d("DeepLink","Host : " + host);
Log.d("DeepLink","param : " + host);
if (host.equals("page_details")){
Intent intent = new Intent(this,DatadetailAcvity.class);
intent.putExtra("detail_id",Long.valueOf(data.getQueryParameter("detail_id"))); // URL query values as string, you need to parse string to long.
startActivity(intent);
}else{
// ... other logic
}
}
}
Deeplink
scheme://host?pama_name=value&other_param_name=value
Пример:
somescheme://page_details?detail_id=2
Facebook Пошаговое руководство
Обновление
DatadetailAcvity
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_data_detail);
if (getIntent() !=null) {
long detailId = getIntent().getLongExtra("detail_id",-1);
if (detailId != -1){
// do your stuff and displayed page by id
}
}
}