我在我的应用程序中使用firebase通知和动态链接
我发送深层链接作为通知中的有效负载,当用户点击通知时,我正在打开这样的深层链接
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(pushAction.getActionDeeplink())); // contains the deeplink
if (pushNotification.getExtraData() != null) { // not extra Data from push
intent.putExtra(IntentKeys.PUSH_DATA_EXTRA, pushNotification.getExtraData());
}
PendingIntent actionPendingIntent =
PendingIntent.getActivity(context, pushNotification.getNotificationId(), intent,
PendingIntent.FLAG_UPDATE_CURRENT);
final NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(context)
.setSmallIcon(R.mipmap.ic_launcher)
.setLargeIcon(largeIcon)
.setTicker(pushNotification.getTicker())
.setContentTitle(pushNotification.getTitle())
.setContentText(pushNotification.getMessage())
.setAutoCancel(true)
.setContentIntent(actionPendingIntent);
notificationManager.notify(uniqueId, mBuilder.build());
我已在我的申请中宣布了一项活动
<activity
android:name=".ui.activities.SaveActivity"
android:label="@string/title_activity_save"
android:screenOrientation="portrait"
android:windowSoftInputMode="stateHidden|adjustPan">
<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="example.com"
android:pathPattern="/save"
android:scheme="http" />
</intent-filter>
</activity>
通过通知发送的深层网址 http://example.com/save
在我设置的活动中,我接受了像这样的深层次链接
public class SaveActivity extends BaseActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_save);
setupGoogleApiClient();
}
private void setupGoogleApiClient() {
mGoogleApiClient = new GoogleApiClient.Builder(this)
.enableAutoManage(this, this)
.addApi(AppInvite.API)
.build();
boolean autoLaunchDeepLink = false;
AppInvite.AppInviteApi.getInvitation(mGoogleApiClient, this, autoLaunchDeepLink)
.setResultCallback(
new ResultCallback<AppInviteInvitationResult>() {
@Override
public void onResult(@NonNull AppInviteInvitationResult result) {
if (result.getStatus().isSuccess()) {
Intent intent = result.getInvitationIntent();
String deepLink = AppInviteReferral.getDeepLink(intent);
Log.d("save getInvitation: found deeplink." + deepLink);
/**************************** ISSUE ***********************/
if(intent.hasExtra(IntentKeys.PUSH_DATA_EXTRA)) {
// there is no extra data :(
}
/**************************** ISSUE ***********************/
} else {
Log.d("save getInvitation: no deep link found.");
}
}
});
}
}
一切都按预期工作。 SaveActivity被调用,它正在打开SaveActivity。但是,活动中没有收到额外的数据。
我使用IntentKeys.PUSH_DATA_EXTRA作为意图中的键来设置字符串extra。