Reputation: 49
I added App link assistant in my app to open particular activity from an external link. Now I've the following code in my DataDetailActivity.
Intent appLinkIntent = getIntent();
String appLinkAction = appLinkIntent.getAction();
Uri appLinkData = appLinkIntent.getData();
if(appLinkData != null)
{
String dataId = appLinkData.getLastPathSegment();
Intent resultIntent = new Intent(this, DataDetailActivity.class);
startActivity(resultIntent);
}
I would like to open particular DataDetailActivity. But this does throws error. Where do I have to pass dataId in the intent?
Note: We have Default HomeScreen in the app that has Login To FB button. So Do I have to write down this code in HomeScreenActivity and pass intent to DatadetailAcvity.java? If yes then how Do I tell to DataDetailScreen for particular data(If i have id)?
Any help would be appreciated.
Upvotes: 1
Views: 2259
Reputation: 8139
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
Example:
somescheme://page_details?detail_id=2
Facebook Step-by-Step Guide
Update
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
}
}
}
Upvotes: 2
Reputation: 13609
Without error info,but if you want pass data through deep linking, you could use query parameters.
Suppose url is https://www.example.com/example?param1=hello
Then
Intent intent = getIntent();
Uri data = intent.getData();
String param1 = data.getQueryParameter("param1");
Upvotes: 0