I don't believe you have to use getInvitation(), Personally I just override 'onNewIntent' like so:
@Override
protected void onNewIntent(final Intent intent) {
super.onNewIntent(intent);
if (intent.getAction().equals("android.intent.action.VIEW")) {
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
handleItemId(getIdFromIntent(intent));
}
}, 50);
}
}
I set up a handler with postDelayed to allow the activity to set-up. You don't have to do that.
You must have an intent filter set up like this
<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="yourwebsite.com" android:scheme="http"/>
<data android:host="yourwebsite.com" android:scheme="https"/>
<data android:host="anything" android:scheme="yourappname"/>
</intent-filter>
Then the dynamic url https://*****.app.goo.gl/?link=http://yourwebsite.com&al=yourappname://anything/method&apn=com.yourwebsite.yourappname
should open your website on desktop iOS etc, and the app or playstore on android.
To receive deep links from google searches that covert from links on your website to fragments in your app you must define them. My handleItemId and getIdFromIntent methods are defined as follows.
public boolean handleItemId(int id) {
if (id == R.id.nav_home) {
fragment = new FragmentHome();
} else if (id == R.id.nav_favorites) {
fragment = new FragmentFavoritesPager();
} else if (id == R.id.nav_contact) {
Intent intent = new Intent(Intent.ACTION_SENDTO);
intent.setData(Uri.parse("mailto:RateMyASVAB@gmail.com")); // only email apps should handle this
if (intent.resolveActivity(getPackageManager()) != null) {
startActivity(intent);
} else {
Toast.makeText(this, "No email app is installed", Toast.LENGTH_LONG).show();
}
return false;
} else if (id == R.id.nav_settings) {
fragment = new FragmentSettings();
} else {
return false;
}
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
getSupportFragmentManager()
.beginTransaction()
.setCustomAnimations(android.R.anim.fade_in, android.R.anim.fade_out)
.replace(R.id.content_main, fragment)
.commitAllowingStateLoss();
}
},400);
return true;
}
And getIdFromIntent
private int getIdFromIntent(Intent intent) {
int id = R.id.nav_home;
if (intent.getData() != null) {
List<String> segments = intent.getData().getPathSegments();
if (segments.size() > 0) {
switch (segments.get(0)) {
case "favorites":
id = R.id.nav_favorites;
break;
case "contact":
id = R.id.nav_contact;
break;
case "settings":
id = R.id.nav_settings;
break;
}
}
}
return id;
}