【问题标题】:How to manage andorid deeplink and Applink in one Activity?如何在一个 Activity 中管理 android 深层链接和 Applink?
【发布时间】:2021-07-21 10:02:12
【问题描述】:

如何在一个Activity中管理deeplink和applink? 这是当前的 AndroidManifest.xml 设置。

    <activity android:name=".MainActivity" android:launchMode="singleTask">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
        <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="peterworks" android:host="open"/>
        </intent-filter>
        <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="https" android:host="peterworks.io"/>
        </intent-filter>
    </activity>

【问题讨论】:

    标签: android deep-linking applinks android-deep-link android-app-links


    【解决方案1】:

    这是使用 deeplink 和 Android Applink 管理您的 deeplinkActivity 的示例代码。

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    
        // onNewIntent Method will process every deeplink data.
        onNewIntent(MainActivity.this.getIntent());
    
    }
    
    @Override
    protected void onNewIntent(Intent intent) {
        super.onNewIntent(intent);
    
        // setIntent should be called for get new deeplink data. If this is not called, always same deeplink will called
        setIntent(intent);
    
        // Deeplink data process start
        Uri myDeeplink = intent.getData();
    
        if (myDeeplink != null){
    
            if(myDeeplink.getScheme().equals("https")) {
             // Do your things when Android Applink is open your app.
    
            } else {
             // Do your things when Deeplink is open your app.
    
            }
    
        }
    
    }
    

    【讨论】:

      【解决方案2】:

      您可以尝试使用以下库来简化该过程:https://github.com/airbnb/DeepLinkDispatch

      它提供了一种基于注释的方法来集成深层链接。

      来自其文档的示例:

      @DeepLink("example://example.com/deepLink/{id}")
      public class SampleActivity extends Activity {
        @Override protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          Intent intent = getIntent();
          if (intent.getBooleanExtra(DeepLink.IS_DEEP_LINK, false)) {
            Bundle parameters = intent.getExtras();
            String idString = parameters.getString("id");
            // Do something with idString
          }
        }
      }
      

      【讨论】:

        猜你喜欢
        • 2017-08-08
        • 2019-04-15
        • 2018-06-13
        • 2015-07-31
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多