1

我使用推送通知在我的 Android 应用程序中实现了深度链接,但是当我使用推送通知深度链接消息而不是深度链接活动打开应用程序时,应用程序打开启动活动的方式不一致。我试图改变android:launchMode="singleTop"但没有奏效。我的 Deep Linking Activity 和 Android Manifest 代码部分如下所示。

深度链接活动:

    [Activity(Label = "DeepLinkingActivity")]
public class DeepLinkingActivity : Activity
{                                                                    
    protected override void OnCreate(Bundle savedInstanceState)
    {
        base.OnCreate(savedInstanceState);

        if (SessionContext.DeepLinkingMessageContent == null)
        {
            CheckDeepLinkingContent(Intent);
        }
    }

    protected override void OnNewIntent(Intent intent)
    {
        base.OnNewIntent(intent);

        if (SessionContext.DeepLinkingMessageContent == null)
        {
            CheckDeepLinkingContent(intent);
        }
    }

    void CheckDeepLinkingContent(Intent intent)
    {
        if (intent.Data != null)
        {

            var intentData = Intent.Data;
            var hostData = intentData.Host; 
            var path = intentData.Path; 

            var pathContent = path.Split('/');

            //...
            //processing content of the deep linking message

            SessionContext.DeepLinkingMessageContent = deepLinkingContent;

            StartActivity(typeof(LoginView));
            Finish();
        }
    }

Android 清单的一部分:

        <activity android:name="myapp.android.views.DeepLinkingActivity" android:launchMode="singleTop">
        <intent-filter android:autoVerify="true">
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE" />
            <data android:scheme="myappscheme" android:host="apphost"/>
       </intent-filter>
    </activity>
4

0 回答 0